public void Create_IntervalChangesAccordingToProductParams() { var factory = new OrderDeterriorationTimerFactory(); var kitchenShelf = new KitchenShelf("hot", 10, 1); var shelfOrder = new ShelfOrder(new Order() { ShelfLife = 300, DecayRate = 0.5 }, DateTime.Now); var timer1 = factory.Create(kitchenShelf, shelfOrder); var shelfOrderWithLowerShelfLife = new ShelfOrder(new Order() { ShelfLife = 100, DecayRate = 0.5, }, DateTime.Now); var timer2 = factory.Create(kitchenShelf, shelfOrderWithLowerShelfLife); var shelfOrderWithHigherDecayRate = new ShelfOrder(new Order() { ShelfLife = 300, DecayRate = 1, }, DateTime.Now); var timer3 = factory.Create(kitchenShelf, shelfOrderWithHigherDecayRate); Assert.IsTrue(timer1.Interval > timer2.Interval); Assert.IsTrue(timer1.Interval > timer3.Interval); }
/// <inheritdoc/> public void PublishOrderReceivedEvent(KitchenShelf shelf, Order order) { queuePublisher.Publish(new DeliverySimulatorEvent() { Message = $"Order {order.Id} was cooked and placed into \"{shelf.Temp}\" shelf. Number of items in shelf - {shelf.Orders.Count} / {shelf.MaxCapacity}." }); }
/// <summary> /// Get timer based on order max age for specific shelf /// </summary> /// <param name="shelf">Shelf which contains the order</param> /// <param name="order">Order</param> /// <returns>Timer with calculated interval</returns> public Timer Create(KitchenShelf shelf, ShelfOrder order) { var timer = new Timer(order.GetMaxOrderAge(shelf.DecayModifier) * 1000); timer.AutoReset = false; return(timer); }
/// <summary> /// Create timer with random interval set in predefined boundaries /// </summary> /// <param name="shelf">This parameter is ignored</param> /// <param name="order">This parameter is ignored</param> /// <returns></returns> public Timer Create(KitchenShelf shelf, ShelfOrder order) { var courierArrivalDelay = random.Next( AppSettings.Instance.AppConfig.Shelves.Timers.CourierTimerMinDelay, AppSettings.Instance.AppConfig.Shelves.Timers.CourierTimerMaxDelay); var timer = new Timer(TimeSpan.FromSeconds(courierArrivalDelay).TotalMilliseconds); timer.AutoReset = false; return(timer); }