internal static ProductCategoryDto GetValidProductCategoryDto(ProductCategoriesController controller, bool first = true) { var result = controller.GetProductCategories(); var listResult = result.ValidateResponseAndCastTo <List <ProductCategoryDto>, OkObjectResult>((int)HttpStatusCodes.Ok); listResult.Any().Should().BeTrue(); return(first ? listResult.First() : listResult.Last()); }
public void When_getting_all_product_categories_it_should_return_a_list_with_elements() { // Arrange var controller = new ProductCategoriesController(_logger, _repository); // Act var result = controller.GetProductCategories(); var listResult = result.ValidateResponseAndCastTo <List <ProductCategoryDto>, OkObjectResult>((int)HttpStatusCodes.Ok); // Assert listResult.Any().Should().BeTrue(); }
public async Task GetProductCategory_Success() { var dbContext = _fixture.Context; dbContext.ProductCategories.Add(new ProductCategory { Name = "Test product category" }); await dbContext.SaveChangesAsync(); var controller = new ProductCategoriesController(dbContext); var result = await controller.GetProductCategories(); var actionResult = Assert.IsType <ActionResult <IEnumerable <ProductCategoryVm> > >(result); Assert.NotEmpty(actionResult.Value); }
public async Task GetProductCategoriesReturnsAResponseWithAListOfProductCategories() { var dbContext = GetDbContext(); var controller = new ProductCategoriesController(dbContext); var result = await controller.GetProductCategories(); var resultArray = result.ToArray(); resultArray.Should().NotBeNull(); resultArray.Should().HaveCount(1); var resultModel = resultArray.First(); var entity = dbContext.ProductCategories.Find(1); resultModel.Id.Should().Be(entity.Id); resultModel.Name.Should().Be(entity.Name); resultModel.Description.Should().Be(entity.Description); }