PageRenderTime 32ms CodeModel.GetById 14ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/V2.2/trunk/RI/Desktop/StockTraderRI.Modules.WatchList.Tests/Services/WatchListServiceFixture.cs

#
C# | 190 lines | 128 code | 43 blank | 19 comment | 0 complexity | acc8fe2967cd8261197ea49e4a89b513 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//===================================================================================
 17using System.Collections.ObjectModel;
 18using System.Globalization;
 19using Microsoft.VisualStudio.TestTools.UnitTesting;
 20using StockTraderRI.Infrastructure.Interfaces;
 21using StockTraderRI.Modules.Watch.Services;
 22using StockTraderRI.Modules.WatchList.Tests.Mocks;
 23
 24namespace StockTraderRI.Modules.WatchList.Tests.Services
 25{
 26    /// <summary>
 27    /// Summary description for WatchListServiceFixture
 28    /// </summary>
 29    [TestClass]
 30    public class WatchListServiceFixture
 31    {
 32        [TestMethod]
 33        public void ServiceListensToAddWatchCommand()
 34        {
 35            WatchListService service = new WatchListService(new MockMarketFeedService());
 36            Assert.AreEqual(0, service.RetrieveWatchList().Count);
 37
 38            service.AddWatchCommand.Execute("Stock999");
 39
 40            Assert.AreEqual(1, service.RetrieveWatchList().Count);
 41        }
 42
 43        [TestMethod]
 44        public void ServiceListensToAddWatchCommandAndReturnsCommandParamsInList()
 45        {
 46            WatchListService service = new WatchListService(new MockMarketFeedService());
 47
 48            service.AddWatchCommand.Execute("STOCK00");
 49            service.AddWatchCommand.Execute("STOCK99");
 50
 51            Assert.AreEqual(2, service.RetrieveWatchList().Count);
 52            Assert.AreEqual<string>("STOCK00", service.RetrieveWatchList()[0]);
 53            Assert.AreEqual<string>("STOCK99", service.RetrieveWatchList()[1]);
 54        }
 55
 56        [TestMethod]
 57        public void GetWatchListShouldReturnObservableCollection()
 58        {
 59            WatchListService service = new WatchListService(new MockMarketFeedService());
 60
 61            service.AddWatchCommand.Execute("Stock000");
 62            ObservableCollection<string> watchList = service.RetrieveWatchList();
 63
 64            bool collectionChanged = false;
 65            watchList.CollectionChanged += delegate
 66            {
 67                collectionChanged = true;
 68            };
 69
 70            service.AddWatchCommand.Execute("Stock111");
 71
 72            Assert.AreEqual(true, collectionChanged);
 73        }
 74
 75        [TestMethod]
 76        public void TickerSymbolGetsConvertedToUppercase()
 77        {
 78            WatchListService service = new WatchListService(new MockMarketFeedService());
 79
 80            service.AddWatchCommand.Execute("StockInMixedCase");
 81
 82            Assert.AreEqual<string>("StockInMixedCase".ToUpper(CultureInfo.InvariantCulture), service.RetrieveWatchList()[0]);
 83        }
 84
 85        [TestMethod]
 86        public void NullOrEmptyStringIsNotAddedToList()
 87        {
 88            WatchListService service = new WatchListService(new MockMarketFeedService());
 89
 90            service.AddWatchCommand.Execute(null);
 91            service.AddWatchCommand.Execute(string.Empty);
 92
 93            Assert.AreEqual(0, service.RetrieveWatchList().Count);
 94        }
 95
 96        [TestMethod]
 97        public void AddingSameSymbolTwiceOnlyAddsItOnceToTheList()
 98        {
 99            WatchListService service = new WatchListService(new MockMarketFeedService());
100
101            service.AddWatchCommand.Execute("DUPE");
102            service.AddWatchCommand.Execute("DUPE");
103
104            Assert.AreEqual(1, service.RetrieveWatchList().Count);
105        }
106
107        [TestMethod]
108        public void DoesNotAddWatchIfSymbolDoesNotExistInMarketFeed()
109        {
110            MockMarketFeedService marketFeedService = new MockMarketFeedService();
111            marketFeedService.MockSymbolExists = false;
112
113            WatchListService service = new WatchListService(marketFeedService);
114
115            service.AddWatchCommand.Execute("INEXISTENT");
116
117            Assert.AreEqual(0, service.RetrieveWatchList().Count);
118            Assert.AreEqual<string>("INEXISTENT", marketFeedService.SymbolExistsArgumentTickerSymbol);
119        }
120
121        [TestMethod]
122        public void SymbolWithLeadingBlankSpacesIsAddedToList()
123        {
124            WatchListService service = new WatchListService(new MockMarketFeedService());
125
126            service.AddWatchCommand.Execute("    FUND0");
127
128            Assert.AreEqual(1, service.RetrieveWatchList().Count);
129            Assert.AreEqual("FUND0", service.RetrieveWatchList()[0]);
130        }
131
132        [TestMethod]
133        public void SymbolWithTrailingBlankSpacesIsAddedToList()
134        {
135            WatchListService service = new WatchListService(new MockMarketFeedService());
136
137            service.AddWatchCommand.Execute("FUND0    ");
138
139            Assert.AreEqual(1, service.RetrieveWatchList().Count);
140            Assert.AreEqual("FUND0", service.RetrieveWatchList()[0]);
141        }
142
143
144        [TestMethod]
145        public void AddingSameSymbolOneWithLeadingBlankSpacesTwiceOnlyAddsItOnceToTheList()
146        {
147            WatchListService service = new WatchListService(new MockMarketFeedService());
148
149            service.AddWatchCommand.Execute("    FUND0");
150            service.AddWatchCommand.Execute("FUND0");
151
152            Assert.AreEqual(1, service.RetrieveWatchList().Count);
153            Assert.AreEqual("FUND0", service.RetrieveWatchList()[0]);
154        }
155
156        [TestMethod]
157        public void AddingSameSymbolOneWithTrailingBlankSpacesTwiceOnlyAddsItOnceToTheList()
158        {
159            WatchListService service = new WatchListService(new MockMarketFeedService());
160
161            service.AddWatchCommand.Execute("FUND0    ");
162            service.AddWatchCommand.Execute("FUND0");
163
164            Assert.AreEqual(1, service.RetrieveWatchList().Count);
165            Assert.AreEqual("FUND0", service.RetrieveWatchList()[0]);
166        }
167
168        [TestMethod]
169        public void ServiceExposesCommandInstance()
170        {
171            WatchListService service = new WatchListService(new MockMarketFeedService());
172
173            Assert.AreEqual(0, service.RetrieveWatchList().Count);
174            service.AddWatchCommand.Execute("testSymbol");
175            Assert.AreEqual(1, service.RetrieveWatchList().Count);
176            Assert.AreEqual("TESTSYMBOL", service.RetrieveWatchList()[0]);
177
178        }
179
180
181    }
182
183    class TestableWatchListService : WatchListService
184    {
185        public TestableWatchListService(IMarketFeedService marketFeedService)
186            : base(marketFeedService)
187        {
188        }
189    }
190}