public void DeleteCartItemWithValidId() { // Act var resultRaw = _controller.DeleteCartItem(2); NegotiatedContentResult <ResponseDto> result = (NegotiatedContentResult <ResponseDto>)resultRaw; ////// Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(HttpStatusCode.OK, result.Content.StatusCode); Assert.AreEqual("CarItem with id: 2 successfully deleted.", result.Content.MessageDetail); }
public void ShouldReturnInternalServerErrorWhenDeletingWithException() { // Arrange var controller = new CartController( new StubIShoppingCartRepository { GetShoppingCartString = id => new ShoppingCart(id), SaveShoppingCartShoppingCart = cart => { throw new Exception("error"); } }, null); SetupControllerForTests(controller); // Act var response = controller.DeleteCartItem(new CartItemDelete { ProductId = 11, ShoppingCartId = "id" }); var error = JsonConvert.DeserializeAnonymousType(response.Content.ReadAsStringAsync().Result, new { Message = string.Empty }); // Assert Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); Assert.AreEqual("error", error.Message); }
public void ShouldDeleteAnItem() { // Arrange var targetItemRemoved = false; var controller = new CartController( new StubIShoppingCartRepository { GetShoppingCartString = id => new ShoppingCart(id), SaveShoppingCartShoppingCart = cart => { targetItemRemoved = true; return(cart); } }, null); SetupControllerForTests(controller); // Act var response = controller.DeleteCartItem(new CartItemDelete { ProductId = 11, ShoppingCartId = "id" }); // Assert Assert.IsTrue(targetItemRemoved); Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); }
public async Task Check_DeleteCartItem_ReturnOk() { // Arrange var controller = new CartController(_dbContext); UserTempStorage.cartID = 1; CartItems ci = new CartItems(); ci.GameId = 1; // Act IActionResult deleteItem = await controller.DeleteCartItem(ci); //string var = results.RouteValues["id"].ToString(); // Assert Assert.IsInstanceOf <OkObjectResult>(deleteItem); }
public void ShouldReturnNotFoundWhenDeletingItemFromUnexistentCart() { // Arrange var controller = new CartController( new StubIShoppingCartRepository { GetShoppingCartString = (id) => null }, null); SetupControllerForTests(controller); // Act var response = controller.DeleteCartItem(new CartItemDelete { ProductId = 11, ShoppingCartId = "id" }); var error = JsonConvert.DeserializeAnonymousType(response.Content.ReadAsStringAsync().Result, new { Message = string.Empty }); // Assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }