Exemple #1
0
        public void ShouldRequireMinimumFields()
        {
            var command = new ConfirmOrderCommand();

            FluentActions.Invoking(() =>
                                   SendAsync(command))
            .Should()
            .Throw <BaseValidationException>();
        }
Exemple #2
0
        public void ShouldThrowOrderNotFoundException()
        {
            // Cancel Order Command
            var cancelOrderCommand = new ConfirmOrderCommand {
                OrderId = Guid.NewGuid().ToString()
            };

            FluentActions.Invoking(() => SendAsync(cancelOrderCommand)).Should().Throw <OrderNotFoundException>();
        }
        public override async Task HandleAsync(ConfirmOrderIntegrationEvent @event)
        {
            var command = new ConfirmOrderCommand
            {
                OrderId = @event.OrderId
            };

            await _bus.SendAsync(command);
        }
Exemple #4
0
        public async Task <IActionResult> ConfirmOrderAsync(Guid orderId)
        {
            var command = new ConfirmOrderCommand {
                OrderId = orderId
            };

            await SendCommandAsync(command);

            return(Ok());
        }
Exemple #5
0
        public async Task <ActionResult> CreateOrderAsync([FromBody] ConfirmOrderCommand command)
        {
            var commandResult = await _mediator.Send(command);

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Exemple #6
0
        public async Task <ActionResult <RegBookResponseObj> > ConfirmOrder([FromBody] ConfirmOrder requestObj)
        {
            ConfirmOrderCommand command = _mapper.Map <ConfirmOrderCommand>(requestObj);
            var response = await _mediator.Send(command);

            if (response.OrderId < 1 || !response.Status.IsSuccessful)
            {
                return(BadRequest(response));
            }
            var locatioUri = _uriService.GetBookUri(response.OrderId.ToString());

            return(Created(locatioUri, response));
        }
Exemple #7
0
        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>();
        }
Exemple #8
0
        public async Task <IActionResult> ConfirmOrder([FromBody] ConfirmOrderCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(new { result }));
        }
        List<CommandRouteItem> GetConfirmOrderCommandRoutes(ConfirmOrderCommand confirmOrderCommand)
        {
            List<CommandRouteItem> commandRouteItems = new List<CommandRouteItem>();
            string serializedCommand = JsonConvert.SerializeObject(confirmOrderCommand);
            List<Guid> ids = GetDestinationIdsFromOrderId(confirmOrderCommand.DocumentId);

            Guid[] _destinationIds = RemoveSourceCCAppId(ids.ToArray(), confirmOrderCommand);

            foreach (Guid id in _destinationIds)
                commandRouteItems.Add(CreateRouteItem(confirmOrderCommand, "ConfirmOrder", id, serializedCommand));

            return commandRouteItems;

        }
Exemple #10
0
        public async Task <ActionResult <CommandResult <CommandEmptyResult> > > ConfirmOrder([FromForm] ConfirmOrderCommand command)
        {
            var result = await _mediator.Send(command);

            if (result.IsSuccess)
            {
                return(Ok(result.Payload));
            }

            return(BadRequest(result.FailureReason));
        }
Exemple #11
0
        public async Task ShouldShippOrder()
        {
            // 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);

            // Act

            // Shipp Order Command
            var shippOrderCommand = new ShippOrderCommand {
                OrderId = orderId
            };

            await SendAsync(shippOrderCommand);

            // 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.Shipped);
        }
        public async Task <IActionResult> Confirm([FromRoute] ConfirmOrderCommand request)
        {
            await _mediator.Send(request);

            return(Ok());
        }