public async Task GetProductWhichIsNotInDb() { var query = new GetProductByIdQuery(Guid.NewGuid()); using var context = new ProductContextTestProvider().GetContext(); var handler = new GetProductByIdHandler(context, new ProductMapper()); var productCount = context.Products.Count(); var result = await handler.Handle(query); productCount.ShouldBe(0); result.ShouldBeNull(); }
public async Task GetProductById() { var query = new GetProductByIdQuery(Guid.NewGuid()); var contextProvider = new ProductContextTestProvider(); using var context = contextProvider.GetContext(); var handler = new GetProductByIdHandler(context, new ProductMapper()); contextProvider.AddProduct(new Database.Entities.Product(query.Id, "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.Number.ShouldBe("Number1"); result.Name.ShouldBe("Name1"); result.Quantity.ShouldBe(11); }
public async Task GetProductById_Success_ReturnProductDetail() { //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", CreateDate = DateTime.Now, CreatedBy = Constants.UserId.ToString() } }; await _fuhoDbContext.Products.AddRangeAsync(products); await _fuhoDbContext.SaveChangesAsync(); var getProductbyIdQuery = new GetProductByIdQuery() { ProductId = Constants.ProductId }; //Act var sut = new GetProductByIdHandler(_fuhoDbContext, _logger.Object); var result = await sut.Handle(getProductbyIdQuery, CancellationToken.None); //Assert Assert.NotNull(sut); Assert.IsType <ProductDetailVm>(result); }