PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/V1/trunk/Source/StockTraderRI/StockTraderRI.Modules.WatchList.Tests/WatchModuleFixture.cs

#
C# | 104 lines | 73 code | 15 blank | 16 comment | 0 complexity | d6fe814a07b6f20c542f06ee296629e0 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.Modularity;
  18. using Microsoft.Practices.Composite.Regions;
  19. using Microsoft.Practices.Unity;
  20. using Microsoft.VisualStudio.TestTools.UnitTesting;
  21. using StockTraderRI.Modules.Watch;
  22. using StockTraderRI.Modules.Watch.AddWatch;
  23. using StockTraderRI.Modules.Watch.Services;
  24. using StockTraderRI.Modules.Watch.WatchList;
  25. using StockTraderRI.Modules.WatchList.Tests.Mocks;
  26. namespace StockTraderRI.Modules.WatchList.Tests
  27. {
  28. [TestClass]
  29. public class WatchModuleFixture
  30. {
  31. [TestMethod]
  32. public void RegisterViewsServicesRegistersWatchListView()
  33. {
  34. var container = new MockUnityContainer();
  35. var module = new TestableWatchModule(container, new MockRegionManager());
  36. module.InvokeRegisterViewsAndServices();
  37. Assert.AreEqual(typeof(WatchListService), container.Types[typeof(IWatchListService)]);
  38. Assert.AreEqual(typeof(WatchListView), container.Types[typeof(IWatchListView)]);
  39. Assert.AreEqual(typeof(WatchListPresentationModel), container.Types[typeof(IWatchListPresentationModel)]);
  40. Assert.AreEqual(typeof(AddWatchView), container.Types[typeof(IAddWatchView)]);
  41. Assert.AreEqual(typeof(AddWatchPresenter), container.Types[typeof(IAddWatchPresenter)]);
  42. }
  43. [TestMethod]
  44. public void InitAddsAddWatchControlViewToToolbarRegion()
  45. {
  46. var toolbarRegion = new MockRegion();
  47. var collapsibleRegion = new MockRegion();
  48. var regionManager = new MockRegionManager();
  49. var container = new MockUnityResolver();
  50. container.Bag.Add(typeof(IAddWatchPresenter), new MockAddWatchPresenter());
  51. container.Bag.Add(typeof(IWatchListPresentationModel), new MockWatchListPresentationModel());
  52. IModule module = new WatchModule(container, regionManager);
  53. regionManager.Regions.Add("WatchRegion", collapsibleRegion);
  54. regionManager.Regions.Add("MainToolbarRegion", toolbarRegion);
  55. Assert.AreEqual(0, toolbarRegion.AddedViews.Count);
  56. Assert.AreEqual(0, collapsibleRegion.AddedViews.Count);
  57. module.Initialize();
  58. Assert.AreEqual(1, toolbarRegion.AddedViews.Count);
  59. Assert.AreEqual(1, collapsibleRegion.AddedViews.Count);
  60. }
  61. internal class TestableWatchModule : WatchModule
  62. {
  63. public TestableWatchModule(IUnityContainer container, IRegionManager regionManager)
  64. : base(container, regionManager)
  65. {
  66. }
  67. public void InvokeRegisterViewsAndServices()
  68. {
  69. base.RegisterViewsAndServices();
  70. }
  71. }
  72. class MockAddWatchPresenter : IAddWatchPresenter
  73. {
  74. private IAddWatchView _view = new MockAddWatchView();
  75. public IAddWatchView View
  76. {
  77. get { return _view; }
  78. }
  79. }
  80. class MockWatchListPresentationModel : IWatchListPresentationModel
  81. {
  82. private IWatchListView _view = new MockWatchListView();
  83. public IWatchListView View
  84. {
  85. get { return _view; }
  86. }
  87. }
  88. }
  89. }