public async Task AddBasketItem_ReturnBadRequestResult_WhenQuantityIsInvalid() { //Arrange var newBasketItem = new BasketItem(10, 1, 1); _mockService.Setup(service => service.AddBasketItem(It.IsAny <BasketItem>())) .ReturnsAsync(newBasketItem); var controller = new BasketItemController(_mockService.Object); SetupHttpContextUser(controller, _user); //Act var actionResult = await controller.AddBasketItem(10, 51); //Assert Assert.IsType <BadRequestObjectResult>(actionResult); }
public async Task AddBasketItem_ReturnNotFoundResult_WhenBasketItemIsNull() { //Arrange var newBasketItem = new BasketItem(10, 1, 1); _mockService.Setup(service => service.AddBasketItem(It.IsAny <BasketItem>())) .ReturnsAsync((BasketItem)null); var controller = new BasketItemController(_mockService.Object); SetupHttpContextUser(controller, _user); //Act var actionResult = await controller.AddBasketItem(10, 1); //Assert Assert.IsType <NotFoundResult>(actionResult); }
public async Task AddBasketItem_ReturnBasketItemInOkObjectResult_WhenAddBasketItemIsSuccess() { //Arrange var newBasketItem = new BasketItem(10, 1, 1); _mockService.Setup(service => service.AddBasketItem(It.IsAny <BasketItem>())) .ReturnsAsync(newBasketItem); var controller = new BasketItemController(_mockService.Object); SetupHttpContextUser(controller, _user); //Act var actionResult = await controller.AddBasketItem(10, 1) as OkObjectResult; var resultObject = GetObjectResultContent <BasketItem>(actionResult); //Assert Assert.IsType <OkObjectResult>(actionResult); Assert.Equal(serializeObject(newBasketItem), serializeObject(resultObject)); }