예제 #1
0
        public async Task Cancel_basket_and_check_order_status_cancelled()
        {
            using (var orderServer = new OrderingScenariosBase().CreateServer())
                using (var basketServer = new BasketScenariosBase().CreateServer())
                {
                    // Expected data
                    var cityExpected        = $"city-{Guid.NewGuid()}";
                    var orderStatusExpected = "cancelled";

                    var basketClient = basketServer.CreateIdempotentClient();
                    var orderClient  = orderServer.CreateIdempotentClient();

                    // GIVEN a basket is created
                    var contentBasket = new StringContent(BuildBasket(), UTF8Encoding.UTF8, "application/json");
                    await basketClient.PostAsync(BasketScenariosBase.Post.CreateBasket, contentBasket);

                    // AND basket checkout is sent
                    await basketClient.PostAsync(BasketScenariosBase.Post.CheckoutOrder, new StringContent(BuildCheckout(cityExpected), UTF8Encoding.UTF8, "application/json"));

                    // WHEN Order is created in Ordering.api
                    var newOrder = await TryGetNewOrderCreated(cityExpected, orderClient);

                    // AND Order is cancelled in Ordering.api
                    await orderClient.PutAsync(OrderingScenariosBase.Put.CancelOrder, new StringContent(BuildCancelOrder(newOrder.OrderNumber), UTF8Encoding.UTF8, "application/json"));

                    // AND the requested order is retrieved
                    var order = await TryGetOrder(newOrder.OrderNumber, orderClient);

                    // THEN check status
                    Assert.Equal(orderStatusExpected, order.Status);
                }
        }
예제 #2
0
        public async Task Post_update_product_price_and_catalog_and_basket_list_modified()
        {
            decimal priceModification = 0.15M;
            string  userId            = "JohnId";

            using (var catalogServer = new CatalogScenariosBase().CreateServer())
                using (var basketServer = new BasketScenariosBase().CreateServer())
                {
                    var catalogClient = catalogServer.CreateClient();
                    var basketClient  = basketServer.CreateClient();

                    // GIVEN a product catalog list
                    var originalCatalogProducts = await GetCatalogAsync(catalogClient);

                    // AND a user basket filled with products
                    var basket = ComposeBasket(userId, originalCatalogProducts.Data.Take(3));
                    var res    = await basketClient.PostAsync(
                        BasketScenariosBase.Post.CreateBasket,
                        new StringContent(JsonConvert.SerializeObject(basket), UTF8Encoding.UTF8, "application/json")
                        );

                    // WHEN the price of one product is modified in the catalog
                    var itemToModify = basket.Items[2];
                    var oldPrice     = itemToModify.UnitPrice;
                    var newPrice     = oldPrice + priceModification;
                    var pRes         = await catalogClient.PutAsync(CatalogScenariosBase.Put.UpdateCatalogProduct, new StringContent(ChangePrice(itemToModify, newPrice, originalCatalogProducts), UTF8Encoding.UTF8, "application/json"));

                    var modifiedCatalogProducts = await GetCatalogAsync(catalogClient);

                    var itemUpdated = await GetUpdatedBasketItem(newPrice, itemToModify.ProductId, userId, basketClient);

                    if (itemUpdated == null)
                    {
                        Assert.False(true, $"The basket service has not been updated.");
                    }
                    else
                    {
                        //THEN the product price changes in the catalog
                        Assert.Equal(newPrice, modifiedCatalogProducts.Data.Single(it => it.Id == itemToModify.ProductId).Price);

                        // AND the products in the basket reflects the changed priced and the original price
                        Assert.Equal(newPrice, itemUpdated.UnitPrice);
                        Assert.Equal(oldPrice, itemUpdated.OldUnitPrice);
                    }
                }
        }