public void EmptyYourBasket() { using (var context = GetContextWithData()) using (var controller = new BasketController(context)) { BasketRequest model = new BasketRequest(); model.ClientId = "A120"; model.Quantity = 1; model.SKU = "P113"; IActionResult result = controller.Add(model); Assert.IsType <OkResult>(result); model = new BasketRequest(); model.ClientId = "A120"; model.Quantity = 1; model.SKU = "P113"; result = controller.Add(model); Assert.IsType <OkResult>(result); controller.EmptyBasket("A120"); List <BasketRequest> list = (List <BasketRequest>)controller.Get("A120"); Assert.True(list.Count == 0); } }
public void CheckAddProductsToABasket() { using (var context = GetContextWithData()) using (var controller = new BasketController(context)) { BasketRequest model = new BasketRequest(); model.ClientId = "A120"; model.Quantity = 1; model.SKU = "P113"; IActionResult result = controller.Add(model); Assert.IsType <OkResult>(result); model = new BasketRequest(); model.ClientId = "A120"; model.Quantity = 1; model.SKU = "P113"; result = controller.Add(model); Assert.IsType <OkResult>(result); List <BasketRequest> list = (List <BasketRequest>)controller.Get("A120"); Assert.NotNull(list); Assert.Single(list); Assert.True(list[0].SKU == "P113" && list[0].TotalPrice == 280 && list[0].Quantity == 2); } }
public void GivenIHaveAddedTheFollowingItemsToMyBasket(Table table) { foreach (var row in table.Rows) { _basket_Controller.Add(int.Parse(row["ProductId"])); } }
public void Add_ShouldCall_BasketServiceAdd() { // Given var basketId = Guid.NewGuid(); var itemId = Guid.NewGuid(); var basketViewModel = new BasketViewModel { BasketId = basketId }; _basketService.Setup(x => x.Add(basketId, itemId)).Returns(basketViewModel); // When var result = _basketController.Add(basketId, itemId); // Then result.Value.ShouldBe(basketViewModel); }
public void AddProductToABasket() { using (var context = GetContextWithData()) using (var controller = new BasketController(context)) { BasketRequest model = new BasketRequest(); model.ClientId = "A111"; model.Quantity = 1; model.SKU = "P113"; IActionResult result = controller.Add(model); Assert.IsType <OkResult>(result); } }
public void TryAddProductToABasket() { using (var context = GetContextWithData()) using (var controller = new BasketController(context)) { BasketRequest model = new BasketRequest(); model.ClientId = "A111"; model.Quantity = 1; model.SKU = "P116"; IActionResult result = controller.Add(model); Assert.IsType <BadRequestObjectResult>(result); BasketResponse value = (BasketResponse)((Microsoft.AspNetCore.Mvc.ObjectResult)result).Value; Assert.Equal(BasketError.ProductNotAvailable, value.Error); Assert.False(value.Success); Assert.Equal(0, (int)value.SuccessResult); } }