public Task Put([FromBody] string name) { var command = new CreateProductCategoryCommand(name); _commandBus.ExecuteAsync(command).Wait(); return(Task.CompletedTask); }
public async Task <IActionResult> CreateProductCategory( [FromRoute] int supplierId, CreateProductCategoryCommandDto dto) { var command = new CreateProductCategoryCommand(supplierId, new ProductCategoryName(dto.Name)); await _mediator.Send(command); return(StatusCode(StatusCodes.Status201Created)); }
public async Task ShouldListProducts() { // 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 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 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" }; await SendAsync(createFirstProductCommand); await SendAsync(createSecondProductCommand); var productsQuery = new ListProductsQuery(); var products = await SendAsync(productsQuery); products.Data.Should().NotBeNull(); products.Data.Should().HaveCount(2); }
public async Task <IActionResult> Post([FromBody] CreateProductCategoryCommand request) { try { await _createProductCategoryCommand.Handle(request, CancellationToken.None); return(Ok(new ApiResponse(200))); } catch (Exception ex) { _logger.LogCritical(ex, $"Error on Insert Product Cattegory"); return(BadRequest(new ApiBadRequestResponse(500, "Something Wrong"))); } }
public async Task ShouldThrowUnitNotFoundExceptionAsync() { // Arrange await RunAsDefaultUserAsync(); // 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); // AddItem To Shopping Van var command = new AddItemToVanCommand { ProductId = productId, UnitId = Guid.NewGuid().ToString() }; // Act FluentActions.Invoking(() => SendAsync(command)).Should().Throw <UnitNotFoundException>(); }
public async Task ShouldGetProductById() { // 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); var productByIdQuery = new ProductByIdQuery { ProductId = productId }; var product = await SendAsync(productByIdQuery); product.Should().NotBeNull(); product.Id.Should().Be(productId); }
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 ShouldAddItemToVan() { // Arrange await RunAsDefaultUserAsync(); // 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); // AddItem To Shopping Van var command = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; // Act await SendAsync(command); var shoppingVanItemCount = await SendAsync(command); // Assert shoppingVanItemCount.Should().Be(2); }
public async Task ShouldDeliverOrder() { // Arrange var accountId = await RunAsDefaultUserAsync(); var createCustomerCommand = new CreateCustomerCommand { AccountId = accountId, ShopName = "Test Shop Name", ShopAddress = "Test Shop address", LocationOnMap = "Test LocationOnMap" }; await SendAsync(createCustomerCommand); // 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); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); var orderId = await SendAsync(placeOrderCommand); // Confirm Order Command var confirmOrderCommand = new ConfirmOrderCommand { OrderId = orderId }; await SendAsync(confirmOrderCommand); // Shipp Order Command var shippOrderCommand = new ShippOrderCommand { OrderId = orderId }; await SendAsync(shippOrderCommand); // Act // Deliver Order Command var deliverOrderCommand = new DeliverOrderCommand { OrderId = orderId }; await SendAsync(deliverOrderCommand); // Get Order By Id Query var orderByIdQuery = new OrderByIdQuery { OrderId = orderId }; var order = await SendAsync(orderByIdQuery); // Assert order.Should().NotBeNull(); order.OrderStatus.Should().Be(OrderStatus.Delivered); }
public async Task <ActionResult <int> > Create(CreateProductCategoryCommand command) { return(await Mediator.Send(command)); }
public async Task ShouldUpdateOrder() { // Arrange var accountId = await RunAsDefaultUserAsync(); var createCustomerCommand = new CreateCustomerCommand { AccountId = accountId, ShopName = "Test Shop Name", ShopAddress = "Test Shop address", LocationOnMap = "Test LocationOnMap" }; await SendAsync(createCustomerCommand); // 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 first unit to product var addFirstUnitCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 92, ContentCount = 2, Price = 33, Count = 6, IsAvailable = true, Name = "Test First Unit", Weight = 44 }; var firstUnitId = await SendAsync(addFirstUnitCommand); // Add first unit to product var addSecondUnitCommand = new AddUnitCommand { ProductId = productId, SellingPrice = 342, ContentCount = 24, Price = 323, Count = 64, IsAvailable = true, Name = "Test Second Unit", Weight = 94 }; var secondUnitId = await SendAsync(addSecondUnitCommand); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = firstUnitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); var orderId = await SendAsync(placeOrderCommand); // Get Order By Id Query var orderByIdQuery = new OrderByIdQuery { OrderId = orderId }; var order = await SendAsync(orderByIdQuery); // Act var updateOrderCommand = new UpdateOrderCommand { OrderId = orderId, OrderItemId = order.OrderItems.FirstOrDefault(x => x.UnitId == firstUnitId).Id, UnitId = secondUnitId, UnitCount = 10, UnitName = addSecondUnitCommand.Name }; await SendAsync(updateOrderCommand); // Get Order By Id Query var orderAfterUpdate = await SendAsync(orderByIdQuery); // Assert order.Should().NotBeNull(); order.OrderItems.Count.Should().Be(1); order.OrderItems.FirstOrDefault(x => x.UnitId == firstUnitId).UnitName.Should().Be(addFirstUnitCommand.Name); orderAfterUpdate.OrderItems.FirstOrDefault(x => x.UnitId == secondUnitId).UnitName.Should().Be(addSecondUnitCommand.Name); }
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 <ActionResult <ProductCategoryDto> > CreateProductCategory(CreateProductCategoryCommand request) { var result = await Mediator.Send(request); return(GetResponse(result)); }
public async Task <IActionResult> Post([FromBody] CreateProductCategoryCommand command) { var result = await Mediator.Send(command); return(Ok(new { result })); }
public async Task ShouldGetCurrentCustomerVan() { // Arrange var currentCustomerId = await RunAsDefaultUserAsync(); // 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); // AddItem To Shopping Van var command = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(command); // Act var getCurrentCustomerVanQuery = new CurrentCustomerVanQuery(); var currentCustomerVan = await SendAsync(getCurrentCustomerVanQuery); // Assert currentCustomerVan.TotalItemsCount.Should().Be(1); currentCustomerVan.TotalPrice.Should().Be(addUnitToCommand.SellingPrice + (addUnitToCommand.SellingPrice * 0.14f)); currentCustomerVan.CustomerId.Should().Be(currentCustomerId); }
public async Task ShouldThrowCancelConfirmedOrderException() { // Arrange var accountId = await RunAsDefaultUserAsync(); var createCustomerCommand = new CreateCustomerCommand { AccountId = accountId, ShopName = "Test Shop Name", ShopAddress = "Test Shop address", LocationOnMap = "Test LocationOnMap" }; await SendAsync(createCustomerCommand); // 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); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); var orderId = await SendAsync(placeOrderCommand); // Act var confirmOrderCommand = new ConfirmOrderCommand { OrderId = orderId }; await SendAsync(confirmOrderCommand); var cancelOrderCommand = new CancelOrderCommand { OrderId = orderId }; // Assert // Cancel Order Command FluentActions.Invoking(() => SendAsync(cancelOrderCommand)).Should().Throw <CancelConfirmedOrderException>(); }
public async Task <IActionResult> Post(CreateProductCategoryCommand command) { return(Ok(await _mediator.Send(command))); }
public async Task ShouldListAllOrders() { // Arrange var accountId = await RunAsDefaultUserAsync(); var createCustomerCommand = new CreateCustomerCommand { AccountId = accountId, ShopName = "Test Shop Name", ShopAddress = "Test Shop address", LocationOnMap = "Test LocationOnMap" }; await SendAsync(createCustomerCommand); // 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); // AddItem To Shopping Van var addItemToVanCommand = new AddItemToVanCommand { ProductId = productId, UnitId = unitId }; await SendAsync(addItemToVanCommand); await SendAsync(addItemToVanCommand); // Place Order Command var placeOrderCommand = new PlaceOrderCommand(); await SendAsync(placeOrderCommand); // Act // Get Order By Id Query var listOrdersQuery = new ListOrdersQuery { OrderStatuses = new List <OrderStatus> { OrderStatus.Placed } }; var listOrders = await SendAsync(listOrdersQuery); // Assert listOrders.Data.Should().NotBeNull(); listOrders.Data.Count.Should().Be(1); }
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) ); }