public void Should_publish_price_for_every_registered_pasta()
        {
            // Mock and dependencies setup
            var publisher = Substitute.For<IPastaPricerPublisher>();
            var marketDataProvider = new MarketDataProvider();
            var pastasConfiguration = new[]
                                      {
                                          "gnocchi(eggs-potatoes-flour)",
                                          "spaghetti(eggs-flour)",
                                          "organic spaghetti(organic eggs-flour)",
                                          "spinach farfalle(eggs-flour-spinach)",
                                          "tagliatelle(eggs-flour)",
                                      };

            var unitOfExecutionsFactory = new UnitOfExecutionsFactory();

            var pastaPricer = new PastaPricerEngine(unitOfExecutionsFactory.GetPool(), pastasConfiguration, marketDataProvider, publisher);
            pastaPricer.Start();

            // Turns on market data (note: make the pasta pricer start its dependencies instead?)
            marketDataProvider.Start();

            // A sleep?!? There should be a better way ;-)
            Thread.Sleep(100);

            publisher.Received().Publish("gnocchi", 2.32m);
            publisher.Received().Publish("spaghetti", 1.35m);
            publisher.Received().Publish("organic spaghetti", 0.5m);
            publisher.Received().Publish("spinach farfalle", 0.5m);
            publisher.Received().Publish("tagliatelle", 0.5m);
        }
Beispiel #2
0
        public void Should_publish_price_once_started_and_when_MarketData_is_available()
        {
            // Mock and dependencies setup
            var unitOfExecutionsFactory = new UnitOfExecutionsFactory();

            var marketDataProvider = new MarketDataProvider();

            var pastaPricer = new PastaPricerEngine(unitOfExecutionsFactory.GetPool(),
                                                    new[] { "gnocchi(eggs-potatoes-flour)" },
                                                    marketDataProvider,
                                                    this);

            this.ClearDico();
            Check.That(this.lastPrices).IsEmpty();

            pastaPricer.Start();

            Check.That(this.lastPrices).IsEmpty();

            // Turns on market data (note: make the pasta pricer start its dependencies instead?)
            marketDataProvider.Start();

            // A sleep?!? There should be a better way ;-)
            Thread.Sleep(1000);

            // It has publish a price now!
            Check.That(this.lastPrices.Keys).Contains("gnocchi");
        }
        public void Should_publish_price_once_started_and_when_MarketData_is_available()
        {
            // Mock and dependencies setup
            var unitOfExecutionsFactory = new UnitOfExecutionsFactory();
            
            var publisher = Substitute.For<IPastaPricerPublisher>();
            var marketDataProvider = new MarketDataProvider();

            var pastaPricer = new PastaPricerEngine(unitOfExecutionsFactory.GetPool(), new[] { "gnocchi(eggs-potatoes-flour)" }, marketDataProvider, publisher);
            
            CheckThatNoPriceHasBeenPublished(publisher);
            
            pastaPricer.Start();

            CheckThatNoPriceHasBeenPublished(publisher);

            // Turns on market data (note: make the pasta pricer start its dependencies instead?)
            marketDataProvider.Start();

            // A sleep?!? There should be a better way ;-)
            Thread.Sleep(60);

            // It has publish a price now!
            publisher.Received().Publish("gnocchi", 0.50m);
        }
Beispiel #4
0
        public void Should_publish_price_for_every_registered_pasta()
        {
            this.ClearDico();
            // Mock and dependencies setup
            var marketDataProvider  = new MarketDataProvider();
            var pastasConfiguration = new[]
            {
                "gnocchi(eggs-potatoes-flour)",
                "spaghetti(eggs-flour)",
                "organic spaghetti(organic eggs-flour)",
                "spinach farfalle(eggs-flour-spinach)",
                "tagliatelle(eggs-flour)",
            };

            var unitOfExecutionsFactory = new UnitOfExecutionsFactory();

            var pastaPricer = new PastaPricerEngine(unitOfExecutionsFactory.GetPool(), pastasConfiguration, marketDataProvider, this);

            pastaPricer.Start();

            // Turns on market data (note: make the pasta pricer start its dependencies instead?)
            marketDataProvider.Start();

            // A sleep?!? There should be a better way ;-)
            Stopwatch timer = new Stopwatch();

            timer.Start();
            while (timer.ElapsedMilliseconds < 20000)
            {
                lock (this.lastPrices)
                {
                    if (pastasConfiguration.Length == this.lastPrices.Count)
                    {
                        // all price received
                        break;
                    }
                    Monitor.Wait(this.lastPrices, 100);
                }
            }

            Check.That(this.lastPrices.Keys).Contains("gnocchi");
            Check.That(this.lastPrices.Keys).Contains("spaghetti");
            Check.That(this.lastPrices.Keys).Contains("organic spaghetti");
            Check.That(this.lastPrices.Keys).Contains("spinach farfalle");
            Check.That(this.lastPrices.Keys).Contains("tagliatelle");
        }