public void Should_only_get_MarketData_for_registered_rawMaterials_or_throw_an_exception_otherwise()
        {
            var marketDataProvider = new MarketDataProvider();
            marketDataProvider.RegisterRawMaterial("eggs");
            marketDataProvider.RegisterRawMaterial("flour");

            Check.That(marketDataProvider.GetRawMaterial("flour")).IsNotNull();

            Check.ThatCode(() => marketDataProvider.GetRawMaterial("banana")).Throws<InvalidOperationException>();

            Check.That(marketDataProvider.GetRawMaterial("eggs")).IsNotNull();
        }
        public void Should_only_get_MarketData_for_registered_rawMaterials_or_throw_an_exception_otherwise()
        {
            var marketDataProvider = new MarketDataProvider();

            marketDataProvider.RegisterRawMaterial("eggs");
            marketDataProvider.RegisterRawMaterial("flour");

            Check.That(marketDataProvider.GetRawMaterial("flour")).IsNotNull();

            Check.ThatCode(() => marketDataProvider.GetRawMaterial("banana")).Throws <InvalidOperationException>();

            Check.That(marketDataProvider.GetRawMaterial("eggs")).IsNotNull();
        }
        public void Should_return_the_same_instance_of_MarketData_given_the_same_rawMaterial_name()
        {
            var marketDataProvider = new MarketDataProvider();
            marketDataProvider.RegisterRawMaterial("eggs");

            Check.That(marketDataProvider.GetRawMaterial("eggs")).IsSameReferenceThan(marketDataProvider.GetRawMaterial("eggs"));
        }
        public void Should_provide_MarketData_for_eggs()
        {
            var marketDataProvider = new MarketDataProvider();
            marketDataProvider.RegisterRawMaterial("eggs");

            Check.That(marketDataProvider.GetRawMaterial("eggs")).IsInstanceOf<RawMaterialMarketData>();
        }
        public void Should_return_the_same_instance_of_MarketData_given_the_same_rawMaterial_name()
        {
            var marketDataProvider = new MarketDataProvider();

            marketDataProvider.RegisterRawMaterial("eggs");

            Check.That(marketDataProvider.GetRawMaterial("eggs")).IsSameReferenceThan(marketDataProvider.GetRawMaterial("eggs"));
        }
        public void Should_provide_MarketData_for_eggs()
        {
            var marketDataProvider = new MarketDataProvider();

            marketDataProvider.RegisterRawMaterial("eggs");

            Check.That(marketDataProvider.GetRawMaterial("eggs")).IsInstanceOf <RawMaterialMarketData>();
        }
        public void Should_receive_price_for_registered_RawMaterials_once_started()
        {
            var marketDataProvider = new MarketDataProvider();
            marketDataProvider.RegisterRawMaterial("eggs");
            
            marketDataProvider.GetRawMaterial("eggs").PriceChanged += (o, args) => this.priceChangedRaisedEvent.Set();

            marketDataProvider.Start();

            const int TimeoutInMsec = 100;
            var hasReceivedEvent = this.priceChangedRaisedEvent.WaitOne(TimeoutInMsec);
            
            Check.That(hasReceivedEvent).IsTrue();
            marketDataProvider.Stop();
        }
        public void Should_receive_price_for_registered_RawMaterials_once_started()
        {
            var marketDataProvider = new MarketDataProvider();

            marketDataProvider.RegisterRawMaterial("eggs");

            void Handler(object o, RawMaterialPriceChangedEventArgs args) => this.priceChangedRaisedEvent.Set();

            marketDataProvider.GetRawMaterial("eggs").PriceChanged += Handler;

            marketDataProvider.Start();

            const int TimeoutInMsec    = 500;
            var       hasReceivedEvent = this.priceChangedRaisedEvent.WaitOne(TimeoutInMsec);

            Check.That(hasReceivedEvent).IsTrue();
            marketDataProvider.Stop();
            marketDataProvider.GetRawMaterial("eggs").PriceChanged -= Handler;
        }