示例#1
0
        public void Post_SendBookOrder_ExampleOfOverrideWithMock_ShouldSucceed()
        {
            BookOrder bookOrder = BookOrder.CreateNew("SupplierFoo", Guid.NewGuid());

            bookOrder.Approve();

            IBookOrderRepository mockBookOrderRepository = Substitute.For <IBookOrderRepository>();

            mockBookOrderRepository.Get(bookOrder.Id).Returns(bookOrder);

            TestContainerRegistrations = container =>
            {
                container.RegisterInstance(mockBookOrderRepository);
            };

            StartServer();

            // act
            var result = Client.Post($"bookOrders/{bookOrder.Id}/send", null);

            // assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);

            mockBookOrderRepository.Received(1).Store(Arg.Is <BookOrder>(
                                                          x => x.Id == bookOrder.Id &&
                                                          x.State == BookOrderState.Sent));
        }
        public void Execute(Guid bookOrderId)
        {
            Logger.Information("Execute ApproveBookOrderUseCase for Id: {Title}", bookOrderId);

            BookOrder bookorder = _bookOrderRepository.Get(bookOrderId);

            bookorder.Approve();

            _bookOrderRepository.Store(bookorder);
        }
示例#3
0
        public void Post_SendBookOrder_WhenBookOrderIsApproved_ShouldSendBookOrder()
        {
            BookOrder bookOrder = BookOrder.CreateNew("SupplierFoo", Guid.NewGuid());

            bookOrder.Approve();
            BookOrderRepositoryInMemory.Store(bookOrder);

            StartServer();

            // act
            var result = Client.Post($"bookOrders/{bookOrder.Id}/send", null);

            // assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);
            var storedBookOrder = BookOrderRepositoryInMemory.Get(bookOrder.Id);

            storedBookOrder.State.Should().Be(BookOrderState.Sent);

            BookSupplierGatewayInMemory.SentBookOrders.Count().Should().Be(1);
            BookSupplierGatewayInMemory.SentBookOrders[0].Id.Should().Be(bookOrder.Id);
            BookSupplierGatewayInMemory.SentBookOrders[0].State.Should().Be(BookOrderState.Sent);
        }