private static void ValidateDeliveryYear(DeliveryYearDto deliveryYear, short year, IReadOnlyCollection <int> qualifications) { deliveryYear.Year.Should().Be(year); deliveryYear.Qualifications.Should().NotBeNull(); deliveryYear.Qualifications.Should().HaveCount(qualifications.Count); foreach (var qualification in qualifications) { deliveryYear.Qualifications.Should().Contain(qualification); } }
public static IList <Qualification> GetQualificationsForDeliveryYear( this DeliveryYearDto deliveryYear, IDictionary <int, Qualification> qualificationsDictionary) { var list = new List <Qualification>(); if (deliveryYear.Qualifications != null) { list.AddRange( deliveryYear .Qualifications .Select(q => new Qualification { Id = q, Name = qualificationsDictionary[q].Name, Route = qualificationsDictionary[q].Route })); } return(list.OrderBy(q => q.Name).ToList()); }
private IList <Provider> ProcessTLevelDetailsDocument( JsonDocument jsonDoc) { var providers = new List <Provider>(); foreach (var courseElement in jsonDoc.RootElement .GetProperty("tLevels") .EnumerateArray() .Where(courseElement => courseElement.SafeGetString("offeringType") == "TLevel")) { var tLevelId = courseElement.SafeGetString("tLevelId"); if (!DateTime.TryParse(courseElement.SafeGetString("startDate"), out var startDate)) { _logger.LogWarning("Could not read start date for course record with tLevelId {tLevelId}.", tLevelId); continue; } var qualification = courseElement.TryGetProperty("qualification", out var qualificationProperty) ? qualificationProperty.SafeGetInt32("frameworkCode") : 0; if (qualification == 0) { if (_logger.IsEnabled(LogLevel.Warning)) { _logger.LogWarning("Could not find qualification for course record with tLevelId {tLevelId}.", tLevelId); } continue; } if (!courseElement.TryGetProperty("provider", out var providerProperty)) { if (_logger.IsEnabled(LogLevel.Warning)) { _logger.LogWarning( "Could not find provider property for course record with tLevelId {tLevelId}.", tLevelId); } continue; } if (!int.TryParse(providerProperty.SafeGetString("ukprn"), out var ukPrn)) { if (_logger.IsEnabled(LogLevel.Warning)) { _logger.LogWarning( "Could not find ukprn property for course record with tLevelId {tLevelId}.", tLevelId); } continue; } var providerName = providerProperty.SafeGetString("providerName"); var providerWebsite = providerProperty.SafeGetString("website"); var provider = providers.FirstOrDefault(p => p.UkPrn == ukPrn); if (provider == null) { provider = new Provider { UkPrn = ukPrn, Name = providerName, Locations = new List <Location>() }; providers.Add(provider); } if (!courseElement.TryGetProperty("locations", out var locationsProperty)) { if (_logger.IsEnabled(LogLevel.Warning)) { _logger.LogWarning( "Could not find locations property for course record with tLevelId {tLevelId}.", tLevelId); } continue; } foreach (var locationElement in locationsProperty.EnumerateArray()) { var postcode = locationElement.SafeGetString("postcode"); var locationWebsite = locationElement.SafeGetString("website"); var location = provider.Locations.FirstOrDefault(l => l.Postcode == postcode); if (location == null) { location = new Location { Postcode = postcode, Name = locationElement.SafeGetString("venueName"), Town = locationElement.SafeGetString("town"), Latitude = locationElement.SafeGetDouble("latitude"), Longitude = locationElement.SafeGetDouble("longitude"), Website = !string.IsNullOrWhiteSpace(locationWebsite) ? locationWebsite : providerWebsite, DeliveryYears = new List <DeliveryYearDto>() }; provider.Locations.Add(location); } var deliveryYear = location .DeliveryYears .FirstOrDefault(dy => dy.Year == startDate.Year); if (deliveryYear == null) { deliveryYear = new DeliveryYearDto { Year = (short)startDate.Year, Qualifications = new List <int> { qualification } }; location.DeliveryYears.Add(deliveryYear); } else if (!deliveryYear.Qualifications .Contains(qualification)) { deliveryYear.Qualifications.Add(qualification); } } } return(providers); }