public async Task GetAllBasketItems_ReturnBasketItemsInOkObjectResult_WhenGetBasketItemsIsSuccess() { //Arrange var basketItems = new List <BasketItem>() { new BasketItem(10, 1, 1), new BasketItem(20, 1, 1) }; _mockService.Setup(service => service.GetAllBasketItems(It.IsAny <int>())) .ReturnsAsync(basketItems); // inject mocked IItemService and _mapper in controller var controller = new BasketItemController(_mockService.Object); SetupHttpContextUser(controller, _user); //Act var actionResult = await controller.GetAllBasketItems() as OkObjectResult; var resultObject = GetObjectResultContent <IEnumerable <BasketItem> >(actionResult); //Assert Assert.IsType <OkObjectResult>(actionResult); Assert.Equal(serializeObject(basketItems), serializeObject(resultObject)); }
public async Task GetAllBasketItems_ReturnNotFoundResult_whenBasketItemsIsNull() { //Arrange var basketItems = new List <BasketItem>() { new BasketItem(10, 1, 1), new BasketItem(20, 1, 1) }; _mockService.Setup(service => service.GetAllBasketItems(It.IsAny <int>())) .ReturnsAsync((IEnumerable <BasketItem>)null); // inject mocked IItemService and _mapper in controller var controller = new BasketItemController(_mockService.Object); SetupHttpContextUser(controller, _user); //Act var actionResult = await controller.GetAllBasketItems(); //Assert Assert.IsType <NotFoundResult>(actionResult); }