PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/V1/trunk/Source/QuickStarts/UIComposition/UIComposition.Modules.Project.Tests/ProjectModuleFixture.cs

#
C# | 97 lines | 64 code | 17 blank | 16 comment | 0 complexity | 90e0e1d59cac451757354c1ddafde169 MD5 | raw file
 1//===============================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation
 4//===============================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===============================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===============================================================================
17
18using Microsoft.Practices.Composite.Regions;
19using Microsoft.Practices.Unity;
20using Microsoft.VisualStudio.TestTools.UnitTesting;
21using UIComposition.Infrastructure;
22using UIComposition.Modules.Project.Services;
23using UIComposition.Modules.Project.Tests.Mocks;
24
25namespace UIComposition.Modules.Project.Tests
26{
27    [TestClass]
28    public class ProjectModuleFixture
29    {
30
31        MockUnityContainer container;
32        MockRegionManager regionManager;
33
34        [TestInitialize]
35        public void SetUp()
36        {
37            container = new MockUnityContainer();
38            regionManager = new MockRegionManager();
39        }
40        [TestMethod]
41        public void RegisterViewsAndServices()
42        {
43            TestableProjectModule module = CreateTestableProjectModule();
44
45            module.InvokeRegisterViewsAndServices();
46
47            Assert.AreEqual(typeof(ProjectService), container.Types[typeof(IProjectService)]);
48            Assert.AreEqual(typeof(ProjectsListView), container.Types[typeof(IProjectsListView)]);
49            Assert.AreEqual(typeof(ProjectsListPresenter), container.Types[typeof(IProjectsListPresenter)]);
50        }
51
52        [TestMethod]
53        public void InitializeShouldCallRegisterAndViewServices()
54        {
55            container.RegisterInstance<IUnityContainer>(container);
56            container.RegisterInstance<IRegionManager>(regionManager);
57            MockRegion mainToolbar = new MockRegion();
58
59            regionManager.Regions.Add(RegionNames.MainToolBar, mainToolbar);
60
61            ProjectModule module = CreateProjectModule();
62
63            module.Initialize();
64
65            Assert.AreEqual(typeof(ProjectService), container.Types[typeof(IProjectService)]);
66            Assert.AreEqual(typeof(ProjectsListView), container.Types[typeof(IProjectsListView)]);
67            Assert.AreEqual(typeof(ProjectsListPresenter), container.Types[typeof(IProjectsListPresenter)]);
68        }
69
70        private ProjectModule CreateProjectModule()
71        {
72            ProjectModule module = new ProjectModule(container);
73            return module;
74        }
75
76        private TestableProjectModule CreateTestableProjectModule()
77        {
78            TestableProjectModule module = new TestableProjectModule(container);
79            return module;
80        }
81
82    }
83
84    class TestableProjectModule : ProjectModule
85    {
86        public TestableProjectModule(IUnityContainer container)
87            : base(container)
88        {
89
90        }
91
92        public void InvokeRegisterViewsAndServices()
93        {
94            base.RegisterViewsAndServices();
95        }
96    }
97}