Пример #1
0
        public async Task Orders_can_be_created()
        {
            // arrange
            var user    = UserBuilder.Create().WithRole(UserRole.Customer).WithEmail("*****@*****.**").WithRole(UserRole.Customer).Active().Build(ArrangeRepositoryContext);
            var company = CompanyBuilder.Create().WithName("test company").WithUsers(user).Build(ArrangeRepositoryContext);
            var product = ProductBuilder.Create().WithName("test Prod").Active().Build(ArrangeRepositoryContext);

            var amount = 2;

            var request = new CreateOrder.Command
            {
                DeliveryDate  = DateTime.Now.AddDays(1),
                UserId        = user.Id,
                OrderProducts = new List <OrderItemDto> {
                    new OrderItemDto()
                    {
                        ProductId = product.Id,
                        Amount    = amount
                    }
                }
            };
            var controller = new OrdersController(Mediator);

            controller.SetUserId(user.Id);

            // act
            var result = await controller.CreateAsync(request);

            // assert
            result.Should().NotBeNullOrWhiteSpace();

            var subject = AssertRepositoryContext.Orders
                          .Include(x => x.OrderProducts)
                          .ThenInclude(x => x.Product)
                          .FirstOrDefault();

            subject.Should().NotBeNull();
            subject.DeliveryDate.Should().Be(request.DeliveryDate);
            subject.UserId.Should().Be(request.UserId);
            subject.DestinationCompanyId.Should().Be(company.Id);

            subject.OrderProducts.Count.Should().Be(1);
            subject.OrderProducts.First().ProductId.Should().Be(product.Id);
            subject.OrderProducts.First().Amount.Should().Be(amount);
        }
Пример #2
0
        public async Task Can_not_create_order_in_unavailability_duration()
        {
            // arrange
            var user    = UserBuilder.Create().WithRole(UserRole.Customer).WithEmail("*****@*****.**").WithRole(UserRole.Customer).Active().Build(ArrangeRepositoryContext);
            var company = CompanyBuilder.Create().WithName("test company").WithUsers(user).Removed().Build(ArrangeRepositoryContext);

            var product = ProductBuilder.Create().WithName("test Prod").Active().Build(ArrangeRepositoryContext);

            var unavailability = UnavailabilityBuilder.Create().From(DateTime.Now).To(DateTime.Now.AddDays(3)).WithReason(UnavailabilityReason.Sick).Build(ArrangeRepositoryContext);

            var request = new CreateOrder.Command
            {
                DeliveryDate  = DateTime.Now.AddDays(1),
                UserId        = user.Id,
                OrderProducts = new List <OrderItemDto> {
                    new OrderItemDto()
                    {
                        ProductId = product.Id,
                        Amount    = 1
                    }
                }
            };

            var controller = new OrdersController(Mediator);

            controller.SetUserId(user.Id);

            // act
            Func <Task> act       = () => controller.CreateAsync(request);
            var         exception = await Assert.ThrowsAsync <BadRequestException>(act);

            //assert
            exception.Message.Should().Be("Can not create order in unavailability duration");

            // assert
            var subject = AssertRepositoryContext.Orders.ToList();

            subject.Count.Should().Be(0);
        }
Пример #3
0
        public async Task <IActionResult> Post([FromBody] CreateOrder.Command command, CancellationToken cancellationToken)
        {
            await _mediator.Send(command, cancellationToken);

            return(Ok());
        }
Пример #4
0
        public async Task <string> CreateAsync(CreateOrder.Command command)
        {
            var response = await _mediator.Send(command);

            return(response);
        }