public void ReceiveMultiple_WithTriggeringPrice_Raises_OrderPlacedEvent_Only_Once_And_Is_Effectively_Shutdown(int numberOfTimesToReceiveTick) { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 300m; var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); for (int i = 0; i < numberOfTimesToReceiveTick; i++) { concreteEquityOrder.ReceiveTick(equityCode, price); } A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeLoggerService.Info($"Bought equityCode '{equityCode}' at price '{price}'")).MustHaveHappenedOnceExactly(); }
public void ReceiveTick_WithNonTriggeringPrice_DoesNot_Raise_OrderPlacedEvent() { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 115m; var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); using (var monitoredConcreteEquityOrder = concreteEquityOrder.Monitor()) { concreteEquityOrder.ReceiveTick(equityCode, price); monitoredConcreteEquityOrder.Should().NotRaise("OrderPlaced"); } A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)).MustNotHaveHappened(); A.CallTo(() => fakeLoggerService.Info($"Bought equityCode '{equityCode}' at price '{price}'")).MustNotHaveHappened(); }
public void ReceiveTick_WithTriggeringPrice_Raises_OrderPlacedEvent() { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 300m; var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); using (var monitoredConcreteEquityOrder = concreteEquityOrder.Monitor()) { concreteEquityOrder.ReceiveTick(equityCode, price); monitoredConcreteEquityOrder.Should().Raise("OrderPlaced") .WithArgs <OrderPlacedEventArgs>(args => args.EquityCode == equityCode && args.Price == price); } A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeLoggerService.Info($"Bought equityCode '{equityCode}' at price '{price}'")).MustHaveHappenedOnceExactly(); }
public void ReceiveTick_WithNonTriggeringPrice_When_Given_OrderService_That_Throws_DoesNotRaise_OrderErroredEvent() { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 115m; A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)) .Throws(() => new InvalidOperationException($"Bad buy received equityCode: '{equityCode}', price: '{price}'")); var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); using (var monitoredConcreteEquityOrder = concreteEquityOrder.Monitor()) { concreteEquityOrder.ReceiveTick(equityCode, price); monitoredConcreteEquityOrder.Should().NotRaise("OrderErrored"); } A.CallTo(() => fakeLoggerService.Error($"Error seen in ReceiveTick: Bad buy received equityCode: '{equityCode}', price: '{price}'", A <InvalidOperationException> ._)).MustNotHaveHappened(); }
public async Task ReceiveMultipleAsync_WithTriggeringPrice_Raises_OrderPlacedEvent_Only_Once_And_Is_Effectively_Shutdown(int numberOfTimesToReceiveTick) { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 300m; var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); var tasks = Enumerable.Range(0, numberOfTimesToReceiveTick).Select(x => Task.Run(() => { concreteEquityOrder.ReceiveTick(equityCode, price); })).ToArray(); await Task.WhenAll(tasks); A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeLoggerService.Info($"Bought equityCode '{equityCode}' at price '{price}'")).MustHaveHappenedOnceExactly(); }
public void ReceiveMultiple_WithTriggeringPrice_When_Given_OrderService_That_ThrowsOnce_Is_Effectively_Shutdown(int numberOfTimesToReceiveTick) { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 300m; A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)) .Throws(() => new InvalidOperationException($"Bad buy received equityCode: '{equityCode}', price: '{price}'")).NumberOfTimes(1); var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); for (int i = 0; i < numberOfTimesToReceiveTick; i++) { concreteEquityOrder.ReceiveTick(equityCode, price); } A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeLoggerService.Error($"Error seen in ReceiveTick: Bad buy received equityCode: '{equityCode}', price: '{price}'", A <InvalidOperationException> ._)).MustHaveHappenedOnceExactly(); }
public async Task ReceiveMultipleAsync_WithTriggeringPrice_When_Given_OrderService_That_Throws_Is_Effectively_Shutdown(int numberOfTimesToReceiveTick) { var fakeOrderService = A.Fake <IOrderService>(); var fakeLoggerService = A.Fake <ILoggerService>(); var equityCode = "GBPEUR"; var price = 253.5m; var threshold = 300m; A.CallTo(() => fakeOrderService.Buy(equityCode, A <int> ._, price)) .Throws(() => new InvalidOperationException($"Bad buy received equityCode: '{equityCode}', price: '{price}'")).NumberOfTimes(numberOfTimesToReceiveTick); var concreteEquityOrder = new ConcreteEquityOrder(threshold, fakeOrderService, fakeLoggerService); var tasks = Enumerable.Range(0, numberOfTimesToReceiveTick).Select(x => Task.Run(() => { concreteEquityOrder.ReceiveTick(equityCode, price); })).ToArray(); await Task.WhenAll(tasks); A.CallTo(() => fakeLoggerService.Error($"Error seen in ReceiveTick: Bad buy received equityCode: '{equityCode}', price: '{price}'", A <InvalidOperationException> ._)) .MustHaveHappenedOnceOrMore(); }