Exemple #1
0
        public void GivenNoSalesAreasAWarningIsLogged()
        {
            // Arrange
            var service = new RecalculateBreakAvailabilityService(
                _mockRepositoryFactory.Object,
                stubLogger
                );

            // Act
            service.Execute(
                _period,
                Enumerable.Empty <SalesArea>()
                );

            // Assert
            _ = stubLogger.Messages
                .Should()
                .ContainSingle(x => x.Equals("No sales areas were passed to the calculator."), null);
        }
Exemple #2
0
        public void AScheduleBreakMustHaveTheSameAvailabilityAsTheOrdinaryBreak()
        {
            // Arrange
            var mockSalesAreaName = _fixture.Create <string>();

            var mockSpots = _fixture
                            .Build <Spot>()
                            .With(p => p.SalesArea, mockSalesAreaName)
                            .With(p => p.StartDateTime, _period.Start)
                            .With(p => p.SpotLength, Duration.FromSeconds(30))
                            .With(p => p.ClientPicked, true)
                            .Without(p => p.ExternalBreakNo)
                            .CreateMany(4)
                            .ToList();

            var mockProgramme = _fixture
                                .Build <Programme>()
                                .With(p => p.SalesArea, mockSalesAreaName)
                                .With(p => p.StartDateTime, _period.Start)
                                .With(p => p.Duration, Duration.FromHours(1))
                                .Create();

            var mockBreaks = _fixture
                             .Build <Break>()
                             .With(p => p.SalesArea, mockSalesAreaName)
                             .With(p => p.ScheduledDate, _period.Start)
                             .With(p => p.Duration, Duration.FromSeconds(180))
                             .With(p => p.Avail, Duration.FromSeconds(180))
                             .With(p => p.OptimizerAvail, Duration.FromSeconds(180))
                             .CreateMany()
                             .ToList();

            var mockSchedule = _fixture
                               .Build <Schedule>()
                               .With(p => p.SalesArea, mockSalesAreaName)
                               .With(p => p.Date, _period.Start)
                               .Create();

            CreateTheSchedule(mockProgramme, mockBreaks, mockSchedule);
            AddSpotToBreak(mockSpots, mockBreaks, mockSchedule);

            _ = mockSchedule.Breaks[0].Avail.Should().NotBe(mockBreaks[0].Avail, null);

            _ = _mockBreakRepository
                .Setup(m =>
                       m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>()))
                .Returns(mockBreaks);

            _ = _mockScheduleRepository
                .Setup(m =>
                       m.GetSchedule(It.IsAny <string>(), It.IsAny <DateTime>()))
                .Returns(mockSchedule);

            _mockScheduleRepository
            .Setup(m => m.Update(It.IsAny <Schedule>()))
            .Verifiable();

            _ = _mockSpotRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <List <string> >()))
                .Returns(mockSpots);

            _ = _mockProgrammeRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>()))
                .Returns(new List <Programme>(1)
            {
                mockProgramme
            });

            var service = new RecalculateBreakAvailabilityService(
                _mockRepositoryFactory.Object,
                stubLogger
                );

            var mockSalesArea = _fixture
                                .Build <SalesArea>()
                                .With(p => p.Name, mockSalesAreaName)
                                .Create();

            // Act
            service.Execute(
                _period,
                new List <SalesArea>(1)
            {
                mockSalesArea
            }
                );

            // Assert
            _ = stubLogger.Messages
                .Should()
                .Contain(x => x.StartsWith("Found schedule for sales area"), null);

            _ = mockSchedule.Breaks[0].Avail.Should().Be(mockBreaks[0].Avail, null);

            var targetBreak = mockBreaks.First(y =>
                                               y.ExternalBreakRef.Equals("Break_0"));

            var targetScheduleBreak = mockSchedule.Breaks.First(y =>
                                                                y.ExternalBreakRef.Equals("Break_0"));

            _mockScheduleRepository.Verify(m =>
                                           m.Update(
                                               It.Is <Schedule>(x => x.Breaks.Contains(targetScheduleBreak))
                                               ));

            _ = targetBreak.Avail.Should().Be(Duration.FromSeconds(150), null);
            _ = targetBreak.OptimizerAvail.Should().Be(Duration.FromSeconds(120), null);

            _ = targetScheduleBreak.Avail.Should().Be(Duration.FromSeconds(150), null);
            _ = targetScheduleBreak.OptimizerAvail.Should().Be(Duration.FromSeconds(120), null);
        }
