public Task <DeleteUnitResponse> deleteUnit(DeleteUnitRequest request) { DeleteUnitCommand command = new DeleteUnitCommand(request.Id); Task <object> unit = (Task <object>)Bus.SendCommand(command); //RabbitMQBus.Publish(command); DeleteUnitResponse response = new DeleteUnitResponse(); response = Common <DeleteUnitResponse> .checkHasNotification(_notifications, response); return(Task.FromResult(response)); }
public Task <object> Handle(DeleteUnitCommand command, CancellationToken cancellationToken) { if (!command.IsValid(_unitRepository)) { NotifyValidationErrors(command); return(Task.FromResult(false as object)); } else { bool result = _unitRepository.Delete(command.Id); return(Task.FromResult(true as object)); } }
public void ShouldThrowProductNotFoundException() { // Arrange // Add unit to product var deleteUnitToCommand = new DeleteUnitCommand { // random product Id ProductId = Guid.NewGuid().ToString(), UnitId = Guid.NewGuid().ToString() }; // Act var results = FluentActions.Invoking(() => SendAsync(deleteUnitToCommand)); // Assert results.Should().Throw <ProductNotFoundException>(); }
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 <IActionResult> DeleteUnit([FromQuery] DeleteUnitCommand command) { var result = await Mediator.Send(command); return(Ok(result)); }