예제 #1
0
        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));
        }
예제 #2
0
 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));
     }
 }
예제 #3
0
        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>();
        }
예제 #4
0
        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);
        }
예제 #5
0
        public async Task <IActionResult> DeleteUnit([FromQuery] DeleteUnitCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(result));
        }