Exemple #3
0
        public void ProgrammeStartsBeforeMidnightAndFinishesAfterMidnight()
        {
            // Arrange
            Programme programme1 = CreateProgramme(
                _period.Start.Date.AddHours(23),
                Duration.FromMinutes(30)
                );

            Programme programme2 = CreateProgramme(
                _period.Start.Date.AddHours(23).AddMinutes(30),
                Duration.FromMinutes(60)
                );

            var breakOneStart = programme2.StartDateTime.AddMinutes(5);
            var breakTwoStart = programme2.StartDateTime.AddMinutes(45);

            List <Break> breaks         = CreateBreaks(breakOneStart, breakTwoStart);
            List <Break> scheduleBreaks = CreateBreaks(breakOneStart, breakTwoStart);

            LinkBreaks(breaks, scheduleBreaks);

            List <Spot>     spots     = CreateSpots(breaks);
            List <Schedule> schedules = CreateSchedules(programme1, programme2, scheduleBreaks);

            _ = _mockProgrammeRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsNotNull <string>()))
                .Returns(new List <Programme> {
                programme1, programme2
            });

            _ = _mockSpotRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsNotNull <List <string> >()))
                .Returns(spots);

            _ = _mockBreakRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsNotNull <string>()))
                .Returns(breaks);

            _ = _mockScheduleRepository
                .Setup(m => m.GetSchedule(It.IsNotNull <string>(), It.Is <DateTime>(x => x.Date == breakOneStart.Date)))
                .Returns(schedules[0]);

            _ = _mockScheduleRepository
                .Setup(m => m.GetSchedule(It.IsNotNull <string>(), It.Is <DateTime>(x => x.Date == breakTwoStart.Date)))
                .Returns(schedules[1]);

            var service = new RecalculateBreakAvailabilityService(_mockRepositoryFactory.Object, stubLogger);

            // Act
            service.Execute(_period, _salesAreas);

            // Assert
            _mockBreakRepository.Verify(m => m.SaveChanges(), Times.Once);
            _mockScheduleRepository.Verify(m => m.SaveChanges(), Times.Once);

            _mockBreakRepository.Verify(m =>
                                        m.Add(It.Is <Break>(x =>
                                                            x.ScheduledDate.Date == breakOneStart.Date &&
                                                            x.Avail == Duration.FromSeconds(150) &&
                                                            x.OptimizerAvail == Duration.FromSeconds(120)
                                                            )),
                                        Times.Exactly(4)
                                        );

            _mockBreakRepository.Verify(m =>
                                        m.Add(It.Is <Break>(x =>
                                                            x.ScheduledDate.Date == breakTwoStart.Date &&
                                                            x.Avail == Duration.FromSeconds(150) &&
                                                            x.OptimizerAvail == Duration.FromSeconds(120)
                                                            )),
                                        Times.Exactly(4)
                                        );

            _mockScheduleRepository.Verify(m =>
                                           m.Update(It.Is <Schedule>(x =>
                                                                     x.Date.Date == breakOneStart.Date &&
                                                                     x.Breaks[0].Avail == Duration.FromSeconds(150) &&
                                                                     x.Breaks[0].OptimizerAvail == Duration.FromSeconds(120)
                                                                     )),
                                           Times.Once
                                           );

            _mockScheduleRepository.Verify(m =>
                                           m.Update(It.Is <Schedule>(x =>
                                                                     x.Date.Date == breakTwoStart.Date &&
                                                                     x.Breaks[0].Avail == Duration.FromSeconds(150) &&
                                                                     x.Breaks[0].OptimizerAvail == Duration.FromSeconds(120)
                                                                     )),
                                           Times.Exactly(2)
                                           );
        }
Exemple #4
0
        public void GivenManySpotsInformationOnManySpotsIsLogged()
        {
            // Arrange
            var mockSalesAreaName = _fixture.Create <string>();

            var mockSpots = _fixture
                            .Build <Spot>()
                            .With(p => p.SalesArea, mockSalesAreaName)
                            .With(p => p.StartDateTime, _period.Start)
                            .CreateMany(4)
                            .ToList();

            var mockProgrammes = _fixture
                                 .Build <Programme>()
                                 .With(p => p.SalesArea, mockSalesAreaName)
                                 .With(p => p.StartDateTime, _period.Start)
                                 .CreateMany(2)
                                 .ToList();

            var mockBreaks = _fixture
                             .Build <Break>()
                             .With(p => p.SalesArea, mockSalesAreaName)
                             .With(p => p.ScheduledDate, _period.Start)
                             .With(p => p.Duration, Duration.FromSeconds(180))
                             .CreateMany()
                             .ToList();

            _ = _mockBreakRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>()))
                .Returns(mockBreaks);

            _ = _mockSpotRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <List <string> >()))
                .Returns(mockSpots);

            _ = _mockProgrammeRepository
                .Setup(m => m.Search(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>()))
                .Returns(mockProgrammes);

            var service = new RecalculateBreakAvailabilityService(
                _mockRepositoryFactory.Object,
                stubLogger
                );

            var mockSalesArea = _fixture
                                .Build <SalesArea>()
                                .With(p => p.Name, mockSalesAreaName)
                                .Create();

            // Act
            service.Execute(
                _period,
                new List <SalesArea>(1)
            {
                mockSalesArea
            }
                );

            // Assert
            _ = stubLogger.Messages
                .Should()
                .Contain(x => x.StartsWith($"Found {mockSpots.Count.ToString()} spots for sales area {mockSalesAreaName}"), null);
        }