PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 100 lines | 63 code | 21 blank | 16 comment | 0 complexity | 86fb590edd6112488064233fcb600784 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            var module = CreateProjectModule();
 43
 44            module.Initialize();
 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, new MockRegionContentRegistry());
 72            return module;
 73        }
 74
 75        private class MockRegionContentRegistry : IRegionViewRegistry
 76        {
 77            public event System.EventHandler<ViewRegisteredEventArgs> ContentRegistered;
 78
 79
 80
 81            public System.Collections.Generic.IEnumerable<object> GetContents(string regionName)
 82            {
 83                throw new System.NotImplementedException();
 84            }
 85
 86
 87
 88
 89            public void RegisterViewWithRegion(string regionName, System.Type viewType)
 90            {
 91                throw new System.NotImplementedException();
 92            }
 93
 94            public void RegisterViewWithRegion(string regionName, System.Func<object> getContentDelegate)
 95            {
 96            }
 97        }
 98    }
 99}
100