示例#1
0
        public void MarketServiceReadsIntervalFromXml()
        {
            var xmlMarketData = XDocument.Parse(Resources.TestXmlMarketData);

            using (var marketFeed = new TestableMarketFeedService(xmlMarketData, new MockPriceUpdatedEventAggregator()))
            {
                Assert.AreEqual <int>(5000, marketFeed.RefreshInterval);
            }
        }
示例#2
0
 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);
     }
 }
示例#3
0
        public void ShouldPublishUpdatedAfterUpdatingPrices()
        {
            var eventAggregator = new MockPriceUpdatedEventAggregator();

            using (var marketFeed = new TestableMarketFeedService(eventAggregator))
            {
                marketFeed.InvokeUpdatePrices();
            }
            Assert.IsTrue(eventAggregator.MockMarketPriceUpdatedEvent.PublishCalled);
        }
示例#4
0
        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"));
            }
        }
示例#5
0
        public void ShouldPublishUpdatedOnSinglePriceChange()
        {
            var eventAggregator = new MockPriceUpdatedEventAggregator();

            using (TestableMarketFeedService marketFeed = new TestableMarketFeedService(eventAggregator))
            {
                marketFeed.TestUpdatePrice("STOCK0", 30.00m, 1000);
            }

            Assert.IsTrue(eventAggregator.MockMarketPriceUpdatedEvent.PublishCalled);
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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"]);
        }
示例#8
0
        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);
        }