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