Пример #1
0
        public void And_Has_No_Permissions_Then_Throws_No_Permissions_Exception(SearchReservationsQuery query,
                                                                                ValidationResult validationResult,
                                                                                string propertyName,
                                                                                [Frozen] Mock <IValidator <SearchReservationsQuery> > mockValidator,
                                                                                SearchReservationsQueryHandler handler)
        {
            validationResult.ValidationDictionary.Clear();
            validationResult.FailedAuthorisationValidation = true;
            mockValidator
            .Setup(validator => validator.ValidateAsync(query))
            .ReturnsAsync(validationResult);

            Assert.ThrowsAsync <ProviderNotAuthorisedException>(() => handler.Handle(query, CancellationToken.None));
        }
        public void And_Invalid_Then_It_Throws_ValidationException(
            CacheReservationStartDateCommand command,
            ValidationResult validationResult,
            string propertyName)
        {
            validationResult.AddError(propertyName);

            _mockValidator
            .Setup(validator => validator.ValidateAsync(command))
            .ReturnsAsync(validationResult);

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

            act.Should().ThrowExactly <ValidationException>()
            .Which.ValidationResult.MemberNames.First(c => c.StartsWith(propertyName)).Should().NotBeNullOrEmpty();
        }
        public async Task Then_Gets_Reservations_From_Service(
            long accountId,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <IReservationService> mockService,
            GetReservationsQueryHandler handler)
        {
            var query = new GetReservationsQuery {
                AccountId = accountId
            };

            validationResult.ValidationDictionary.Clear();

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

            mockService.Verify(client => client.GetReservations(accountId),
                               Times.Once);
        }
        public void And_Command_Not_Valid_Then_Throws_ValidationException(
            DeleteReservationCommand command,
            string propertyName,
            ValidationResult validationResult,
            [Frozen] Mock <IValidator <DeleteReservationCommand> > mockValidator,
            DeleteReservationCommandHandler handler)
        {
            validationResult.AddError(propertyName);
            mockValidator
            .Setup(validator => validator.ValidateAsync(It.IsAny <DeleteReservationCommand>()))
            .ReturnsAsync(validationResult);

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

            act.Should().ThrowExactly <ValidationException>()
            .Which.ValidationResult.MemberNames.First(c => c.StartsWith(propertyName)).Should().NotBeNullOrEmpty();
        }
Пример #5
0
        public void And_Invalid_Then_Throws_Validation_Exception(
            SearchReservationsQuery query,
            ValidationResult validationResult,
            string propertyName,
            [Frozen] Mock <IValidator <SearchReservationsQuery> > mockValidator,
            SearchReservationsQueryHandler handler)
        {
            validationResult.AddError(propertyName);
            validationResult.FailedAuthorisationValidation = false;
            mockValidator
            .Setup(validator => validator.ValidateAsync(query))
            .ReturnsAsync(validationResult);

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

            act.Should().ThrowExactly <ValidationException>()
            .Which.ValidationResult.MemberNames.First(c => c.StartsWith(propertyName)).Should().NotBeNullOrEmpty();
        }
Пример #6
0
        public void And_The_Command_Is_Not_Valid_Then_Does_Not_Cache_Reservation(
            CacheReservationCourseCommand command,
            ValidationResult validationResult,
            string propertyName)
        {
            //Assign
            validationResult.AddError(propertyName);

            _mockValidator
            .Setup(validator => validator.ValidateAsync(command))
            .ReturnsAsync(validationResult);

            //Act
            Assert.ThrowsAsync <ValidationException>(() => _commandHandler.Handle(command, CancellationToken.None));

            //Assert
            _mockCacheStorageService.Verify(s => s.SaveToCache(It.IsAny <string>(), It.IsAny <CachedReservation>(), It.IsAny <int>()), Times.Never);
        }
