public async Task Then_If_The_Query_Is_Valid_The_Service_Is_Called_And_The_Data_Returned(
            GetCourseProviderQuery request,
            TrainingCourseProviderDetails courseProviderResponse,
            [Frozen] Mock <IValidator <GetCourseProviderQuery> > mockValidator,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <ICourseService> mockService,
            GetCourseProviderQueryHandler handler)
        {
            //Arrange
            validationResult.ValidationDictionary.Clear();
            mockValidator.Setup(x => x.ValidateAsync(request)).ReturnsAsync(validationResult);
            mockService.Setup(x => x.GetCourseProviderDetails(request.ProviderId, request.CourseId, request.Location, request.Lat, request.Lon, request.ShortlistUserId.Value)).ReturnsAsync(courseProviderResponse);

            //Act
            var actual = await handler.Handle(request, CancellationToken.None);

            //Assert
            mockService.Verify(x => x.GetCourseProviderDetails(request.ProviderId, request.CourseId, request.Location, request.Lat, request.Lon, request.ShortlistUserId.Value), Times.Once);
            Assert.IsNotNull(actual);
            actual.Provider.Should().BeEquivalentTo(courseProviderResponse.CourseProviderDetails);
            actual.Course.Should().BeEquivalentTo(courseProviderResponse.TrainingCourse);
            actual.AdditionalCourses.Should().BeEquivalentTo(courseProviderResponse.AdditionalCourses);
            actual.Location.Should().Be(courseProviderResponse.Location.Name);
            actual.LocationGeoPoint.Should().BeEquivalentTo(courseProviderResponse.Location.LocationPoint.GeoPoint);
            actual.ProvidersAtLocation.Should().Be(courseProviderResponse.ProvidersCount.ProvidersAtLocation);
            actual.ShortlistItemCount.Should().Be(courseProviderResponse.ShortlistItemCount);
        }
        public async Task Then_If_There_Is_No_Course_Provider_Returns_Null(
            GetCourseProviderQuery request,
            Provider courseProviderResponse,
            [Frozen] Mock <IValidator <GetCourseProviderQuery> > mockValidator,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <ICourseService> mockService,
            GetCourseProviderQueryHandler handler)
        {
            //Arrange
            validationResult.ValidationDictionary.Clear();
            mockValidator.Setup(x => x.ValidateAsync(request)).ReturnsAsync(validationResult);
            mockService.Setup(x => x.GetCourseProviderDetails(request.ProviderId, request.CourseId, request.Location, request.Lat, request.Lon, request.ShortlistUserId.Value)).ReturnsAsync((TrainingCourseProviderDetails)null);

            //Act
            var actual = await handler.Handle(request, CancellationToken.None);

            //Assert
            mockService.Verify(x => x.GetCourseProviderDetails(request.ProviderId, request.CourseId, request.Location, request.Lat, request.Lon, request.ShortlistUserId.Value), Times.Once);
            Assert.IsNull(actual.Provider);
            Assert.IsNull(actual.Course);
            Assert.IsNull(actual.AdditionalCourses);
            Assert.IsNull(actual.Location);
            Assert.IsNull(actual.LocationGeoPoint);
            Assert.AreEqual(0, actual.ShortlistItemCount);
        }
Пример #3
0
        public async Task Then_Gets_Provider_From_The_Service_By_Ukprn_And_StandardId_And_Passes_Empty_Guid_If_No_Shortlist_UserId(
            string sectorSubjectArea,
            GetCourseProviderQuery query,
            ProviderLocation providerStandard,
            [Frozen] Mock <IProviderService> providerService,
            GetCourseProviderQueryHandler handler)
        {
            //Arrange
            query.ShortlistUserId             = null;
            providerStandard.AchievementRates = null;
            providerService.Setup(x => x.GetProviderByUkprnAndStandard(query.Ukprn, query.StandardId, query.Lat, query.Lon, query.SectorSubjectArea, Guid.Empty)).ReturnsAsync(providerStandard);

            //Act
            var actual = await handler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            actual.ProviderStandardLocation.Should().BeEquivalentTo(providerStandard);
        }
Пример #4
0
        public async Task Then_Gets_Provider_From_The_Service_By_Ukprn_And_StandardId(
            string sectorSubjectArea,
            GetCourseProviderQuery query,
            ProviderLocation providerStandard,
            [Frozen] Mock <IProviderService> providerService,
            GetCourseProviderQueryHandler handler)
        {
            //Arrange
            providerStandard.AchievementRates = providerStandard.AchievementRates.Select(c =>
            {
                c.SectorSubjectArea = sectorSubjectArea;
                return(c);
            }).ToList();
            providerService.Setup(x => x.GetProviderByUkprnAndStandard(query.Ukprn, query.StandardId, query.Lat, query.Lon, query.SectorSubjectArea, query.ShortlistUserId.Value)).ReturnsAsync(providerStandard);

            //Act
            var actual = await handler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            actual.ProviderStandardLocation.Should().BeEquivalentTo(providerStandard);
        }
        public void Then_Throws_ValidationException_When_Request_Fails_Validation(
            GetCourseProviderQuery request,
            string propertyName,
            [Frozen] Mock <IValidator <GetCourseProviderQuery> > mockValidator,
            [Frozen] ValidationResult validationResult,
            [Frozen] Mock <ICourseService> mockService,
            GetCourseProviderQueryHandler handler)
        {
            // Arrange
            validationResult.AddError(propertyName);
            mockValidator
            .Setup(validator => validator.ValidateAsync(It.IsAny <GetCourseProviderQuery>()))
            .ReturnsAsync(validationResult);

            // Act
            var act = new Func <Task>(async() => await handler.Handle(request, CancellationToken.None));

            // Assert
            act.Should().Throw <ValidationException>()
            .WithMessage($"*{propertyName}*");
        }