Example #1
0
        public void Get_ShouldReturnAllBookOrders()
        {
            var bookOrders = new List <BookOrder>();

            var line1 = new OrderLine("Title1", 10.5M, 1, Guid.NewGuid());

            var bookOrder1 = a.BookOrder.ForSupplier("Supplier1")
                             .WithId(Guid.NewGuid())
                             .WithLine(line1)
                             .ThatIsNew();

            bookOrders.Add(bookOrder1);

            var line2      = new OrderLine("Title2", 20.5M, 2, Guid.NewGuid());
            var bookOrder2 = a.BookOrder.ForSupplier("Supplier2")
                             .WithId(Guid.NewGuid())
                             .WithLine(line2)
                             .ThatIsApproved();

            bookOrders.Add(bookOrder2);

            BookOrderRepositoryInMemory.Store(bookOrder1);
            BookOrderRepositoryInMemory.Store(bookOrder2);

            StartServer();

            // act
            var result = Client.GetAsync("bookOrders").Result;

            // assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);
            var bookOrdersResponse =
                JsonConvert.DeserializeObject <IEnumerable <BookOrderResponseDto> >(result.Content.ReadAsStringAsync().Result)
                .ToList();

            bookOrdersResponse.Count.Should().Be(2);
            bookOrdersResponse[0].Supplier.Should().Be("Supplier1");
            bookOrdersResponse[0].State.Should().Be("New");
            bookOrdersResponse[0].Id.Should().Be(bookOrders[0].Id.ToString());
            bookOrdersResponse[0].OrderLines.Count.Should().Be(1);
            bookOrdersResponse[0].OrderLines[0].Title.Should().Be("Title1");
            bookOrdersResponse[0].OrderLines[0].Price.Should().Be(10.5M);
            bookOrdersResponse[0].OrderLines[0].Quantity.Should().Be(1);
            bookOrdersResponse[1].Supplier.Should().Be("Supplier2");
            bookOrdersResponse[1].State.Should().Be("Approved");
            bookOrdersResponse[1].Id.Should().Be(bookOrders[1].Id.ToString());
            bookOrdersResponse[1].OrderLines.Count.Should().Be(1);
            bookOrdersResponse[1].OrderLines[0].Title.Should().Be("Title2");
            bookOrdersResponse[1].OrderLines[0].Price.Should().Be(20.5M);
            bookOrdersResponse[1].OrderLines[0].Quantity.Should().Be(2);
        }
Example #2
0
        public void Post_ApproveBookOrder_WhenBookOrderIsNew_ShouldApproveBookOrder()
        {
            BookOrder bookOrder = BookOrder.CreateNew("SupplierFoo", Guid.NewGuid());

            bookOrder.State.Should().Be(BookOrderState.New);
            BookOrderRepositoryInMemory.Store(bookOrder);

            StartServer();

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

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

            storedBookOrder.State.Should().Be(BookOrderState.Approved);
        }
Example #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);
        }