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); }
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); }
public void Factory_should_create_worker_unit() { var factory = new UnitOfExecutionsFactory(); var threadExec = factory.GetDedicatedThread(); Check.That(threadExec).IsNotNull(); }
public void Factory_should_decrease_core_count() { var factory = new UnitOfExecutionsFactory(); var initialCount = factory.AvailableCore; var threadExec = factory.GetDedicatedThread(); Check.That(threadExec).IsNotNull(); Check.That(factory.AvailableCore).IsEqualTo(initialCount - 1); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { Console.WriteLine("Welcome to the pasta pricer (powered by the Michonne library)."); Console.WriteLine("Conflation Y/N?"); var option = Console.ReadLine(); bool conflationEnabled = false; if (option.ToUpper().StartsWith("Y")) { conflationEnabled = true; Console.WriteLine("Conflation enabled!\n"); } else { Console.WriteLine("NO Conflation\n"); } Console.WriteLine(" Type 'Enter' to start market data inputs."); Console.WriteLine(" Then type 'Enter' again, to stop market data inputs."); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.DarkGray; var publisher = new ConsolePastaPricerPublisher(); var marketDataProvider = new AggresiveMarketDataProvider(aggressionFactor: 50, timerPeriodInMsec:2); //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, conflationEnabled); pastaPricer.Start(); // Turns on market data marketDataProvider.Start(); Console.ReadLine(); Console.WriteLine("----------------\nMarket data is stopping.\n----------------\n"); marketDataProvider.Stop(); publisher.CountPublish(); Console.WriteLine(Environment.NewLine); Console.WriteLine("----------------\nMarket data stopped. Wait a while, and type 'Enter' to exit.\n----------------\n"); Console.ReadLine(); Console.WriteLine("{0} late prices have been published since we stopped the market data.", publisher.PublicationCounter); Console.WriteLine("Type Enter to exit the program."); }
public void Factory_should_create_pool_unit() { var factory = new UnitOfExecutionsFactory(); var poolExec = factory.GetPool(); Check.That(poolExec).IsNotNull(); }
public void Factory_should_detect_number_of_cores() { var factory = new UnitOfExecutionsFactory(); Check.That(factory.CoreCount).IsEqualTo(Environment.ProcessorCount); }