public async Task AddProductCommandHandle_AddsProduct() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); AllMarktContextIM.SaveChanges(); var addProductCommand = new AddProductCommand { Name = "Test Name1", Description = "Test Description1", Price = 10, ImageURI = "", State = true, ProductCategoryId = productCategory.Id }; //Act await _addProductCommandHandler.Handle(addProductCommand, CancellationToken.None); //Assert AllMarktContextIM.Products.Should() .Contain(product => product.Name == addProductCommand.Name && product.Description == addProductCommand.Description && product.Price == addProductCommand.Price && product.ImageURI == addProductCommand.ImageURI && product.State == addProductCommand.State && product.ProductCategory.Id == addProductCommand.ProductCategoryId); }
public async Task DeleteProduct_CommandHandle_DeletesExistingProducty() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); await AllMarktContextIM.SaveChangesAsync(); AllMarktContextIM.Products.Add(new AllMarkt.Entities.Product { Name = "Test Name1", Description = "Test Description1", Price = 10, ImageURI = "", State = true, ProductCategory = productCategory }); await AllMarktContextIM.SaveChangesAsync(); var existingProduct = AllMarktContextIM.Products.First(); var deleteProductCommand = new DeleteProductCommand { Id = existingProduct.Id }; //Act await _deleteProductCommandHandler.Handle(deleteProductCommand, CancellationToken.None); //Assert AllMarktContextIM.Products .Should() .NotContain(product => product.Id == deleteProductCommand.Id); }
public async Task AddProductCommentCommandHandle_AddsShopComment() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); AllMarktContextIM.SaveChanges(); var user = new AllMarkt.Entities.User { Email = "*****@*****.**", Password = "******", DisplayName = "UserTest" }; var product = new AllMarkt.Entities.Product { Name = "testProduct", Description = "testDescription", Price = 20, ImageURI = "", State = true, ProductCategory = productCategory }; AllMarktContextIM.Users.Add(user); AllMarktContextIM.Products.Add(product); await AllMarktContextIM.SaveChangesAsync(); var addProductCommentCommand = new AddProductCommentCommand { Rating = 5, Text = "cel mai bun produs", ProductId = product.Id, AddedByUserId = user.Id }; //Act await _addProductCommentCommandHandler.Handle(addProductCommentCommand, CancellationToken.None); //Assert AllMarktContextIM.ProductComments .Should() .Contain(productComment => productComment.Rating == addProductCommentCommand.Rating && productComment.Text == addProductCommentCommand.Text && productComment.AddedBy.Id == addProductCommentCommand.AddedByUserId && productComment.Product.Id == addProductCommentCommand.ProductId); }
public async Task EditProduct_CommandHandle_UpdatesExistingProduct() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); await AllMarktContextIM.SaveChangesAsync(); var product = new AllMarkt.Entities.Product { Name = "Test Name1", Description = "Test Description1", Price = 10, ImageURI = "", State = true, ProductCategory = productCategory }; AllMarktContextIM.Products.Add(product); await AllMarktContextIM.SaveChangesAsync(); var existingProduct = AllMarktContextIM.Products.First(); var editProductCommand = new EditProductCommand { Id = existingProduct.Id, Name = "TestName_EDIT", Description = "TestDescription_EDIT", Price = 11, ImageURI = "abc", State = false, }; //Act await _editProductCommandHandler.Handle(editProductCommand, CancellationToken.None); //Assert AllMarktContextIM.Products.Should().Contain(x => x.Id == editProductCommand.Id); product.Name.Should().Be(editProductCommand.Name); product.Description.Should().Be(editProductCommand.Description); product.Price.Should().Be(editProductCommand.Price); product.ImageURI.Should().Be(editProductCommand.ImageURI); product.State.Should().Be(editProductCommand.State); }
public async Task GetAllProductsByProductCategoryQueryHandler_ReturnsEmpty() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); AllMarktContextIM.SaveChanges(); //Act var result = await _getAllProductsQueryHandler.Handle(new GetAllProductsByProductCategoryQuery(productCategory.Id), CancellationToken.None); //Assert result.Should().BeEmpty(); }
public async Task GetAllProductsByProductCategoryQueryHandler_ReturnsExistingProducts() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); AllMarktContextIM.SaveChanges(); AllMarktContextIM.Products.Add(new AllMarkt.Entities.Product { Name = "Test Name1", Description = "Test Description1", Price = 10, ImageURI = "", State = true, ProductCategory = productCategory }); AllMarktContextIM.Products.Add(new AllMarkt.Entities.Product { Name = "Test Name2", Description = "Test Description2", Price = 10, ImageURI = "", State = true, ProductCategory = productCategory }); AllMarktContextIM.SaveChanges(); //Act var result = await _getAllProductsQueryHandler.Handle(new GetAllProductsByProductCategoryQuery(productCategory.Id), CancellationToken.None); //Assert result.Count().Should().Be(2); }
public AddProductCommandTests() { _addProductCommandHandler = new AddProductCommandHandler(AllMarktContextIM); _productCategory = new AllMarkt.Entities.ProductCategory(); }