Beispiel #1
0
        public async Task Then_Returns_Mapped_Reservations(
            long accountId,
            List <Reservation> serviceReservations,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <IReservationService> mockService,
            GetAvailableReservationsQueryHandler handler)
        {
            var query = new GetAvailableReservationsQuery {
                AccountId = accountId
            };

            validationResult.ValidationDictionary.Clear();
            serviceReservations.ForEach(reservation =>
            {
                reservation.Status    = ReservationStatus.Pending;
                reservation.IsExpired = false;
            });
            mockService
            .Setup(client => client.GetReservations(accountId))
            .ReturnsAsync(serviceReservations);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Reservations.Should().BeEquivalentTo(serviceReservations);
        }
Beispiel #2
0
        public async Task Then_Gets_Reservations_From_Service(
            long accountId,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <IReservationService> mockService,
            GetAvailableReservationsQueryHandler handler)
        {
            var query = new GetAvailableReservationsQuery {
                AccountId = accountId
            };

            validationResult.ValidationDictionary.Clear();

            await handler.Handle(query, CancellationToken.None);

            mockService.Verify(client => client.GetReservations(accountId),
                               Times.Once);
        }
Beispiel #3
0
        public void And_Invalid_Then_Throws_ValidationException(
            long accountId,
            string propertyName,
            [Frozen] ValidationResult validationResult,
            GetAvailableReservationsQueryHandler handler)
        {
            var query = new GetAvailableReservationsQuery {
                AccountId = accountId
            };

            validationResult.AddError(propertyName);

            Func <Task> act = async() => { await handler.Handle(query, CancellationToken.None); };

            act.Should().ThrowExactly <ValidationException>()
            .Which.ValidationResult.MemberNames.First(c => c.StartsWith(propertyName)).Should().NotBeNullOrEmpty();
        }
Beispiel #4
0
        public async Task And_Status_Not_Pending_Then_Does_Not_Return_Reservation(
            long accountId,
            List <Reservation> serviceReservations,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <IReservationService> mockService,
            GetAvailableReservationsQueryHandler handler)
        {
            var query = new GetAvailableReservationsQuery {
                AccountId = accountId
            };

            validationResult.ValidationDictionary.Clear();
            serviceReservations[0].Status = ReservationStatus.Completed;
            mockService
            .Setup(client => client.GetReservations(accountId))
            .ReturnsAsync(serviceReservations);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Reservations.Should().NotContain(serviceReservations[0]);
        }