public async Task TLevels_Get_WithNoTLevels_ReturnsOkWithEmptyCollection() { SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetTLevels>())) .ReturnsAsync(Array.Empty <TLevel>()); CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <CosmosQueries.GetProvidersByIds>())) .ReturnsAsync(new Dictionary <Guid, CosmosModels.Provider>()); SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetProvidersByIds>())) .ReturnsAsync(new Dictionary <Guid, Provider>()); SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetVenuesByIds>())) .ReturnsAsync(new Dictionary <Guid, Venue>()); CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <CosmosQueries.GetFeChoicesByProviderUkprns>())) .ReturnsAsync(new Dictionary <int, CosmosModels.FeChoice>()); // Act var response = await HttpClient.GetAsync($"tlevels"); // Assert response.StatusCode.Should().Be(StatusCodes.Status200OK); var result = JObject.Parse(await response.Content.ReadAsStringAsync()); result.Should().NotBeNull(); result["tLevels"].ToArray().Should().BeEmpty(); }
public async Task TLevels_Get_WithTLevels_ReturnsOkWithExpectedTLevelsCollection() { var provider1 = CreateProvider(1); var sqlProvider1 = CreateSqlProvider(provider1); var provider1FeChoice = CreateFeChoice(1, provider1.Ukprn); var provider1Venue1 = CreateVenue(1); var provider1Venue2 = CreateVenue(2); var provider1TLevelLocation1 = CreateTLevelLocation(1, provider1Venue1.VenueId); var provider1TLevelLocation2 = CreateTLevelLocation(2, provider1Venue1.VenueId); var provider1TLevelLocation3 = CreateTLevelLocation(3, provider1Venue2.VenueId); // Provider1, with one location var provider1TLevel1 = CreateTLevel(1, provider1, new[] { provider1TLevelLocation1 }); // Provider1, with two locations var provider1TLevel2 = CreateTLevel(2, provider1, new[] { provider1TLevelLocation2, provider1TLevelLocation3 }); var provider2 = CreateProvider(2); var sqlProvider2 = CreateSqlProvider(provider2); var provider2Venue1 = CreateVenue(3); var provider2TLevelLocation1 = CreateTLevelLocation(4, provider2Venue1.VenueId); // Provider2, with one location, no FeChoices var provider2TLevel1 = CreateTLevel(3, provider2, new[] { provider2TLevelLocation1 }); SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetTLevels>())) .ReturnsAsync(new[] { provider1TLevel1, provider1TLevel2, provider2TLevel1 }); CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <CosmosQueries.GetProvidersByIds>())) .ReturnsAsync(new[] { provider1, provider2 }.ToDictionary(p => p.Id, p => p)); SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetProvidersByIds>())) .ReturnsAsync(new[] { sqlProvider1, sqlProvider2 }.ToDictionary(p => p.ProviderId, p => p)); SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetVenuesByIds>())) .ReturnsAsync(new[] { provider1Venue1, provider1Venue2, provider2Venue1 }.ToDictionary(v => v.VenueId, v => v)); CosmosDbQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <CosmosQueries.GetFeChoicesByProviderUkprns>())) .ReturnsAsync(new[] { provider1FeChoice }.ToDictionary(f => f.UKPRN, f => f)); // Act var response = await HttpClient.GetAsync($"tlevels"); // Assert response.StatusCode.Should().Be(StatusCodes.Status200OK); var result = JObject.Parse(await response.Content.ReadAsStringAsync()); result.Should().NotBeNull(); var tLevels = result["tLevels"].ToArray(); tLevels.Should().NotBeNullOrEmpty(); tLevels.Length.Should().Be(3); AssertHasTLevel(tLevels, provider1, sqlProvider1, new[] { provider1Venue1, provider1Venue2 }, provider1TLevel1, provider1FeChoice); AssertHasTLevel(tLevels, provider1, sqlProvider1, new[] { provider1Venue1, provider1Venue2 }, provider1TLevel2, provider1FeChoice); AssertHasTLevel(tLevels, provider2, sqlProvider2, new[] { provider2Venue1 }, provider2TLevel1, null);
public async Task Handle_WithCourseIdNotFound_ReturnsNotFound() { var courseId = Guid.NewGuid(); var courseRunId = Guid.NewGuid(); SqlQueryDispatcher.Setup(s => s.ExecuteQuery(It.IsAny <GetCourse>())) .ReturnsAsync((Course)null); var result = await HttpClient.GetAsync(CourseRunDetailUrl(courseId, courseRunId)); result.StatusCode.Should().Be(StatusCodes.Status404NotFound); }
public async Task ValidRequest_ReturnsOkWithExpectedOutput() { // Arrange var tLevelDefinitions = new[] { CreateTLevelDefinition(1), CreateTLevelDefinition(2), CreateTLevelDefinition(3) }; SqlQueryDispatcher .Setup(s => s.ExecuteQuery(It.IsAny <GetTLevelDefinitions>())) .ReturnsAsync(tLevelDefinitions); // Act var response = await HttpClient.GetAsync($"tleveldefinitions"); // Assert response.StatusCode.Should().Be(StatusCodes.Status200OK); var json = JObject.Parse(await response.Content.ReadAsStringAsync()); json["tLevelDefinitions"]?.ToArray().Should().NotBeNullOrEmpty() .And.HaveCount(tLevelDefinitions.Length); using (new AssertionScope()) { foreach (var tLevelDefinition in tLevelDefinitions) { var item = json["tLevelDefinitions"].SingleOrDefault(t => t["tLevelDefinitionId"].ToObject <Guid>() == tLevelDefinition.TLevelDefinitionId); item.Should().NotBeNull(); item["frameworkCode"].ToObject <int>().Should().Be(tLevelDefinition.FrameworkCode); item["progType"].ToObject <int>().Should().Be(tLevelDefinition.ProgType); item["qualificationLevel"].ToObject <string>().Should().Be(tLevelDefinition.QualificationLevel.ToString()); item["name"].ToObject <string>().Should().Be(tLevelDefinition.Name); } } }
public async Task PostcodeWithoutSpaces_IsNormalizedToIncludeSpace() { // Arrange var postcode = "AB12DE"; var normalizedPostcode = "AB1 2DE"; var lat = 1D; var lng = 2D; ConfigureOnspdSearchResultsForPostcode(normalizedPostcode, coords: (lat, lng)); var request = CreateRequest(new { postcode, sortBy = "Distance" }); // Act var response = await HttpClient.SendAsync(request); // Assert response.EnsureSuccessStatusCode(); SqlQueryDispatcher.Verify(c => c.ExecuteQuery(It.Is <GetPostcodeInfo>(q => q.Postcode == normalizedPostcode))); }
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); } }
public async Task ValidRequest_ReturnsOkWithExpectedOutput() { // Arrange var providerId = Guid.NewGuid(); var providerName = "Test Provider"; var providerUkprn = 123456; var providerContactEmail = "*****@*****.**"; var providerEmployerSatisfaction = 9m; var providerLearnerSatisfaction = 10m; var tLevelDefinitionId = Guid.NewGuid(); var tLevelDefinitionName = "T Level name"; var tLevelDefinitionFrameworkCode = 4; var tLevelDefinitionProgType = 3; var tLevelDefinitionQualificationLevel = 5; var venueId = Guid.NewGuid(); var venueName = "Venue"; var venueAddressLine1 = "Venue address line 1"; var venueAddressLine2 = "Venue address line 2"; var venueTown = "Venue town"; var venueCounty = "Venue county"; var venuePostcode = "AB1 2DE"; var venueTelephone = "01234 567890"; var venueEmail = "*****@*****.**"; var venueWebsite = "exampleprovider.com/venue"; var venueLatitude = 1d; var venueLongitude = 2d; var tLevelId = Guid.NewGuid(); var whoFor = "Who for"; var entryRequirements = "Entry requirements"; var whatYoullLearn = "What you'll learn"; var howYoullLearn = "How you'll learn"; var howYoullBeAssessed = "How you'll be assessed"; var whatYouCanDoNext = "What you can do next"; var yourReference = "YOUR-REF"; var startDate = new DateTime(2021, 4, 1); var website = "http://exampleprovider.com/tlevel"; var tLevelLocationId = Guid.NewGuid(); var now = DateTime.UtcNow; SqlQueryDispatcher .Setup(d => d.ExecuteQuery(It.Is <GetTLevel>(q => q.TLevelId == tLevelId))) .ReturnsAsync(new TLevel() { TLevelId = tLevelId, TLevelStatus = TLevelStatus.Live, TLevelDefinition = new TLevelDefinition() { TLevelDefinitionId = tLevelDefinitionId, Name = tLevelDefinitionName, FrameworkCode = tLevelDefinitionFrameworkCode, ProgType = tLevelDefinitionProgType, QualificationLevel = tLevelDefinitionQualificationLevel }, ProviderId = providerId, ProviderName = providerName, WhoFor = whoFor, EntryRequirements = entryRequirements, WhatYoullLearn = whatYoullLearn, HowYoullLearn = howYoullLearn, HowYoullBeAssessed = howYoullBeAssessed, WhatYouCanDoNext = whatYouCanDoNext, YourReference = yourReference, StartDate = startDate, Locations = new[] { new TLevelLocation() { TLevelLocationId = tLevelLocationId, TLevelLocationStatus = TLevelLocationStatus.Live, VenueId = venueId, VenueName = venueName } }, Website = website, CreatedOn = now, UpdatedOn = now }); SqlQueryDispatcher .Setup(d => d.ExecuteQuery(It.Is <GetProviderById>(q => q.ProviderId == providerId))) .ReturnsAsync(new Provider() { ProviderId = providerId, ProviderType = ProviderType.TLevels, ProviderName = providerName, Ukprn = providerUkprn }); SqlQueryDispatcher .Setup(d => d.ExecuteQuery(It.Is <GetVenuesByIds>(q => q.VenueIds.SingleOrDefault() == venueId))) .ReturnsAsync(new Dictionary <Guid, Venue>() { { venueId, new Venue() { VenueId = venueId, VenueName = venueName, AddressLine1 = venueAddressLine1, AddressLine2 = venueAddressLine2, Town = venueTown, County = venueCounty, Postcode = venuePostcode, Telephone = venueTelephone, Email = venueEmail, Website = venueWebsite, Latitude = venueLatitude, Longitude = venueLongitude } } }); CosmosDbQueryDispatcher .Setup(d => d.ExecuteQuery(It.Is <Core.DataStore.CosmosDb.Queries.GetProviderById>(q => q.ProviderId == providerId))) .ReturnsAsync(new Core.DataStore.CosmosDb.Models.Provider() { Id = providerId, UnitedKingdomProviderReferenceNumber = providerUkprn.ToString(), ProviderType = ProviderType.TLevels, ProviderContact = new[] { new Core.DataStore.CosmosDb.Models.ProviderContact() { ContactType = "P", // Primary, ContactEmail = providerContactEmail } }, ProviderAliases = Array.Empty <Core.DataStore.CosmosDb.Models.ProviderAlias>() }); CosmosDbQueryDispatcher .Setup(d => d.ExecuteQuery(It.Is <Core.DataStore.CosmosDb.Queries.GetFeChoiceForProvider>(q => q.ProviderUkprn == providerUkprn))) .ReturnsAsync(new Core.DataStore.CosmosDb.Models.FeChoice() { UKPRN = providerUkprn, Id = Guid.NewGuid(), EmployerSatisfaction = providerEmployerSatisfaction, LearnerSatisfaction = providerLearnerSatisfaction, CreatedDateTimeUtc = now }); // Act var response = await HttpClient.GetAsync($"tleveldetail?tlevelid={tLevelId}"); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var json = JObject.Parse(await response.Content.ReadAsStringAsync()); using (new AssertionScope()) { json["offeringType"].ToObject <string>().Should().Be("TLevel"); json["tLevelId"].ToObject <string>().Should().Be(tLevelId.ToString()); json["tLevelDefinitionId"].ToObject <string>().Should().Be(tLevelDefinitionId.ToString()); json["qualification"]["frameworkCode"].ToObject <int>().Should().Be(tLevelDefinitionFrameworkCode); json["qualification"]["progType"].ToObject <int>().Should().Be(tLevelDefinitionProgType); json["qualification"]["qualificationLevel"].ToObject <string>().Should().Be(tLevelDefinitionQualificationLevel.ToString()); json["qualification"]["tLevelName"].ToObject <string>().Should().Be(tLevelDefinitionName); json["provider"]["providerName"].ToObject <string>().Should().Be(providerName); json["provider"]["ukprn"].ToObject <int>().Should().Be(providerUkprn); json["provider"]["email"].ToObject <string>().Should().Be(providerContactEmail); json["provider"]["employerSatisfaction"].ToObject <decimal?>().Should().Be(providerEmployerSatisfaction); json["provider"]["learnerSatisfaction"].ToObject <decimal?>().Should().Be(providerLearnerSatisfaction); json["whoFor"].ToObject <string>().Should().Be(whoFor); json["entryRequirements"].ToObject <string>().Should().Be(entryRequirements); json["whatYoullLearn"].ToObject <string>().Should().Be(whatYoullLearn); json["howYoullLearn"].ToObject <string>().Should().Be(howYoullLearn); json["howYoullBeAssessed"].ToObject <string>().Should().Be(howYoullBeAssessed); json["whatYouCanDoNext"].ToObject <string>().Should().Be(whatYouCanDoNext); json["website"].ToObject <string>().Should().Be(website); json["startDate"].ToObject <DateTime>().Should().Be(startDate); json["deliveryMode"].ToObject <string>().Should().Be("ClassroomBased"); json["attendancePattern"].ToObject <string>().Should().Be("Daytime"); json["studyMode"].ToObject <string>().Should().Be("FullTime"); json["durationUnit"].ToObject <string>().Should().Be("Years"); json["durationValue"].ToObject <int>().Should().Be(2); json["cost"].ToObject <decimal?>().Should().BeNull(); json["costDescription"].ToObject <string>().Should().Be("T Levels are currently only available to 16-19 year olds. Contact us for details of other suitable courses."); var location = json["locations"].ToArray().Should().ContainSingle().Subject; location["tLevelLocationId"].ToObject <string>().Should().Be(tLevelLocationId.ToString()); location["venueName"].ToObject <string>().Should().Be(venueName); location["addressLine1"].ToObject <string>().Should().Be(venueAddressLine1); location["addressLine2"].ToObject <string>().Should().Be(venueAddressLine2); location["town"].ToObject <string>().Should().Be(venueTown); location["county"].ToObject <string>().Should().Be(venueCounty); location["postcode"].ToObject <string>().Should().Be(venuePostcode); location["telephone"].ToObject <string>().Should().Be(venueTelephone); location["email"].ToObject <string>().Should().Be(venueEmail); location["website"].ToObject <string>().Should().Be("http://" + venueWebsite); location["latitude"].ToObject <double>().Should().Be(venueLatitude); location["longitude"].ToObject <double>().Should().Be(venueLongitude); } }