public async Task ShouldDeleteUnitFromProduct() { // Arrange // Create product brand var brandCommand = new CreateBrandCommand { Name = "Test Brand" }; var brandId = await SendAsync(brandCommand); // Create product category var productCategoryCommand = new CreateProductCategoryCommand { Name = "Test Product Category" }; var productCategoryId = await SendAsync(productCategoryCommand); // Create product var createProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; var productId = await SendAsync(createProductCommand); // Add unit to product var addUnitToCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test Unit", Weight = 44 }; var unitId = await SendAsync(addUnitToCommand); var deleteProductUnitCommand = new DeleteUnitCommand { ProductId = productId, UnitId = unitId }; await SendAsync(deleteProductUnitCommand); var listProductsUnitsQuery = new ListUnitsByProductsIdsQuery { ProductsIds = new List <string> { productId } }; var currentProductUnits = await SendAsync(listProductsUnitsQuery); currentProductUnits.Should().NotContain(x => x.Id == unitId && x.ProductId == addUnitToCommand.ProductId); }
public async Task ShouldListUnitsByProductsIds() { // Arrange // Create product brand var brandCommand = new CreateBrandCommand { Name = "Test Brand" }; var brandId = await SendAsync(brandCommand); // Create product category var productCategoryCommand = new CreateProductCategoryCommand { Name = "Test Product Category" }; var productCategoryId = await SendAsync(productCategoryCommand); // Create First product var createFirstProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; // Create Second product var createSecondProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; var firstProductId = await SendAsync(createFirstProductCommand); var secondProductId = await SendAsync(createSecondProductCommand); // Add unit to first product var addFirstUnitCommand = new AddUnitCommand { ProductId = firstProductId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test Unit", Weight = 44 }; // Add unit to second product var addSecondUnitCommand = new AddUnitCommand { ProductId = secondProductId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test Unit", Weight = 44 }; var firstUnitId = await SendAsync(addFirstUnitCommand); var secondUnitId = await SendAsync(addSecondUnitCommand); var listUnitsByProductsIdsQuery = new ListUnitsByProductsIdsQuery { ProductsIds = new List <string> { firstProductId, secondProductId } }; var productsUnits = await SendAsync(listUnitsByProductsIdsQuery); productsUnits.Should().NotBeNull(); productsUnits.Should().HaveCount(2); productsUnits.Should().Contain(x => x.Id == firstUnitId); productsUnits.Should().Contain(x => x.Id == secondUnitId); }
public async Task <IActionResult> GetUnitsByProductsIds([FromQuery] ListUnitsByProductsIdsQuery query) { var result = await Mediator.Send(query); return(Ok(result)); }
public async Task ShouldUpdateProductUnit() { // Arrange // Create product brand var brandCommand = new CreateBrandCommand { Name = "Test Brand" }; var brandId = await SendAsync(brandCommand); // Create product category var productCategoryCommand = new CreateProductCategoryCommand { Name = "Test Product Category" }; var productCategoryId = await SendAsync(productCategoryCommand); // Create product var createProductCommand = new CreateProductCommand { AvailableToSell = true, // created brand id BrandId = brandId, // created product category id ProductCategoryId = productCategoryId, Name = "Test Product", PhotoUrl = "Test Product", Barcode = "Test Product" }; var productId = await SendAsync(createProductCommand); // Add unit to product var addUnitToCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test Unit", Weight = 44 }; var unitId = await SendAsync(addUnitToCommand); // update product unit var updateProductUnitCommand = new UpdateUnitCommand { ProductId = productId, SellingPrice = 992, ContentCount = 25, Price = 333, Count = 65, IsAvailable = false, Name = "Test Unit Update", Weight = 4, Id = unitId }; await SendAsync(updateProductUnitCommand); var listProductsUnitsQuery = new ListUnitsByProductsIdsQuery { ProductsIds = new List <string> { productId } }; var currentProductUnits = await SendAsync(listProductsUnitsQuery); currentProductUnits.Should().OnlyContain(x => x.Id == unitId && x.ProductId == updateProductUnitCommand.ProductId && x.SellingPrice.Equals(updateProductUnitCommand.SellingPrice) && x.ContentCount == updateProductUnitCommand.ContentCount && x.Price.Equals(updateProductUnitCommand.Price) && x.Count == updateProductUnitCommand.Count && x.IsAvailable == updateProductUnitCommand.IsAvailable && x.Name == updateProductUnitCommand.Name && x.Weight.Equals(updateProductUnitCommand.Weight) ); }