public async void Patch_Catalog_Item_Success() { var expectedProduct = CatalogServiceTestHelper.GetFakeProduct(); _repository.Setup(x => x.CreateProductAsync ( It.Is <Product>(y => y == expectedProduct) )) .Returns(Task.CompletedTask); _repository.Setup(x => x.GetProductByIdAsync ( It.Is <int>(y => y == expectedProduct.ProductId) )) .Returns(Task.FromResult(expectedProduct)); //Act var controller = new ProductController(_repository.Object, _mapper, _env.Object); var actionResult = await controller.Patch(expectedProduct.ProductId, CatalogServiceTestHelper.GetFakePatchDocumentToReplaceVolume()); //Assert var redirectToActionResult = Assert.IsType <CreatedAtActionResult>(actionResult); Assert.Equal("Get", redirectToActionResult.ActionName); Assert.Equal(201, redirectToActionResult.StatusCode); Assert.True(redirectToActionResult.RouteValues.ContainsKey("id")); }
public async void Get_Product_Success() { //Arrange var productId = 1; var expectedName = "Tasty Beer"; var expectedPrice = 6.00; var fakeProduct = CatalogServiceTestHelper.GetFakeProduct(); _repository.Setup(x => x.GetProductByIdAsync ( It.Is <int>(y => y == productId) )) .Returns(Task.FromResult(fakeProduct)); //Act var controller = new ProductController(_repository.Object, _mapper, _env.Object); var actionResult = await controller.Get(productId); //Assert var viewResult = Assert.IsType <OkObjectResult>(actionResult); var model = Assert.IsType <ProductViewModel>(viewResult.Value); Assert.Equal(expectedName, model.ProductName); Assert.Equal(expectedPrice, model.Price); }
public void Mapper_Maps_Product_To_ProductViewModel() { var expectedStockQuantity = 50; var expectedPrice = 6.00; var product = CatalogServiceTestHelper.GetFakeProduct(); var productViewModel = _mapper.Map <ProductViewModel>(product); Assert.IsType <ProductViewModel>(productViewModel); Assert.Equal(expectedStockQuantity, productViewModel.Quantity); Assert.Equal(expectedPrice, productViewModel.Price); }
public async void Post_Catalog_Item_Success() { var expectedProduct = CatalogServiceTestHelper.GetFakeProduct(); _repository.Setup(x => x.UpdateProductAsync ( It.Is <Product>(y => y == expectedProduct) )) .Returns(Task.CompletedTask); //Act var controller = new ProductController(_repository.Object, _mapper, _env.Object); var actionResult = await controller.Post(CatalogServiceTestHelper.GetFakeProductViewModel()); //Assert var redirectToActionResult = Assert.IsType <CreatedAtActionResult>(actionResult); Assert.Equal("Get", redirectToActionResult.ActionName); Assert.Equal(201, redirectToActionResult.StatusCode); }
public async void Get_Catalog_Item_Picture_Success() { var expectedProduct = CatalogServiceTestHelper.GetFakeProduct(); var expectedContentType = "image/png"; _repository.Setup(x => x.GetProductByIdAsync ( It.Is <int>(y => y == expectedProduct.ProductId) )) .Returns(Task.FromResult(expectedProduct)); _env.Setup(x => x.WebRootPath) .Returns("Content/images/"); //Act var controller = new ProductController(_repository.Object, _mapper, _env.Object); var actionResult = await controller.GetImageAsync(expectedProduct.ProductId); //Assert var fileActionResult = Assert.IsType <FileContentResult>(actionResult); Assert.Equal(expectedContentType, fileActionResult.ContentType); }