示例#1
0
        public async void Post_BookRequest_WhenOrderDoesNotExistForSupplier_ShouldCreateNewBookOrder()
        {
            StartServer();

            var jsonObject = JsonConvert.SerializeObject(new
            {
                Title    = "The Maltese Falcon",
                Supplier = "Test",
                Price    = 25.50,
                Quantity = 1
            });

            var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json");

            // act
            HttpResponseMessage response = await Client.PostAsync("bookRequests", stringContent);

            // assert
            response.StatusCode.Should().Be(HttpStatusCode.Created);

            var storedBookOrders = BookOrderRepositoryInMemory.GetBySupplier("Test").ToList();

            storedBookOrders.Should().NotBeEmpty();
            storedBookOrders.Count().Should().Be(1);
            storedBookOrders[0].Supplier.Should().Be("Test");
            storedBookOrders[0].State.Should().Be(BookOrderState.New);
            storedBookOrders[0].OrderLines[0].Title.Should().Be("The Maltese Falcon");
            storedBookOrders[0].OrderLines[0].Price.Should().Be(25.50M);
            storedBookOrders[0].OrderLines[0].Quantity.Should().Be(1);
        }
示例#2
0
        public async void Post_BookRequest_WhenNewOrderExistsForSupplier_ShouldAddRequestToExistingSupplierOrder()
        {
            StartServer();

            var bookRequest1 = JsonConvert.SerializeObject(new
            {
                Title    = "The Maltese Falcon",
                Supplier = "Test",
                Price    = 25.50,
                Quantity = 1
            });

            // add initial book for the supplier
            var stringContent             = new StringContent(bookRequest1, Encoding.UTF8, "application/json");
            HttpResponseMessage response1 = await Client.PostAsync("bookRequests", stringContent);

            var bookRequest2 = JsonConvert.SerializeObject(new
            {
                Title    = "Gone With the Wind",
                Supplier = "Test",
                Price    = 30.50,
                Quantity = 2
            });

            stringContent = new StringContent(bookRequest2, Encoding.UTF8, "application/json");

            // act
            HttpResponseMessage response2 = await Client.PostAsync("bookRequests", stringContent);

            // assert
            response1.StatusCode.Should().Be(HttpStatusCode.Created);
            response2.StatusCode.Should().Be(HttpStatusCode.Created);

            response1.Headers.Location.ToString().Should().StartWith("bookOrders");
            response2.Headers.Location.ToString().Should().StartWith("bookOrders");

            var storedBookOrders = BookOrderRepositoryInMemory.GetBySupplier("Test").ToList();

            storedBookOrders.Should().NotBeEmpty();
            storedBookOrders.Count().Should().Be(1);
            storedBookOrders[0].Supplier.Should().Be("Test");
            storedBookOrders[0].State.Should().Be(BookOrderState.New);
            storedBookOrders[0].OrderLines[0].Title.Should().Be("The Maltese Falcon");
            storedBookOrders[0].OrderLines[0].Price.Should().Be(25.50M);
            storedBookOrders[0].OrderLines[0].Quantity.Should().Be(1);
            storedBookOrders[0].OrderLines[1].Title.Should().Be("Gone With the Wind");
            storedBookOrders[0].OrderLines[1].Price.Should().Be(30.50M);
            storedBookOrders[0].OrderLines[1].Quantity.Should().Be(2);
        }