PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/V2.2/trunk/Quickstarts/UI Composition/ViewInjection/Desktop/UIComposition.Modules.Project.Tests/ProjectModuleFixture.cs

#
C# | 96 lines | 64 code | 16 blank | 16 comment | 0 complexity | 74ef2928e5ede6687f08691ae4c0de18 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 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//===================================================================================
17using Microsoft.Practices.Composite.Regions;
18using Microsoft.Practices.Unity;
19using Microsoft.VisualStudio.TestTools.UnitTesting;
20using UIComposition.Infrastructure;
21using UIComposition.Modules.Project.Services;
22using UIComposition.Modules.Project.Tests.Mocks;
23
24namespace UIComposition.Modules.Project.Tests
25{
26    [TestClass]
27    public class ProjectModuleFixture
28    {
29
30        MockUnityContainer container;
31        MockRegionManager regionManager;
32
33        [TestInitialize]
34        public void SetUp()
35        {
36            container = new MockUnityContainer();
37            regionManager = new MockRegionManager();
38        }
39        [TestMethod]
40        public void RegisterViewsAndServices()
41        {
42            TestableProjectModule module = CreateTestableProjectModule();
43
44            module.InvokeRegisterViewsAndServices();
45
46            Assert.AreEqual(typeof(ProjectService), container.Types[typeof(IProjectService)]);
47            Assert.AreEqual(typeof(ProjectsListView), container.Types[typeof(IProjectsListView)]);
48            Assert.AreEqual(typeof(ProjectsListPresenter), container.Types[typeof(IProjectsListPresenter)]);
49        }
50
51        [TestMethod]
52        public void InitializeShouldCallRegisterAndViewServices()
53        {
54            container.RegisterInstance<IUnityContainer>(container);
55            container.RegisterInstance<IRegionManager>(regionManager);
56            MockRegion mainToolbar = new MockRegion();
57
58            regionManager.Regions.Add(RegionNames.MainToolBar, mainToolbar);
59
60            ProjectModule module = CreateProjectModule();
61
62            module.Initialize();
63
64            Assert.AreEqual(typeof(ProjectService), container.Types[typeof(IProjectService)]);
65            Assert.AreEqual(typeof(ProjectsListView), container.Types[typeof(IProjectsListView)]);
66            Assert.AreEqual(typeof(ProjectsListPresenter), container.Types[typeof(IProjectsListPresenter)]);
67        }
68
69        private ProjectModule CreateProjectModule()
70        {
71            ProjectModule module = new ProjectModule(container);
72            return module;
73        }
74
75        private TestableProjectModule CreateTestableProjectModule()
76        {
77            TestableProjectModule module = new TestableProjectModule(container);
78            return module;
79        }
80
81    }
82
83    class TestableProjectModule : ProjectModule
84    {
85        public TestableProjectModule(IUnityContainer container)
86            : base(container)
87        {
88
89        }
90
91        public void InvokeRegisterViewsAndServices()
92        {
93            base.RegisterViewsAndServices();
94        }
95    }
96}