예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        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();
        }
예제 #7
0
        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();
        }