public void AddingSpotToBreakFlagsSpotAsUsed() { // Arrange var smoothBreak = new SmoothBreak( Fixture.Create <Break>(), position: 1); var spot = Fixture.Build <Spot>() .Without(p => p.MultipartSpot) .Create(); var spots = new List <Spot> { spot }; var spotInfos = new Dictionary <Guid, SpotInfo> { [spot.Uid] = Fixture.Create <SpotInfo>() }; var spotIdsUsed = new HashSet <Guid>(); var mockSponsorshipRestrictionService = new Mock <SponsorshipRestrictionService>( new Mock <IReadOnlyList <SponsorshipRestrictionFilterResults> >().Object, new Mock <ISmoothSponsorshipTimelineManager>().Object, new Mock <IReadOnlyDictionary <Guid, SpotInfo> >().Object, new Mock <Action <string, Exception> >().Object ); mockSponsorshipRestrictionService.Setup(s => s.TriggerRecalculationOfAllowedRestrictionLimits( It.IsAny <SpotAction>(), It.IsAny <Spot>(), It.IsAny <Break>())) .Verifiable(); // Act _ = Act(() => { return(SpotPlacementService.AddBookedSpotsToBreak( smoothBreak, spots, spotInfos, spotIdsUsed, mockSponsorshipRestrictionService.Object )); }); // Assert _ = spotIdsUsed.Should().Contain(spot.Uid, becauseArgs: null); }
private static void AddUnusedSpotsToUnusedSpotsCollection( IReadOnlyCollection <Guid> spotIdsUsed, HashSet <Guid> spotIdsNotUsed, IReadOnlyCollection <Spot> allSpots) { foreach (var spot in allSpots) { if (spotIdsUsed.Contains(spot.Uid) || spot.IsBooked()) { continue; } SpotPlacementService.FlagSpotAsNotUsed(spot, spotIdsNotUsed); } // Sanity check _ = spotIdsNotUsed.RemoveWhere(spotIdsUsed.Contains); }
/// <summary> /// Smooth one programme. /// </summary> public SmoothProgramme Execute( SmoothBatchOutput smoothBatchOutput, IReadOnlyCollection <SmoothPass> smoothPasses, IReadOnlyDictionary <string, Break> breaksByExternalRef, IReadOnlyDictionary <string, SpotPlacement> previousSpotPlacementsByExternalRef, IReadOnlyCollection <Break> breaksForThePeriodBeingSmoothed, ISet <Guid> spotIdsUsed) { RaiseDebug( $"Smoothing programme ID [{Log(_smoothProgramme.Programme.Id)}] " + $"in sales area {_smoothProgramme.SalesAreaName}" + Ellipsis ); int countSpotsUnplacedBefore = _programmeSpots.Count(s => !s.IsBooked()); ( _smoothProgramme.BreaksWithPreviousSpots, _smoothProgramme.BreaksWithoutPreviousSpots ) = InitialiseSmoothBreaksForThisProgramme( smoothBatchOutput, spotIdsUsed); // For the breaks in this programme, perform multiple passes from // highest to lowest. If no programme breaks then don't execute any // passes otherwise we'll generate 'Unplaced spot attempt' // (TypeID=1) Smooth failures which is wrong. We'll generate 'No // placing attempt' Smooth failures at the end. var progSpotsNotUsed = new List <Spot>(); var smoothPassResults = new List <SmoothPassResult>(); // We only attempt to place spots if there are breaks if (_smoothProgramme.ProgrammeSmoothBreaks.Count > 0) { ExecuteSmoothPasses( smoothPasses, breaksForThePeriodBeingSmoothed, smoothBatchOutput, progSpotsNotUsed, smoothPassResults, spotIdsUsed); } // For all spots that we attempted to place above (if we make at // least one pass then we 'attempt' to place every spot) remove them // from the list so that our final list contains only those spots // that we didn't make any attempt to place (E.g. No breaks or programmes). if (smoothPassResults.Count > 0) { SpotPlacementService.MarkSpotsAsPlacementWasAttempted(_programmeSpots, _spotInfos); } _smoothProgramme.SmoothFailures.AddRange( _smoothFailuresFactory.CreateSmoothFailuresForUnplacedSpots( _runId, _smoothProgramme.SalesAreaName, smoothPasses, smoothPassResults, progSpotsNotUsed, breaksByExternalRef, previousSpotPlacementsByExternalRef, _threadSafeCollections.CampaignsByExternalRef, _threadSafeCollections.ClashesByExternalRef, _threadSafeCollections.ProductsByExternalRef ) ); _smoothProgramme.SmoothFailures.AddRange( _smoothFailuresFactory.CreateSmoothFailuresForPlacedSpots( _runId, _smoothProgramme.SalesAreaName, _smoothProgramme.ProgrammeSmoothBreaks, breaksByExternalRef, previousSpotPlacementsByExternalRef, _threadSafeCollections.CampaignsByExternalRef, _threadSafeCollections.ClashesByExternalRef, _threadSafeCollections.ProductsByExternalRef ) ); IReadOnlyCollection <Spot> spotsToBatchSave = RenumberSpotPositionInBreak( smoothBatchOutput, spotIdsUsed); _smoothProgramme.SpotsToBatchSave.AddRange(spotsToBatchSave); var recommendationsForPlacedSpots = _smoothRecommendationsFactory.CreateRecommendationsForPlacedSpots( _smoothProgramme.ProgrammeSmoothBreaks, _smoothProgramme.Programme, _smoothProgramme.SalesArea, _processorDateTime ); AddRecommendationsForPlacedSpotsToSmoothProgramme( recommendationsForPlacedSpots); int countSpotsUnplacedAfter = _programmeSpots.Count(s => !s.IsBooked()); _smoothDiagnostics.LogPlacedSmoothSpots( _smoothProgramme.Programme, _smoothProgramme.ProgrammeSmoothBreaks); _smoothDiagnostics.LogProgramme( _smoothProgramme.Programme.Id, _smoothProgramme.ProgrammeSmoothBreaks, countSpotsUnplacedBefore, countSpotsUnplacedAfter ); _smoothDiagnostics.Flush(); return(_smoothProgramme); }