Exemplo n.º 1
0
        public Task ConfirmShouldReturnProperHypermediaLinks(Guid orderId, MenuItem[] menuItems, Fixture fixture) =>
        _apiHelper.InTheContextOfACashier(
            cashier => async httpClient =>
        {
            // Arrange
            await _orderHelper.OrderToGo(orderId, menuItems);

            var command = new ConfirmToGoOrder
            {
                OrderId   = orderId,
                PricePaid = menuItems.Sum(i => i.Price)
            };

            // Act
            var response = await httpClient
                           .PutAsJsonAsync(OrderRoute("confirm"), command);

            // Assert
            var expectedLinks = new List <string>
            {
                LinkNames.Self,
                LinkNames.Order.Get,
                LinkNames.Order.GetAll
            };

            await response.ShouldBeAResource <ConfirmToGoOrderResource>(expectedLinks);
        },
            fixture);
        public async Task CannotConfirmAnOrderTwice(Guid orderId, MenuItem[] items)
        {
            // Arrange
            await _helper.OrderToGo(orderId, items);

            var confirmOrderCommand = new ConfirmToGoOrder
            {
                OrderId   = orderId,
                PricePaid = items.Sum(i => i.Price)
            };

            await _fixture.SendAsync(confirmOrderCommand);

            var commandToTest = new ConfirmToGoOrder
            {
                OrderId   = confirmOrderCommand.OrderId, // Notice the id is the same
                PricePaid = items.Sum(i => i.Price)
            };

            // Act
            var result = await _fixture.SendAsync(commandToTest);

            // Assert
            result.ShouldHaveErrorOfType(ErrorType.Validation);
        }
        public async Task CannotConfirmUnexistingOrder(Guid orderId)
        {
            // Arrange
            // Purposefully not creating any orders
            var commandToTest = new ConfirmToGoOrder
            {
                OrderId   = orderId,
                PricePaid = 100
            };

            // Act
            var result = await _fixture.SendAsync(commandToTest);

            // Assert
            result.ShouldHaveErrorOfType(ErrorType.NotFound);
        }
        public async Task CannotPayLessThanOwed(Guid orderId, MenuItem[] items)
        {
            // Arrange
            await _helper.OrderToGo(orderId, items);

            var commandToTest = new ConfirmToGoOrder
            {
                OrderId   = orderId,
                PricePaid = items.Sum(i => i.Price) - 1 // Notice we're paying less than what the items are worth
            };

            // Act
            var result = await _fixture.SendAsync(commandToTest);

            // Assert
            result.ShouldHaveErrorOfType(ErrorType.Validation);
        }
        public async Task CanConfirmToGoOrder(Guid orderId, MenuItem[] items)
        {
            // Arrange
            await _helper.OrderToGo(orderId, items);

            var commandToTest = new ConfirmToGoOrder
            {
                OrderId   = orderId,
                PricePaid = items.Sum(i => i.Price)
            };

            // Act
            var result = await _fixture.SendAsync(commandToTest);

            // Assert
            await _helper.AssertOrderExists(
                orderId,
                order => order.Status == ToGoOrderStatus.Issued);
        }
Exemplo n.º 6
0
 public async Task <IActionResult> ConfirmToGoOrder([FromBody] ConfirmToGoOrder command) =>
 (await Mediator.Send(command)
  .MapAsync(_ => ToEmptyResourceAsync <ConfirmToGoOrderResource>(x => x.OrderId = command.OrderId)))
 .Match(Ok, Error);