PageRenderTime 22ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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. 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. TestableProjectModule module = CreateTestableProjectModule();
  40. module.InvokeRegisterViewsAndServices();
  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);
  61. return module;
  62. }
  63. private TestableProjectModule CreateTestableProjectModule()
  64. {
  65. TestableProjectModule module = new TestableProjectModule(container);
  66. return module;
  67. }
  68. }
  69. class TestableProjectModule : ProjectModule
  70. {
  71. public TestableProjectModule(IUnityContainer container)
  72. : base(container)
  73. {
  74. }
  75. public void InvokeRegisterViewsAndServices()
  76. {
  77. base.RegisterViewsAndServices();
  78. }
  79. }
  80. }