private static void AddRestrictionForParentProgrammeCategory( Dictionary <string, ProgrammeDictionary> programmeDictionaries, DateTime runEndDate, AgRestriction agRestriction, Restriction restriction, SalesArea salesArea, List <AgRestriction> agRestrictions, string clashCode, Dictionary <string, ProgrammeCategoryHierarchy> programmeCategoriesExternalRefIndex, Dictionary <int, ProgrammeCategoryHierarchy> programmeCategoriesIdIndex, int programmeCategoryId) { if (!programmeCategoriesIdIndex.TryGetValue(programmeCategoryId, out var category) || string.IsNullOrEmpty(category.ParentExternalRef)) { return; } var parentCategoryNum = programmeCategoriesExternalRefIndex.TryGetValue(category.ParentExternalRef, out var parentCategory) ? parentCategory.Id : 0; if (parentCategoryNum == 0) { return; } var agRestrictionClone = agRestriction.Clone(); agRestrictionClone.ProductCode = restriction.ProductCode; agRestrictionClone.ClashCode = clashCode; agRestrictionClone.CopyCode = string.IsNullOrWhiteSpace(restriction.ClockNumber) ? "0" : restriction.ClockNumber; agRestrictionClone.ClearanceCode = restriction.ClearanceCode ?? ""; agRestrictionClone.SalesAreaNo = salesArea?.CustomId ?? 0; agRestrictionClone.ProgCategoryNo = parentCategoryNum; agRestrictionClone.ProgrammeNo = !string.IsNullOrWhiteSpace(restriction.ExternalProgRef) && programmeDictionaries.TryGetValue(restriction.ExternalProgRef.ToUpper(), out var programme) ? programme.Id : 0; agRestrictionClone.StartDate = restriction.StartDate.ToString("yyyyMMdd"); agRestrictionClone.EndDate = restriction.EndDate.HasValue ? restriction.EndDate?.ToString("yyyyMMdd") : runEndDate.AddYears(10).ToString("yyyyMMdd"); agRestrictionClone.IndexType = restriction.IndexType; agRestrictionClone.IndexThreshold = restriction.IndexThreshold; agRestrictionClone.PublicHolidayIndicator = AgConversions.ToAgIncludeExcludeEither(restriction.PublicHolidayIndicator); agRestrictionClone.SchoolHolidayIndicator = AgConversions.ToAgIncludeExcludeEither(restriction.SchoolHolidayIndicator); agRestrictionClone.RestrictionType = Convert.ToInt32(restriction.RestrictionType); agRestrictionClone.RestrictionDays = AgConversions.ToAgDaysAsInt(restriction.RestrictionDays); agRestrictionClone.StartTime = restriction.StartTime?.ToString("hhmmss") ?? "0"; agRestrictionClone.EndTime = restriction.EndTime?.ToString("hhmmss") ?? "995959"; agRestrictionClone.TimeToleranceMinsBefore = restriction.TimeToleranceMinsBefore; agRestrictionClone.TimeToleranceMinsAfter = restriction.TimeToleranceMinsAfter; agRestrictionClone.ProgClassCode = restriction.ProgrammeClassification ?? ""; agRestrictionClone.ProgClassFlag = restriction.ProgrammeClassificationIndicator.ToString(); agRestrictionClone.LiveBroadcastFlag = restriction.LiveProgrammeIndicator.ToString(); agRestrictions.Add(agRestrictionClone); }
public void PerformPassDefaultDataPopulation_ShouldReturnRunDateTimeValues_WhenPassDateTimeValuesIsNull() { DateTime? nulldate = null; TimeSpan? nullTimeSpan = null; const string nullString = null; //Arrange _passes[0].PassSalesAreaPriorities = _fixture.Build <PassSalesAreaPriority>() .With(r => r.EndDate, nulldate) .With(r => r.StartDate, nulldate) .With(r => r.StartTime, nullTimeSpan) .With(r => r.EndTime, nullTimeSpan) .With(r => r.DaysOfWeek, nullString) .Create(); var expected = _run; //Act var result = _passes.ToAgPassDefault(_scenario, _run, _tenantSettings); //Assert var valueToTest = expected.EndTime.Minutes == 0 && expected.EndTime.Hours == 0 && expected.EndTime.Seconds == 0 ? "995959" : AgConversions.ToAgTimeAsHHMMSS(expected.EndTime); _ = expected.EndDate.ToString("yyyyMMdd").Should().Be(result?.AgPassDefaults[0]?.EndDate, null); _ = expected.StartDate.ToString("yyyyMMdd").Should().Be(result?.AgPassDefaults[0]?.StartDate, null); _ = valueToTest.Should().Be(result?.AgPassDefaults[0]?.EndTime, null); _ = AgConversions.ToAgTimeAsHHMMSS(expected.StartTime).Should().Be(result?.AgPassDefaults[0]?.StartTime, null); _ = AgConversions.ToAgDaysAsInt(_defaultDaysOfWeek).Should().Be(result?.AgPassDefaults[0]?.DaysOfWeek, null); }
public SponsoredDayPartProfile() { CreateMap <SponsoredDayPart, AgSponsorshipDayPart>() .ForMember(d => d.StartTime, m => m.MapFrom(src => AgConversions.ToAgTimeAsHHMMSS(src.StartTime))) .ForMember(d => d.EndTime, m => m.MapFrom(src => AgConversions.ToAgTimeAsHHMMSS(src.EndTime))) .ForMember(d => d.Days, m => m.MapFrom(src => AgConversions.ToAgDaysAsInt(src.DaysOfWeek))); CreateMap <CreateSponsoredDayPartModel, SponsoredDayPart>() .ForMember(d => d.EndTime, m => m.PreCondition(src => src.EndTime.HasValue)); }
public void PerformPassDefaultDataPopulation_ShouldReturnPassDateTimeValues_WhenPassDateTimeValuesIsNotNull() { //Arrange var expected = _fixture.Build <PassSalesAreaPriority>() .With(r => r.EndDate, DateTime.Now.AddDays(1)) .With(r => r.StartDate, DateTime.Now) .With(r => r.StartTime, new TimeSpan(21, 30, 0)) .With(r => r.EndTime, new TimeSpan(22, 30, 0)) .With(r => r.DaysOfWeek, "1000000") .Create(); _passes[0].PassSalesAreaPriorities = expected; //Act var result = _passes.ToAgPassDefault(_scenario, _run, _tenantSettings); //Assert _ = expected?.EndDate?.ToString("yyyyMMdd").Should().Be(result?.AgPassDefaults[0]?.EndDate, null); _ = expected.StartDate?.ToString("yyyyMMdd").Should().Be(result?.AgPassDefaults[0]?.StartDate, null); _ = AgConversions.ToAgTimeAsHHMMSS((TimeSpan)expected.EndTime).Should().Be(result?.AgPassDefaults[0]?.EndTime, null); _ = AgConversions.ToAgTimeAsHHMMSS((TimeSpan)expected.StartTime).Should().Be(result?.AgPassDefaults[0]?.StartTime, null); _ = AgConversions.ToAgDaysAsInt(expected.DaysOfWeek).Should().Be(result?.AgPassDefaults[0]?.DaysOfWeek, null); }
private List <AgRestriction> LoadAgRestriction(List <Restriction> restrictions, List <ProgrammeCategoryHierarchy> programmeCategories, IReadOnlyCollection <ProgrammeDictionary> programmeDictionaries, List <SalesArea> allSalesAreas, DateTime runEndDate, List <Clash> allClashes, AgRestriction agRestriction) { var agRestrictions = new List <AgRestriction>(); var salesAreaNamesIndex = allSalesAreas.ToDictionary(s => s.Name); var programmeDictionaryExternalRefsIndex = programmeDictionaries.ToDictionary(c => c.ExternalReference.ToUpper()); var programmeCategoryIdsIndex = new Dictionary <int, ProgrammeCategoryHierarchy>(); var programmeCategoryNamesIndex = new Dictionary <string, ProgrammeCategoryHierarchy>(); var programmeCategoryExternalRefsIndex = new Dictionary <string, ProgrammeCategoryHierarchy>(); var clashesExternalRefsIndex = new Dictionary <string, Clash>(); var clashesParentExternalIdentifiersIndex = new Dictionary <string, List <Clash> >(); foreach (var programmeCategory in programmeCategories) { programmeCategoryIdsIndex.Add(programmeCategory.Id, programmeCategory); programmeCategoryNamesIndex.Add(programmeCategory.Name.ToUpper(), programmeCategory); if (!string.IsNullOrWhiteSpace(programmeCategory.ExternalRef)) { programmeCategoryExternalRefsIndex.Add(programmeCategory.ExternalRef, programmeCategory); } } foreach (var clash in allClashes) { clashesExternalRefsIndex.Add(clash.Externalref, clash); if (string.IsNullOrWhiteSpace(clash.ParentExternalidentifier)) { continue; } if (!clashesParentExternalIdentifiersIndex.ContainsKey(clash.ParentExternalidentifier)) { clashesParentExternalIdentifiersIndex.Add(clash.ParentExternalidentifier, new List <Clash>()); } clashesParentExternalIdentifiersIndex[clash.ParentExternalidentifier].Add(clash); } foreach (var restriction in restrictions) { List <SalesArea> salesAreas; if (restriction.SalesAreas == null || !restriction.SalesAreas.Any()) { salesAreas = allSalesAreas; } else { salesAreas = new List <SalesArea>(); foreach (var item in restriction.SalesAreas) { if (salesAreaNamesIndex.TryGetValue(item, out SalesArea area)) { salesAreas.Add(area); } } } foreach (var salesArea in salesAreas) { if (restriction.RestrictionBasis == RestrictionBasis.Clash) { IEnumerable <Clash> clashes = Enumerable.Empty <Clash>(); if (clashesParentExternalIdentifiersIndex.TryGetValue(restriction.ClashCode, out var childClashes)) { clashes = clashes.Union(childClashes); } if (clashesExternalRefsIndex.TryGetValue(restriction.ClashCode, out var item)) { clashes = clashes.Append(item); } foreach (var clash in clashes) { var agRestrictionClone = agRestriction.Clone(); agRestrictionClone.ProductCode = restriction.ProductCode; agRestrictionClone.ClashCode = clash.Externalref; agRestrictionClone.CopyCode = string.IsNullOrWhiteSpace(restriction.ClockNumber) ? "0" : restriction.ClockNumber; agRestrictionClone.ClearanceCode = restriction.ClearanceCode ?? ""; agRestrictionClone.SalesAreaNo = salesArea?.CustomId ?? 0; agRestrictionClone.ProgCategoryNo = !string.IsNullOrWhiteSpace(restriction.ProgrammeCategory) && programmeCategoryNamesIndex.TryGetValue(restriction.ProgrammeCategory.ToUpper(), out var category) ? category.Id : 0; agRestrictionClone.ProgrammeNo = !string.IsNullOrWhiteSpace(restriction.ExternalProgRef) && programmeDictionaryExternalRefsIndex.TryGetValue(restriction.ExternalProgRef.ToUpper(), out var programme) ? programme.Id : 0; agRestrictionClone.StartDate = restriction.StartDate.ToString("yyyyMMdd"); agRestrictionClone.EndDate = restriction.EndDate.HasValue ? restriction.EndDate?.ToString("yyyyMMdd") : runEndDate.AddYears(10).ToString("yyyyMMdd"); agRestrictionClone.IndexType = restriction.IndexType; agRestrictionClone.IndexThreshold = restriction.IndexThreshold; agRestrictionClone.PublicHolidayIndicator = AgConversions.ToAgIncludeExcludeEither(restriction.PublicHolidayIndicator); agRestrictionClone.SchoolHolidayIndicator = AgConversions.ToAgIncludeExcludeEither(restriction.SchoolHolidayIndicator); agRestrictionClone.RestrictionType = Convert.ToInt32(restriction.RestrictionType); agRestrictionClone.RestrictionDays = AgConversions.ToAgDaysAsInt(restriction.RestrictionDays); agRestrictionClone.StartTime = restriction.StartTime?.ToString("hhmmss") ?? "0"; agRestrictionClone.EndTime = restriction.EndTime?.ToString("hhmmss") ?? "995959"; agRestrictionClone.TimeToleranceMinsBefore = restriction.TimeToleranceMinsBefore; agRestrictionClone.TimeToleranceMinsAfter = restriction.TimeToleranceMinsAfter; agRestrictionClone.ProgClassCode = restriction.ProgrammeClassification ?? ""; agRestrictionClone.ProgClassFlag = restriction.ProgrammeClassificationIndicator.ToString(); agRestrictionClone.LiveBroadcastFlag = restriction.LiveProgrammeIndicator.ToString(); agRestrictionClone.EpisodeNo = restriction.EpisodeNumber; agRestrictions.Add(agRestrictionClone); if (agRestrictionClone.ProgCategoryNo != 0) { var clashCode = clash.Externalref; AddRestrictionForParentProgrammeCategory( programmeDictionaryExternalRefsIndex, runEndDate, agRestriction, restriction, salesArea, agRestrictions, clashCode, programmeCategoryExternalRefsIndex, programmeCategoryIdsIndex, agRestrictionClone.ProgCategoryNo ); } } } else { var agRestrictionClone = agRestriction.Clone(); agRestrictionClone.ProductCode = restriction.ProductCode; agRestrictionClone.ClashCode = restriction.ClashCode ?? ""; agRestrictionClone.CopyCode = string.IsNullOrWhiteSpace(restriction.ClockNumber) ? "0" : restriction.ClockNumber; agRestrictionClone.ClearanceCode = restriction.ClearanceCode ?? ""; agRestrictionClone.SalesAreaNo = salesArea?.CustomId ?? 0; agRestrictionClone.ProgCategoryNo = !string.IsNullOrWhiteSpace(restriction.ProgrammeCategory) && programmeCategoryNamesIndex.TryGetValue(restriction.ProgrammeCategory, out var category) ? category.Id : 0; agRestrictionClone.ProgrammeNo = !string.IsNullOrWhiteSpace(restriction.ExternalProgRef) && programmeDictionaryExternalRefsIndex.TryGetValue(restriction.ExternalProgRef.ToUpper(), out var programme) ? programme.Id : 0; agRestrictionClone.StartDate = restriction.StartDate.ToString("yyyyMMdd"); agRestrictionClone.EndDate = restriction.EndDate.HasValue ? restriction.EndDate?.ToString("yyyyMMdd") : runEndDate.AddYears(10).ToString("yyyyMMdd"); agRestrictionClone.IndexType = restriction.IndexType; agRestrictionClone.IndexThreshold = restriction.IndexThreshold; agRestrictionClone.PublicHolidayIndicator = AgConversions.ToAgIncludeExcludeEither(restriction.PublicHolidayIndicator); agRestrictionClone.SchoolHolidayIndicator = AgConversions.ToAgIncludeExcludeEither(restriction.SchoolHolidayIndicator); agRestrictionClone.RestrictionType = Convert.ToInt32(restriction.RestrictionType); agRestrictionClone.RestrictionDays = AgConversions.ToAgDaysAsInt(restriction.RestrictionDays); agRestrictionClone.StartTime = restriction.StartTime?.ToString("hhmmss") ?? "0"; agRestrictionClone.EndTime = restriction.EndTime?.ToString("hhmmss") ?? "995959"; agRestrictionClone.TimeToleranceMinsBefore = restriction.TimeToleranceMinsBefore; agRestrictionClone.TimeToleranceMinsAfter = restriction.TimeToleranceMinsAfter; agRestrictionClone.ProgClassCode = restriction.ProgrammeClassification ?? ""; agRestrictionClone.ProgClassFlag = restriction.ProgrammeClassificationIndicator.ToString(); agRestrictionClone.LiveBroadcastFlag = restriction.LiveProgrammeIndicator.ToString(); agRestrictionClone.EpisodeNo = restriction.EpisodeNumber; agRestrictions.Add(agRestrictionClone); if (agRestrictionClone.ProgCategoryNo != 0) { var clashCode = restriction.ClashCode ?? ""; AddRestrictionForParentProgrammeCategory( programmeDictionaryExternalRefsIndex, runEndDate, agRestriction, restriction, salesArea, agRestrictions, clashCode, programmeCategoryExternalRefsIndex, programmeCategoryIdsIndex, agRestrictionClone.ProgCategoryNo ); } } } } return(agRestrictions); }