public async Task CanGetCategories() { var query = queryFactory.GetAllCategoriesQuery(); var handler = new GetAllCategoriesHandler(context, mapper); var result = await handler.Handle(query); int expected = context.Categories.Count(); Assert.AreEqual(expected, result.Count()); }
public async Task GetAllCategories_Success_ReturnCategoryListVm() { //Arrange var category = new Category() { CategoryId = Constants.CategoryId, Name = "Phone", Thumbnail = "no-image.jpg" }; var products = new List <Product>() { new Product() { ProductId = Constants.ProductId, BrandName = "Pineapple", ProductName = "PinePhone X", CategoryId = category.CategoryId, Price = 1200, Stock = 12, Sku = "12312", Category = category, Images = "no-images" } }; await _fuhoDbContext.Categories.AddRangeAsync(category); await _fuhoDbContext.Products.AddRangeAsync(products); await _fuhoDbContext.SaveChangesAsync(); var getAllCategoriesQuery = new GetAllCategoriesQuery(); //Act var sut = new GetAllCategoriesHandler(_fuhoDbContext); var result = await sut.Handle(getAllCategoriesQuery, CancellationToken.None); //Assert Assert.Equal(1, result.CategoryDtos.Count); Assert.NotNull(sut); Assert.IsType <CategoryListVm>(result); }