PageRenderTime 55ms CodeModel.GetById 16ms 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. //===================================================================================
  17. using Microsoft.Practices.Composite.Regions;
  18. using Microsoft.Practices.Unity;
  19. using Microsoft.VisualStudio.TestTools.UnitTesting;
  20. using UIComposition.Infrastructure;
  21. using UIComposition.Modules.Project.Services;
  22. using UIComposition.Modules.Project.Tests.Mocks;
  23. namespace UIComposition.Modules.Project.Tests
  24. {
  25. [TestClass]
  26. public class ProjectModuleFixture
  27. {
  28. MockUnityContainer container;
  29. MockRegionManager regionManager;
  30. [TestInitialize]
  31. public void SetUp()
  32. {
  33. container = new MockUnityContainer();
  34. regionManager = new MockRegionManager();
  35. }
  36. [TestMethod]
  37. public void RegisterViewsAndServices()
  38. {
  39. var module = CreateProjectModule();
  40. module.Initialize();
  41. Assert.AreEqual(typeof(ProjectService), container.Types[typeof(IProjectService)]);
  42. Assert.AreEqual(typeof(ProjectsListView), container.Types[typeof(IProjectsListView)]);
  43. Assert.AreEqual(typeof(ProjectsListPresenter), container.Types[typeof(IProjectsListPresenter)]);
  44. }
  45. [TestMethod]
  46. public void InitializeShouldCallRegisterAndViewServices()
  47. {
  48. container.RegisterInstance<IUnityContainer>(container);
  49. container.RegisterInstance<IRegionManager>(regionManager);
  50. MockRegion mainToolbar = new MockRegion();
  51. regionManager.Regions.Add(RegionNames.MainToolBar, mainToolbar);
  52. ProjectModule module = CreateProjectModule();
  53. module.Initialize();
  54. Assert.AreEqual(typeof(ProjectService), container.Types[typeof(IProjectService)]);
  55. Assert.AreEqual(typeof(ProjectsListView), container.Types[typeof(IProjectsListView)]);
  56. Assert.AreEqual(typeof(ProjectsListPresenter), container.Types[typeof(IProjectsListPresenter)]);
  57. }
  58. private ProjectModule CreateProjectModule()
  59. {
  60. ProjectModule module = new ProjectModule(container, new MockRegionContentRegistry());
  61. return module;
  62. }
  63. private class MockRegionContentRegistry : IRegionViewRegistry
  64. {
  65. public event System.EventHandler<ViewRegisteredEventArgs> ContentRegistered;
  66. public System.Collections.Generic.IEnumerable<object> GetContents(string regionName)
  67. {
  68. throw new System.NotImplementedException();
  69. }
  70. public void RegisterViewWithRegion(string regionName, System.Type viewType)
  71. {
  72. throw new System.NotImplementedException();
  73. }
  74. public void RegisterViewWithRegion(string regionName, System.Func<object> getContentDelegate)
  75. {
  76. }
  77. }
  78. }
  79. }