Example #1
0
        public async Task HandleOrderAsync__Order_handle_succeeded__Should_not_throw_any_Exception()
        {
            // Attempt to update existent group by adding 2 tickets and exactly 2 places are available.
            var sightseeingDate = DateTime.Now.AddDays(1).Date.AddHours(12);

            SetUpForSucceededOrderHandle(sightseeingDate, new Ticket[] { _ticket });

            var order = new OrderRequestDto
            {
                Customer = new CustomerDto {
                    EmailAddress = "*****@*****.**"
                },
                Tickets = new ShallowTicket[]
                {
                    new ShallowTicket {
                        DiscountId = "1", SightseeingDate = sightseeingDate, TicketTariffId = "1"
                    },
                    new ShallowTicket {
                        DiscountId = "2", SightseeingDate = sightseeingDate, TicketTariffId = "2"
                    }
                }
            };
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            // Set _shallowTickets and _customer private variables.
            await handler.CreateOrderAsync(order);

            Func <Task> action = async() => await handler.HandleOrderAsync();

            await action.Should().NotThrowAsync <Exception>();

            handler.Tickets.Should().NotBeEmpty();
        }
Example #2
0
        public async Task HandleOrderAsync__Attempt_to_update_existent_group_by_adding_to_many_tickets__Should_throw_InvalidOperationException()
        {
            // Attempt to update existent group by adding 2 tickets , but only 1 place is available in existent group.
            var sightseeingDate = DateTime.Now.AddDays(1).Date.AddHours(12);

            SetUpForFailedUpdate(sightseeingDate);

            var order = new OrderRequestDto
            {
                Customer = new CustomerDto {
                    EmailAddress = "*****@*****.**"
                },
                Tickets = new ShallowTicket[]
                {
                    new ShallowTicket {
                        DiscountId = "1", SightseeingDate = sightseeingDate, TicketTariffId = "1"
                    },
                    new ShallowTicket {
                        DiscountId = "2", SightseeingDate = sightseeingDate, TicketTariffId = "2"
                    }
                }
            };
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            // Set _shallowTickets and _customer private variables.
            await handler.CreateOrderAsync(order);

            Func <Task> action = async() => await handler.HandleOrderAsync();

            await action.Should().ThrowExactlyAsync <InvalidOperationException>();
        }
Example #3
0
        public async Task GetCustomerAsync__Argument_order_id_is_null__Should_throw_ArgumentNullException()
        {
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            Func <Task> action = async() => await handler.GetCustomerAsync(null);

            await action.Should().ThrowExactlyAsync <ArgumentNullException>();
        }
Example #4
0
        public async Task GetCustomerAsync__Customer_from_order_found__Should_return_this_customer()
        {
            _customerDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ReturnsAsync(_customer);
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            var result = await handler.GetCustomerAsync("eW91O2dvdHRoaXM=");

            result.Should().BeEquivalentTo(_customer);
        }
Example #5
0
        public async Task GetCustomerAsync__Customer_from_order_not_found__Should_return_null()
        {
            _customerDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new InvalidOperationException());
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            var result = await handler.GetCustomerAsync("eW91O2dvdHRoaXM=");

            result.Should().BeNull();
        }
Example #6
0
        public async Task GetCustomerAsync__Argument_order_id_has_invalid_format__Should_throw_FormatException()
        {
            string orderId = "1234/23";
            var    handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            Func <Task> action = async() => await handler.GetCustomerAsync(orderId);

            await action.Should().ThrowExactlyAsync <FormatException>();
        }
Example #7
0
        public async Task GetOrderedTicketsAsync__Tickets_from_order_found__Should_return_not_empty_IEnumerable()
        {
            _ticketDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <Ticket, bool> > >())).ReturnsAsync(new Ticket[] { _ticket }.AsEnumerable());
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            var result = await handler.GetOrderedTicketsAsync("eW91O2dvdHRoaXM=");

            result.Should().NotBeEmpty();
        }
Example #8
0
        public async Task CreateOrderAsync__Customer_in_argument_order_is_null__Should_throw_ArgumentException()
        {
            var order = new OrderRequestDto {
                Id = "1", Customer = null, Tickets = new ShallowTicket[] { _shallowTicket }
            };
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            Func <Task> action = async() => await handler.CreateOrderAsync(order);

            await action.Should().ThrowExactlyAsync <ArgumentException>();
        }
Example #9
0
        public async Task CreateOrderAsync__Cannot_get_saved_customer__Should_throw_InvalidOperationException()
        {
            var order = new OrderRequestDto {
                Id = "1", Customer = new CustomerDto(), Tickets = new ShallowTicket[] { _shallowTicket }
            };

            _customerDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <Customer, bool> > >())).ThrowsAsync(new InvalidOperationException());
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            Func <Task> action = async() => await handler.CreateOrderAsync(order);

            await action.Should().ThrowExactlyAsync <InvalidOperationException>();
        }
Example #10
0
        public async Task CreateOrderAsync__Order_create_succeeded__Property_customer_should_return_correct_data()
        {
            // Property should return Customer who ordered tickets.
            // This method set Customer property.
            var tickets = new ShallowTicket[] { _shallowTicket };
            var order   = new OrderRequestDto {
                Id = "1", Customer = new CustomerDto(), Tickets = tickets
            };

            _customerDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <Customer, bool> > >())).ReturnsAsync(new Customer[] { _customer });
            _customerDbServiceMock.Setup(x => x.AddAsync(It.IsAny <Customer>())).ReturnsAsync(_customer);
            var handler = new TicketOrderHandler(_dbServiceFactoryMock.Object, _validatorMock.Object, _logger);

            await handler.CreateOrderAsync(order);

            handler.Customer.Should().BeEquivalentTo(_customer);
        }