Exemplo n.º 1
0
        private async Task ChooseQualification_NotionalNVQLevelv2FiltersCount_IsCorrect()
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var notionalNVQLevelv2Facets = new Dictionary <object, long?> {
                { new Object(), 343 }, { new Object(), 3433 }, { new Object(), 341 }
            };
            var awardOrgCodeFacets = new Dictionary <object, long?>();

            dfc.SearchResult <Lars> res = new dfc.SearchResult <Lars>
            {
                Items = new ReadOnlyCollection <dfc.SearchResultItem <Lars> >(new List <dfc.SearchResultItem <Lars> >()
                {
                    new dfc.SearchResultItem <Lars>()
                    {
                        Record = new Lars(),
                    },
                    new dfc.SearchResultItem <Lars>()
                    {
                        Record = new Lars(),
                    }
                }),
                TotalCount = 2,
                Facets     = new Dictionary <string, IReadOnlyDictionary <object, long?> >
                {
                    { "AwardOrgCode", awardOrgCodeFacets },
                    { "NotionalNVQLevelv2", notionalNVQLevelv2Facets }
                }
            };
            LarsSearchClient.Setup(x => x.Search(It.IsAny <dfc.LarsSearchQuery>())).ReturnsAsync(res);
            LarsSearchSettings.Setup(x => x.Value).Returns(new Core.Configuration.LarsSearchSettings()
            {
                ItemsPerPage = 20
            });

            var request = new HttpRequestMessage(HttpMethod.Get, $"/courses/search?SearchTerm=test&providerId={provider.ProviderId}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            var doc = await response.GetDocument();

            using (new AssertionScope())
            {
                doc.GetElementsByClassName("NotionalNVQLevelv2FilterOption").Length.Should().Be(3);
                doc.GetElementsByClassName("AwardingOrganisationFilterOption").Length.Should().Be(0);
            }
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Exemplo n.º 2
0
        private async Task ChooseQualification_SearchTermLengthInvalid_RendersError(string term)
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var notionalNVQLevelv2Facets = new Dictionary <object, long?>();
            var awardOrgCodeFacets       = new Dictionary <object, long?> {
                { new Object(), 343 }, { new Object(), 3433 }
            };

            dfc.SearchResult <Lars> res = new dfc.SearchResult <Lars>
            {
                Items = new ReadOnlyCollection <dfc.SearchResultItem <Lars> >(new List <dfc.SearchResultItem <Lars> >()
                {
                    new dfc.SearchResultItem <Lars>()
                    {
                        Record = new Lars(),
                    },
                    new dfc.SearchResultItem <Lars>()
                    {
                        Record = new Lars(),
                    }
                }),
                TotalCount = 2,
                Facets     = new Dictionary <string, IReadOnlyDictionary <object, long?> >
                {
                    { "AwardOrgCode", awardOrgCodeFacets },
                    { "NotionalNVQLevelv2", notionalNVQLevelv2Facets }
                }
            };
            LarsSearchClient.Setup(x => x.Search(It.IsAny <dfc.LarsSearchQuery>())).ReturnsAsync(res);
            LarsSearchSettings.Setup(x => x.Value).Returns(new Core.Configuration.LarsSearchSettings()
            {
                ItemsPerPage = 20
            });

            var request = new HttpRequestMessage(HttpMethod.Get, $"/courses/search?SearchTerm={term}&providerId={provider.ProviderId}");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            var doc = await response.GetDocument();

            using (new AssertionScope())
            {
                doc.GetElementByTestId("SearchErrorMessage").TextContent.Should().Be("Enter search criteria");
            }
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Exemplo n.º 3
0
        private async Task ChooseQualification_SearchReturnsNoResults_RendersNoResultsMessage()
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var notionalNVQLevelv2Facets = new Dictionary <object, long?>();
            var awardOrgCodeFacets       = new Dictionary <object, long?>();

            dfc.SearchResult <Lars> res = new dfc.SearchResult <Lars>
            {
                Items = new ReadOnlyCollection <dfc.SearchResultItem <Lars> >(new List <dfc.SearchResultItem <Lars> >()
                {
                }),
                TotalCount = 0,
                Facets     = new Dictionary <string, IReadOnlyDictionary <object, long?> >
                {
                    { "AwardOrgCode", awardOrgCodeFacets },
                    { "NotionalNVQLevelv2", notionalNVQLevelv2Facets }
                }
            };
            LarsSearchClient.Setup(x => x.Search(It.IsAny <dfc.LarsSearchQuery>())).ReturnsAsync(res);
            LarsSearchSettings.Setup(x => x.Value).Returns(new Core.Configuration.LarsSearchSettings()
            {
                ItemsPerPage = 20
            });

            var request = new HttpRequestMessage(HttpMethod.Get, $"/courses/search?SearchTerm=test&providerId={provider.ProviderId}");
            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            var doc = await response.GetDocument();

            using (new AssertionScope())
            {
                doc.GetElementByTestId("NoResults").Should().NotBeNull();
            }
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task Handle_WithValidCourseIdAndCourseRunId_ReturnsOkWithResult()
        {
            var venue = new Venue
            {
                Id        = Guid.NewGuid(),
                VenueName = "TestVenueName"
            };

            var lars = new Core.Search.Models.Lars
            {
                LearnAimRef      = "00112233",
                LearnAimRefTitle = "TestLearnAimRefTitle"
            };

            var courseRun = new CourseRun
            {
                Id           = Guid.NewGuid(),
                RecordStatus = CourseStatus.Live,
                VenueId      = venue.Id
            };

            var alternativeCourseRun = new CourseRun
            {
                Id           = Guid.NewGuid(),
                RecordStatus = CourseStatus.Live,
                VenueId      = venue.Id
            };

            var course = new Course
            {
                Id            = Guid.NewGuid(),
                ProviderUKPRN = 12345678,
                LearnAimRef   = lars.LearnAimRef,
                CourseRuns    = new[]
                {
                    courseRun,
                    alternativeCourseRun
                }
            };

            var provider = new Provider
            {
                Id = Guid.NewGuid(),
                UnitedKingdomProviderReferenceNumber = "12345678",
                ProviderContact = new[]
                {
                    new ProviderContact
                    {
                        ContactEmail = "*****@*****.**",
                        ContactType  = "P"
                    }
                }
            };

            var sqlProvider = new Core.DataStore.Sql.Models.Provider
            {
                ProviderId        = provider.Id,
                ProviderName      = "TestProviderAlias",
                DisplayNameSource = ProviderDisplayNameSource.ProviderName
            };

            var feChoice = new FeChoice
            {
                UKPRN = course.ProviderUKPRN,
                EmployerSatisfaction = 1.2M,
                LearnerSatisfaction  = 3.4M
            };

            CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetCourseById>()))
            .ReturnsAsync(course);

            CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetProviderByUkprn>()))
            .ReturnsAsync(provider);

            LarsSearchClient.Setup(s => s.Search(It.IsAny <LarsLearnAimRefSearchQuery>()))
            .ReturnsAsync(new SearchResult <Core.Search.Models.Lars>
            {
                Items = new[] { new SearchResultItem <Core.Search.Models.Lars> {
                                    Record = lars
                                } }
            });

            CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetVenuesByProvider>()))
            .ReturnsAsync(new[] { venue });

            CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetFeChoiceForProvider>()))
            .ReturnsAsync(feChoice);

            SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <Core.DataStore.Sql.Queries.GetProviderById>()))
            .ReturnsAsync(sqlProvider);

            var result = await HttpClient.GetAsync(CourseRunDetailUrl(course.Id, courseRun.Id));

            result.StatusCode.Should().Be(StatusCodes.Status200OK);

            var resultJson = JObject.Parse(await result.Content.ReadAsStringAsync());

            using (new AssertionScope())
            {
                resultJson.ToObject <object>().Should().NotBeNull();
                resultJson["provider"].ToObject <object>().Should().NotBeNull();
                resultJson["provider"]["ukprn"].ToObject <int>().Should().Be(provider.Ukprn);
                resultJson["provider"]["providerName"].ToObject <string>().Should().Be(sqlProvider.DisplayName);
                resultJson["provider"]["tradingName"].ToObject <string>().Should().Be(sqlProvider.DisplayName);
                resultJson["provider"]["email"].ToObject <string>().Should().Be(provider.ProviderContact.Single().ContactEmail);
                resultJson["provider"]["learnerSatisfaction"].ToObject <decimal>().Should().Be(feChoice.LearnerSatisfaction);
                resultJson["provider"]["employerSatisfaction"].ToObject <decimal>().Should().Be(feChoice.EmployerSatisfaction);
                resultJson["course"].ToObject <object>().Should().NotBeNull();
                resultJson["course"]["courseId"].ToObject <Guid>().Should().Be(course.Id);
                resultJson["venue"].ToObject <object>().Should().NotBeNull();
                resultJson["venue"]["venueName"].ToObject <string>().Should().Be(venue.VenueName);
                resultJson["qualification"].ToObject <object>().Should().NotBeNull();
                resultJson["qualification"]["learnAimRef"].ToObject <string>().Should().Be(lars.LearnAimRef);
                resultJson["qualification"]["learnAimRefTitle"].ToObject <string>().Should().Be(lars.LearnAimRefTitle);
                resultJson["alternativeCourseRuns"][0]["courseRunId"].ToObject <Guid>().Should().Be(alternativeCourseRun.Id);
                resultJson["courseRunId"].ToObject <Guid>().Should().Be(courseRun.Id);
            }
        }