Пример #7
0
        public async Task Then_Gets_Search_Result_From_Service(
            SearchReservationsQuery query,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <IReservationService> mockReservationService,
            SearchReservationsQueryHandler handler)
        {
            validationResult.ValidationDictionary.Clear();
            validationResult.FailedAuthorisationValidation = false;

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

            mockReservationService.Verify(service => service.SearchReservations(
                                              It.Is <SearchReservationsRequest>(request =>
                                                                                request.Filter.SearchTerm == query.Filter.SearchTerm &&
                                                                                request.ProviderId == query.ProviderId &&
                                                                                request.Filter.SelectedEmployer == query.Filter.SelectedEmployer &&
                                                                                request.Filter.SelectedCourse == query.Filter.SelectedCourse &&
                                                                                request.Filter.SelectedStartDate == query.Filter.SelectedStartDate)));
        }
Пример #8
0
        public void And_The_Command_Is_Not_Valid_Then_Does_Not_Get_Cached_Reservation(
            CacheReservationCourseCommand command,
            ValidationResult validationResult,
            string propertyName)
        {
            //Assign
            validationResult.AddError(propertyName);

            _mockValidator
            .Setup(validator => validator.ValidateAsync(command))
            .ReturnsAsync(validationResult);

            //Act
            Assert.ThrowsAsync <ValidationException>(() => _commandHandler.Handle(command, CancellationToken.None));

            //Assert
            _mockCacheRepository.Verify(service => service.GetEmployerReservation(It.IsAny <Guid>()), Times.Never);
            _mockCacheRepository.Verify(service => service.GetProviderReservation(It.IsAny <Guid>(), It.IsAny <uint>()), Times.Never);
        }
        public async Task Then_Returns_Mapped_Reservations(
            long accountId,
            List <Reservation> serviceReservations,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <IReservationService> mockService,
            GetReservationsQueryHandler handler)
        {
            var query = new GetReservationsQuery {
                AccountId = accountId
            };

            validationResult.ValidationDictionary.Clear();
            mockService
            .Setup(client => client.GetReservations(accountId))
            .ReturnsAsync(serviceReservations);

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

            result.Reservations.Should().BeEquivalentTo(serviceReservations);
        }
        public void And_Invalid_Then_Throws_ValidationException(
            long accountId,
            string propertyName,
            ValidationResult validationResult,
            [Frozen] Mock <IValidator <GetReservationsQuery> > mockValidator,
            GetReservationsQueryHandler handler)
        {
            var query = new GetReservationsQuery {
                AccountId = accountId
            };

            validationResult.AddError(propertyName);
            mockValidator
            .Setup(validator => validator.ValidateAsync(It.IsAny <GetReservationsQuery>()))
            .ReturnsAsync(validationResult);

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

            act.Should().ThrowExactly <ValidationException>()
            .Which.ValidationResult.MemberNames.First(c => c.StartsWith(propertyName)).Should().NotBeNullOrEmpty();
        }
Пример #11
0
        public async Task Then_Maps_Reservations(
            SearchReservationsQuery query,
            [Frozen] ValidationResult validationResult,
            SearchReservationsResponse serviceResponse,
            [Frozen] Mock <IReservationService> mockReservationService,
            SearchReservationsQueryHandler handler)
        {
            validationResult.ValidationDictionary.Clear();
            validationResult.FailedAuthorisationValidation = false;
            mockReservationService
            .Setup(service => service.SearchReservations(
                       It.Is <SearchReservationsRequest>(request =>
                                                         request.Filter.SearchTerm == query.Filter.SearchTerm &&
                                                         request.ProviderId == query.ProviderId)))
            .ReturnsAsync(serviceResponse);

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

            result.Reservations.Should().BeEquivalentTo(serviceResponse.Reservations);
            result.NumberOfRecordsFound.Should().Be(serviceResponse.NumberOfRecordsFound);
            result.EmployerFilters.Should().BeEquivalentTo(serviceResponse.EmployerFilters);
            result.CourseFilters.Should().BeEquivalentTo(serviceResponse.CourseFilters);
            result.StartDateFilters.Should().BeEquivalentTo(serviceResponse.StartDateFilters);
        }