public void MarketServiceReadsIntervalFromXml() { var xmlMarketData = XDocument.Parse(Resources.TestXmlMarketData); using (var marketFeed = new TestableMarketFeedService(xmlMarketData, new MockPriceUpdatedEventAggregator())) { Assert.AreEqual <int>(5000, marketFeed.RefreshInterval); } }
public void ShouldUpdatePricesWithin5Points() { using (var marketFeed = new TestableMarketFeedService(new MockPriceUpdatedEventAggregator())) { decimal originalPrice = marketFeed.GetPrice("STOCK0"); marketFeed.InvokeUpdatePrices(); Assert.IsTrue(Math.Abs(marketFeed.GetPrice("STOCK0") - originalPrice) <= 5); } }
public void ShouldPublishUpdatedAfterUpdatingPrices() { var eventAggregator = new MockPriceUpdatedEventAggregator(); using (var marketFeed = new TestableMarketFeedService(eventAggregator)) { marketFeed.InvokeUpdatePrices(); } Assert.IsTrue(eventAggregator.MockMarketPriceUpdatedEvent.PublishCalled); }
public void CanGetPriceAndVolumeFromMarketFeed() { using (var marketFeed = new TestableMarketFeedService(new MockPriceUpdatedEventAggregator())) { marketFeed.TestUpdatePrice("STOCK0", 40.00m, 1234); Assert.AreEqual <decimal>(40.00m, marketFeed.GetPrice("STOCK0")); Assert.AreEqual <long>(1234, marketFeed.GetVolume("STOCK0")); } }
public void ShouldPublishUpdatedOnSinglePriceChange() { var eventAggregator = new MockPriceUpdatedEventAggregator(); using (TestableMarketFeedService marketFeed = new TestableMarketFeedService(eventAggregator)) { marketFeed.TestUpdatePrice("STOCK0", 30.00m, 1000); } Assert.IsTrue(eventAggregator.MockMarketPriceUpdatedEvent.PublishCalled); }
public void RefreshIntervalDefaultsTo10SecondsWhenNotSpecified() { var xmlMarketData = XDocument.Parse(Resources.TestXmlMarketData); xmlMarketData.Element("MarketItems").Attribute("RefreshRate").Remove(); using (var marketFeed = new TestableMarketFeedService(xmlMarketData, new MockPriceUpdatedEventAggregator())) { Assert.AreEqual <int>(10000, marketFeed.RefreshInterval); } }
public void PublishedEventContainsTheUpdatedPriceList() { var eventAgregator = new MockPriceUpdatedEventAggregator(); var marketFeed = new TestableMarketFeedService(eventAgregator); Assert.IsTrue(marketFeed.SymbolExists("STOCK0")); marketFeed.InvokeUpdatePrices(); Assert.IsTrue(eventAgregator.MockMarketPriceUpdatedEvent.PublishCalled); var payload = eventAgregator.MockMarketPriceUpdatedEvent.PublishArgumentPayload; Assert.IsNotNull(payload); Assert.IsTrue(payload.ContainsKey("STOCK0")); Assert.AreEqual(marketFeed.GetPrice("STOCK0"), payload["STOCK0"]); }
public void UpdateShouldPublishWithinRefreshInterval() { var eventAggregator = new MockPriceUpdatedEventAggregator(); using (var marketFeed = new TestableMarketFeedService(eventAggregator)) { marketFeed.RefreshInterval = 500; // ms var callCompletedEvent = new System.Threading.ManualResetEvent(false); eventAggregator.MockMarketPriceUpdatedEvent.PublishCalledEvent += delegate { callCompletedEvent.Set(); }; #if SILVERLIGHT callCompletedEvent.WaitOne(5000); // Wait up to 5 seconds #else callCompletedEvent.WaitOne(5000, true); // Wait up to 5 seconds #endif } Assert.IsTrue(eventAggregator.MockMarketPriceUpdatedEvent.PublishCalled); }