public async Task Category_PicturePost_ReturnsViewResult_WithCategoryViewModel() { // Arrange var categoryPictureViewModel = new CategoryPictureViewModel { Id = 1 }; var categoryDTO = new CategoryDTO { Id = 1, CategoryName = "One", Description = "Description 1", PictureLink = "Pictures Link 1" }; categoryServiceMock.Setup(x => x.GetCategoryById(It.IsAny <int>())) .ReturnsAsync(categoryDTO); categoryServiceMock.Setup(x => x.UpdatePictureById(It.IsAny <int>(), It.IsAny <byte[]>())); var controller = new CategoryController(categoryServiceMock.Object, configMock, loggerMock.Object); // Act var result = await controller.Picture(categoryPictureViewModel); // Assert var viewResult = Assert.IsType <ViewResult>(result); var actual = Assert.IsAssignableFrom <CategoryViewModel>(viewResult.ViewData.Model); Assert.Equal(categoryDTO.Id, actual.Id); Assert.Equal(categoryDTO.CategoryName, actual.CategoryName); Assert.Equal(categoryDTO.Description, actual.Description); Assert.Equal(categoryDTO.PictureLink, actual.PictureLink); }
public async Task <IActionResult> Picture(CategoryPictureViewModel model) { var categoryDTO = await _categoryService.GetCategoryById(model.Id); var category = ConvertToCategoryViewModel(categoryDTO); if (!ModelState.IsValid) { return(View("Edit", category)); } var picture = await ConvertToByte(model.Picture); await _categoryService.UpdatePictureById(model.Id, picture); return(View("Edit", category)); }