public void DispatcherHandlerTest() { var dispatcher = new Dispatcher(); var reportingStore = new ReportingStore(); var assistantManagerDispatcher = new DispatcherHandleOrder(dispatcher, "assistant"); var cashierDispatcher = new DispatcherHandleOrder(dispatcher, "cashier"); var cashier = new Cashier(cashierDispatcher, new FakeOrdersStore()); var cookDispatcher = new DispatcherHandleOrder(dispatcher, "cook"); var waiterDispatcher = new DispatcherHandleOrder(dispatcher, "waiter"); var waiter = new Waiter(waiterDispatcher); dispatcher.Subscribe("waiter", new QueuedHandleOrders(new Cook(cookDispatcher, new FakeIngredientsStore()), "cook")); dispatcher.Subscribe("cook", cashier); dispatcher.Subscribe("cashier", new QueuedHandleOrders(new AssistantManager(assistantManagerDispatcher, new FakePriceTable()), "assistant")); dispatcher.Subscribe("assistant", new QueuedHandleOrders(new Manger(reportingStore), "manager")); waiter.CreateOrder(); Thread.Sleep(100); cashier.PayFor(123); Thread.Sleep(1000); Assert.That(reportingStore.StoredOrders.Count, Is.EqualTo(1)); }
public void Should_Store_The_Order_For_Later_Payment() { var fakeOrdersHandler = new FakeOrdersHandler(); var orderStore = new FakeOrdersStore(); var cashier = new Cashier(fakeOrdersHandler, orderStore); cashier.Handle(SampleOrders.CreateSampleOrder()); Assert.That(orderStore.HasOrderForTable(123)); }
public void Should_Pass_The_Paid_Order_Forward() { var fakeOrdersHandler = new FakeOrdersHandler(); var orderStore = new FakeOrdersStore(); var cashier = new Cashier(fakeOrdersHandler, orderStore); cashier.Handle(SampleOrders.CreateSampleOrder()); cashier.PayFor(123); Assert.That(fakeOrdersHandler.OrdersToBeHandled.Count, Is.EqualTo(1)); }
public void Should_Mark_Order_As_Paid() { var fakeOrdersHandler = new FakeOrdersHandler(); var orderStore = new FakeOrdersStore(); var cashier = new Cashier(fakeOrdersHandler, orderStore); cashier.Handle(SampleOrders.CreateSampleOrder()); cashier.PayFor(123); Assert.That(fakeOrdersHandler.OrdersToBeHandled[0].Paid); }
public void IntegrationTest() { var reportingStore = new ReportingStore(); var manager = new QueuedHandleOrders(new Manger(reportingStore), "manager"); var cashier = new Cashier(manager, new FakeOrdersStore()); var queuedCashier = new QueuedHandleOrders(cashier, "cashier"); var cook = new QueuedHandleOrders(new Cook(queuedCashier, new FakeIngredientsStore()), "cook"); var waiter = new Waiter(cook); waiter.CreateOrder(); Thread.Sleep(3000); cashier.PayFor(123); Thread.Sleep(10000); Assert.That(reportingStore.StoredOrders.Count, Is.EqualTo(1)); }
public void MidgetMonitorTest() { var dispatcher = new Dispatcher(); var reportingStore = new ReportingStore(); var notifyDispatcher = new NotifyDispatcher(dispatcher); IScheduler theScheduler = new NeverTimesOut(); var cashier = new Cashier(notifyDispatcher, new FakeOrdersStore()); var midgetHouse = new MidgetHouse(dispatcher, theScheduler); var waiter = new Waiter(midgetHouse); dispatcher.Subscribe("cook", new QueuedHandleOrders(new Cook(notifyDispatcher, new FakeIngredientsStore()), "cook")); dispatcher.Subscribe("cashier", cashier); dispatcher.Subscribe("assistant", new QueuedHandleOrders(new AssistantManager(notifyDispatcher, new FakePriceTable()), "assistant")); dispatcher.Subscribe("manger", new QueuedHandleOrders(new Manger(reportingStore), "manager")); dispatcher.SubscribeMidgetInfo("midgetObserver", new MidgetObserver()); waiter.CreateOrder(); Thread.Sleep(2000); cashier.PayFor(123); Thread.Sleep(1000); Assert.That(reportingStore.StoredOrders.Count, Is.EqualTo(1)); }
public void PerformanceTestReportWithMultipleCooks() { var reportingStore = new ReportingStore(); var manager = new QueuedHandleOrders(new Manger(reportingStore), "manager"); var cashier = new Cashier(manager, new FakeOrdersStore()); var queuedCashier = new QueuedHandleOrders(cashier, "cashier"); var cook = new QueuedHandleOrders(new RoundRobinHandleOrder(new List<IHandleOrders>() { new Cook(queuedCashier, new FakeIngredientsStore()), new Cook(queuedCashier, new FakeIngredientsStore()), new Cook(queuedCashier, new FakeIngredientsStore()) }, "multiple cooks"), "cook"); var waiter = new Waiter(cook); var monitor = new StatsMonitor(new List<IStatisticTrigger>() { cook, queuedCashier, manager }); for (int i = 0; i < 10000; ++i) { waiter.CreateOrderWithTable(i); } Thread.Sleep(10000); int paidClients = 0; while (paidClients != 10000) { for (int i = 0; i < 10000; ++i) { bool result = cashier.PayFor(i); if (result) { paidClients++; } } } Thread.Sleep(100000); }
public void ObserverNotifyTest() { var dispatcher = new Dispatcher(); var reportingStore = new ReportingStore(); var assistantManagerDispatcher = new DispatcherHandleOrder(dispatcher, "assistant"); var cashierDispatcher = new DispatcherHandleOrder(dispatcher, "cashier"); var cashier = new Cashier(cashierDispatcher, new FakeOrdersStore()); var cookDispatcher = new DispatcherHandleOrder(dispatcher, "cook"); var waiterDispatcher = new DispatcherHandleOrder(dispatcher, "waiter"); var waiter = new Waiter(waiterDispatcher); dispatcher.Subscribe("waiter", new QueuedHandleOrders(new Cook(cookDispatcher, new FakeIngredientsStore()), "cook")); dispatcher.Subscribe("cook", cashier); dispatcher.Subscribe("cashier", new QueuedHandleOrders(new AssistantManager(assistantManagerDispatcher, new FakePriceTable()), "assistant")); dispatcher.Subscribe("assistant", new QueuedHandleOrders(new Manger(reportingStore), "manager")); dispatcher.SubscribeByCorrelationId("#1", new DelegateObserver((order) => Console.WriteLine("Document changed: {0}", order.TotalTax))); waiter.CreateOrder(); Thread.Sleep(300); cashier.PayFor(123); Thread.Sleep(2000); Assert.That(reportingStore.StoredOrders.Count, Is.EqualTo(1)); }