public async Task GetProdustListTest() { var sut = new GetAllProductsHandler(_context); var result = await sut.Handle(new GetAllProductsQuery(), CancellationToken.None); foreach (var product in result) { product.Should().BeOfType <ProductViewModel>(); } result.Count.Should().Be(3); }
public async Task GetAllWhenDbIsEmpty() { var query = new GetAllProductsQuery(); using var context = new ProductContextTestProvider().GetContext(); var handler = new GetAllProductsHandler(context, new ProductMapper()); var productCount = context.Products.Count(); var result = await handler.Handle(query); productCount.ShouldBe(0); result.ShouldNotBeNull(); result.ShouldBeEmpty(); }
public async Task GetAll() { var query = new GetAllProductsQuery(); var contextProvider = new ProductContextTestProvider(); using var context = contextProvider.GetContext(); var handler = new GetAllProductsHandler(context, new ProductMapper()); contextProvider.AddProduct(new Database.Entities.Product(Guid.NewGuid(), "Name1", "Number1", 11, 22)); contextProvider.AddProduct(new Database.Entities.Product(Guid.NewGuid(), "Name2", "Number2", 12, 23)); contextProvider.AddProduct(new Database.Entities.Product(Guid.NewGuid(), "Name3", "Number3", 13, 24)); var productCount = context.Products.Count(); var result = await handler.Handle(query); productCount.ShouldBe(3); result.ShouldNotBeNull(); result.ShouldNotBeEmpty(); result.Count.ShouldBe(3); }
public async Task GetAllProducts_Success_ReturnProductListVm() { //Arrange var category = new Category() { CategoryId = Constants.CategoryId, Name = "Phone", Thumbnail = "no-image.jpg" }; var productOption = new List <ProductOption>() { new ProductOption() { ProductOptionId = Guid.NewGuid(), OptionKey = "Color", OptionValues = "Black, Product Red, White" }, new ProductOption() { ProductOptionId = Guid.NewGuid(), OptionKey = "Capacity", OptionValues = "64GB, 128GB" } }; 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, ProductOptions = productOption, Images = "no-images" } }; await _fuhoDbContext.Products.AddRangeAsync(products); await _fuhoDbContext.SaveChangesAsync(); var getAllProductsQuery = new GetAllProductsQuery() { Page = 1, PageSize = 10 }; //Act var sut = new GetAllProductsHandler(_fuhoDbContext); var result = await sut.Handle(getAllProductsQuery, CancellationToken.None); //Assert Assert.Equal(1, result.ProductDtos.Count); Assert.NotNull(sut); Assert.IsType <ProductListVm>(result); }