PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/V1/trunk/Source/StockTraderRI/StockTraderRI.Modules.Position.Tests/PositionModuleFixture.cs

#
C# | 153 lines | 110 code | 27 blank | 16 comment | 0 complexity | 68823a4cfb321ca1fc30bb3b27dcaa23 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.Regions;
 19using Microsoft.Practices.Unity;
 20using Microsoft.VisualStudio.TestTools.UnitTesting;
 21using StockTraderRI.Infrastructure.Interfaces;
 22using StockTraderRI.Modules.Position.Controllers;
 23using StockTraderRI.Modules.Position.Interfaces;
 24using StockTraderRI.Modules.Position.Orders;
 25using StockTraderRI.Modules.Position.PositionSummary;
 26using StockTraderRI.Modules.Position.Services;
 27using StockTraderRI.Modules.Position.Tests.Mocks;
 28
 29namespace StockTraderRI.Modules.Position.Tests
 30{
 31    [TestClass]
 32    public class PositionModuleFixture
 33    {
 34        [TestMethod]
 35        [DeploymentItem("Data", "Data")]
 36        public void RegisterViewsServicesRegistersViewsAndServices()
 37        {
 38            MockUnityContainer container = new MockUnityContainer();
 39
 40            TestablePositionModule module = new TestablePositionModule(container, new MockRegionManager());
 41
 42            module.InvokeRegisterViewsAndServices();
 43
 44            Assert.AreEqual(typeof(AccountPositionService), container.Types[typeof(IAccountPositionService)]);
 45            Assert.AreEqual(typeof(PositionSummaryView), container.Types[typeof(IPositionSummaryView)]);
 46            Assert.AreEqual(typeof(PositionSummaryPresentationModel), container.Types[typeof(IPositionSummaryPresentationModel)]);
 47            Assert.AreEqual(typeof(OrdersView), container.Types[typeof(IOrdersView)]);
 48            Assert.AreEqual(typeof(OrdersPresentationModel), container.Types[typeof(IOrdersPresentationModel)]);
 49            Assert.AreEqual(typeof(OrderDetailsView), container.Types[typeof(IOrderDetailsView)]);
 50            Assert.AreEqual(typeof(OrderDetailsPresentationModel), container.Types[typeof(IOrderDetailsPresentationModel)]);
 51            Assert.AreEqual(typeof(OrderCommandsView), container.Types[typeof(IOrderCommandsView)]);
 52            Assert.AreEqual(typeof(OrderCompositeView), container.Types[typeof(IOrderCompositeView)]);
 53            Assert.AreEqual(typeof(OrderCompositePresentationModel), container.Types[typeof(IOrderCompositePresentationModel)]);
 54            Assert.AreEqual(typeof(OrdersController), container.Types[typeof(IOrdersController)]);
 55            Assert.AreEqual(typeof(XmlOrdersService), container.Types[typeof(IOrdersService)]);
 56
 57        }
 58
 59        [TestMethod]
 60        public void InitAddsOrdersToolbarViewToToolbarRegion()
 61        {
 62            MockRegion toolbarRegion = new MockRegion();
 63            MockRegion mainRegion = new MockRegion();
 64            MockRegionManager regionManager = new MockRegionManager();
 65            var container = new MockUnityResolver();
 66            container.Bag.Add(typeof(IOrdersController), new MockOrdersController());
 67            container.Bag.Add(typeof(IPositionSummaryPresentationModel), new MockPositionSummaryPresenter());
 68            PositionModule module = new PositionModule(container, regionManager);
 69            regionManager.Regions.Add("MainRegion", mainRegion);
 70            regionManager.Regions.Add("CollapsibleRegion", new MockRegion());
 71            regionManager.Regions.Add("MainToolbarRegion", toolbarRegion);
 72
 73            Assert.AreEqual(0, toolbarRegion.AddedViews.Count);
 74            Assert.AreEqual(0, mainRegion.AddedViews.Count);
 75
 76            module.Initialize();
 77
 78            Assert.AreEqual(1, mainRegion.AddedViews.Count);
 79            Assert.AreEqual(1, toolbarRegion.AddedViews.Count);
 80
 81        }
 82
 83
 84        internal class TestablePositionModule : PositionModule
 85        {
 86            public TestablePositionModule(IUnityContainer container, IRegionManager regionManager)
 87                : base(container, regionManager)
 88            {
 89            }
 90
 91            public void InvokeRegisterViewsAndServices()
 92            {
 93                base.RegisterViewsAndServices();
 94            }
 95        }
 96    }
 97
 98    internal class MockPositionSummaryPresenter : IPositionSummaryPresentationModel
 99    {
100        #region IPositionSummaryPresenter Members
101
102        private IPositionSummaryView _view = new MockPositionSummaryView();
103
104        public IPositionSummaryView View
105        {
106            get { return _view; }
107            set { _view = value; }
108        }
109
110
111        public System.Collections.ObjectModel.ObservableCollection<PositionSummaryItem> PositionSummaryItems
112        {
113            get { throw new System.NotImplementedException(); }
114        }
115
116
117        public Microsoft.Practices.Composite.Wpf.Commands.DelegateCommand<string> BuyCommand
118        {
119            get
120            {
121                throw new System.NotImplementedException();
122            }
123            set
124            {
125                throw new System.NotImplementedException();
126            }
127        }
128
129        public Microsoft.Practices.Composite.Wpf.Commands.DelegateCommand<string> SellCommand
130        {
131            get
132            {
133                throw new System.NotImplementedException();
134            }
135            set
136            {
137                throw new System.NotImplementedException();
138            }
139        }
140
141        #endregion
142
143        #region IPositionSummaryPresentationModel Members
144
145
146        public string HeaderInfo
147        {
148            get { throw new System.NotImplementedException(); }
149        }
150
151        #endregion
152    }
153}