public async void IsBadRequestObjectResultCreateCategoryAsync() { // Arrange CategoryController controller = new CategoryController(mockCategoryService.Object); // Act controller.ModelState.AddModelError("Title", "Title is require value"); var result = await controller.Create(await CategoryTestHelper.GetCategoryCreateUnNormal()); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public async Task CreateCategoryTestAsync() { // Arrange CategoryController controller = new CategoryController(mockCategoryService.Object); // Act var result = await controller.Create(await CategoryTestHelper.GetCategoryCreateNormal()); var okResult = Assert.IsType <OkObjectResult>(result); // Assert Assert.IsType <OkObjectResult>(result); mockCategoryService.Verify( mock => mock.CreateCategory(It.IsAny <string>(), It.IsAny <int?>())); }
public async Task GetListCategoriesTestAsync() { // Arrange mockCategoryService.Setup(service => service.ListCategories()).ReturnsAsync(await CategoryTestHelper.GetCategories()); CategoryController controller = new CategoryController(mockCategoryService.Object); // Act var result = await controller.List(); var okResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <List <CategoryListDto> >(okResult.Value); // Assert Assert.Equal((await CategoryTestHelper.GetCategories()).Where(c => c.Id == 1).FirstOrDefault().Title, model.Where(c => c.Id == 1).FirstOrDefault().Title); }
public async Task GetCategoryTestAsync() { // Arrange mockCategoryService.Setup(service => service.SingleCategory(It.IsAny <int>())).ReturnsAsync(await CategoryTestHelper.GetCategory()); CategoryController controller = new CategoryController(mockCategoryService.Object); // Act var result = await controller.Single(It.IsAny <int>()); var okResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <CategoryViewDto>(okResult.Value); // Assert Assert.Equal((await CategoryTestHelper.GetCategory()).Title, model.Title); }