Exemplo n.º 1
0
        public void GetsTocSchedulesRunningOnRailDay()
        {
            var timetable = CreateTimetable();

            var schedule      = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var schedule2     = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday));
            var startsRailDay = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98765",
                                                                        calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday | DaysFlag.Tuesday),
                                                                        stops: TestSchedules.CreateThreeStopSchedule(Time.StartRailDay));
            var startsBeforeRailDay = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98764",
                                                                              calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday | DaysFlag.Tuesday),
                                                                              stops: TestSchedules.CreateThreeStopSchedule(Time.StartRailDay.AddMinutes(-1)));
            var startsAfterRailDay = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98766",
                                                                             calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday | DaysFlag.Tuesday),
                                                                             stops: TestSchedules.CreateThreeStopSchedule(Time.StartRailDay.AddMinutes(1)));

            var found = timetable.GetSchedulesByToc("VT", MondayAugust12, Time.StartRailDay);

            var startDaySchedule = found.services.Single(s => s.Details == startsRailDay);

            Assert.Equal(MondayAugust12, startDaySchedule.On);

            var startAfterDaySchedule = found.services.Single(s => s.Details == startsAfterRailDay);

            Assert.Equal(MondayAugust12, startAfterDaySchedule.On);

            var startBeforeDaySchedule = found.services.Single(s => s.Details == startsBeforeRailDay);

            Assert.Equal(TuesdayAugust13, startBeforeDaySchedule.On);

            Assert.Equal(4, found.services.Length);
        }
Exemplo n.º 2
0
        public void ThrowsExceptionWhenDateIndicatorNotSet()
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: AssociationDateIndicator.None);

            Assert.Throws <ArgumentException>(() => association.ResolveDate(MondayAugust12, AssociatedUid));
        }
Exemplo n.º 3
0
        public void DoesNotThrowExceptionIsMain()
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: AssociationDateIndicator.None);

            Assert.True(association.AppliesOn(MondayAugust12, MainUid));
        }
Exemplo n.º 4
0
        public void GetsAssociationAppliesOnDate(DateTime date, string timetableUID, AssociationDateIndicator dateIndicator, bool expected)
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: dateIndicator);

            Assert.Equal(expected, association.AppliesOn(date, timetableUID));
        }
Exemplo n.º 5
0
        public void GatherAllReturnsEmptyWhenNoSchedules()
        {
            var(schedule, expected) = CreateSchedule(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.None));

            var services = schedule.AllServices(Aug5, GatherFilterFactory.NoFilter, Time.Midnight);

            Assert.Empty(services);
        }
Exemplo n.º 6
0
        public void GetsScheduleRunningOnDate()
        {
            var schedule =
                TestSchedules.CreateSchedule(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            Assert.True(schedule.RunsOn(MondayAugust12));
            Assert.False(schedule.RunsOn(MondayAugust12.AddDays(1)));
        }
        public void TryFindScheduleReturnsFalseWhenNoSchedulesRunOnDate()
        {
            var schedule = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service  = schedule.Service;

            Assert.False(service.TryResolveOn(MondayAugust12, out var found));
            Assert.Null(found);
        }
        public void TryFindScheduleOnRunningOnDate()
        {
            var schedule = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service  = schedule.Service;

            Assert.True(service.TryResolveOn(MondayAugust12.AddDays(2), out var found));
            Assert.Equal(schedule, found.Details);
        }
Exemplo n.º 9
0
        public void ServiceIsStopsService()
        {
            var schedule = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service  = schedule.Service;

            var serviceTime = new DepartureServiceTime(schedule.Locations.First() as IDeparture);

            Assert.Equal(service, serviceTime.Service);
        }
Exemplo n.º 10
0
        public void ResolveDateWhenCancelledWhenNoDateIndicator(string timetableUid)
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                indicator: StpIndicator.Cancelled,
                dateIndicator: AssociationDateIndicator.None);

            Assert.Equal(MondayAugust12, association.ResolveDate(MondayAugust12, timetableUid));
        }
        public void NullReturnedIfNoSchedulesRunOnDate()
        {
            var schedule  = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service   = schedule.Service;
            var schedule2 = TestSchedules.CreateSchedule(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Thursday), service: service);

            service.TryResolveOn(MondayAugust12, out var found);
            Assert.Null(found);
        }
        public void TryFindScheduleStopReturnsFalseWhenNoStopAtTime()
        {
            var schedule = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service  = schedule.Service;
            var find     = CreateFindSpec(TestSchedules.Ten, MondayAugust12.AddDays(2));

            Assert.False(service.TryFindScheduledStop(find, out var found));
            Assert.Null(found);
        }
        public void TryFindScheduleStopOnRunningOnDate()
        {
            var schedule = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service  = schedule.Service;
            var find     = CreateFindSpec(TestSchedules.TenSixteen, MondayAugust12.AddDays(2));

            Assert.True(service.TryFindScheduledStop(find, out var found));
            Assert.Equal(schedule, found.Service.Details);
        }
Exemplo n.º 14
0
        public void ScheduleNotFoundBasedUponRetailServiceId()
        {
            var timetable = CreateTimetable();

            TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var found = timetable.GetScheduleByRetailServiceId("VT999900", MondayAugust12);

            Assert.Empty(found.services);
            Assert.Equal(LookupStatus.ServiceNotFound, found.status);
        }
        public void HighIndicatorsTakePriorityOverLow(StpIndicator lowIndicator, StpIndicator highIndicator)
        {
            var low     = TestSchedules.CreateScheduleWithService(indicator: lowIndicator, calendar: TestSchedules.EverydayAugust2019);
            var service = low.Service;
            var high    = TestSchedules.CreateSchedule(indicator: highIndicator, calendar: TestSchedules.EverydayAugust2019, service: service);

            TestSchedules.CreateSchedule(indicator: lowIndicator, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday), service: service);

            service.TryResolveOn(MondayAugust12, out var found);
            Assert.Equal(high, found.Details);
        }
Exemplo n.º 16
0
        public void GetScheduleByRetailServiceIdInvalidRetailServiceId(string retailServiceId)
        {
            var timetable = CreateTimetable();

            TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var found = timetable.GetScheduleByRetailServiceId(retailServiceId, MondayAugust12);

            Assert.Empty(found.services);
            Assert.Equal(LookupStatus.InvalidRetailServiceId, found.status);
        }
Exemplo n.º 17
0
        public void ScheduleNotFound()
        {
            var timetable = CreateTimetable();

            TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var found = timetable.GetScheduleByTimetableUid("Z98765", MondayAugust12);

            Assert.Null(found.service);
            Assert.Equal(LookupStatus.ServiceNotFound, found.status);
        }
Exemplo n.º 18
0
        public void ScheduleNotFoundBasedUponRetailServiceIdWhenHaveTwoDifferentRetailServiceIdsForSameService()
        {
            var timetable = CreateTimetable();

            TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday), retailServiceId: "VT999900");

            var found = timetable.GetScheduleByRetailServiceId("VT999900", MondayAugust12);

            Assert.Empty(found.services);
            Assert.Equal(LookupStatus.NoScheduleOnDate, found.status);
        }
        public void GetsScheduleRunningOnDate()
        {
            var schedule = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Wednesday));
            var service  = schedule.Service;

            var schedule2 = TestSchedules.CreateSchedule(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Thursday), service: service);

            service.TryResolveOn(MondayAugust12.AddDays(2), out var found);
            Assert.Equal(schedule, found.Details);

            service.TryResolveOn(MondayAugust12.AddDays(3), out found);
            Assert.Equal(schedule2, found.Details);
        }
Exemplo n.º 20
0
        public void CanAddSchedulesWithSameStpIndicator()
        {
            var service   = new CifService("X12345", Substitute.For <ILogger>());
            var permanent = TestSchedules.CreateSchedule(indicator: StpIndicator.Permanent,
                                                         calendar: TestSchedules.EverydayAugust2019);
            var permanent2 = TestSchedules.CreateSchedule(indicator: StpIndicator.Permanent,
                                                          calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            permanent.AddToService(service);
            permanent2.AddToService(service);

            Assert.Same(service, permanent.Service);
            Assert.Same(service, permanent2.Service);
        }
        public void HandleBadAssociationWhereOtherServiceDoesNotResolve()
        {
            var main  = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var other = TestSchedules.CreateScheduleWithService("Z98765", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var association = TestAssociations.CreateAssociationWithServices(
                mainService: main.Service,
                associatedService: other.Service,
                dateIndicator: AssociationDateIndicator.NextDay);    // Next day means other schedule will not resolve

            var associations = main.Service.AsDynamic()._associations.RealObject as AssociationDictionary;

            var resolved = associations.Resolve(main.TimetableUid, MondayAugust12, main.RetailServiceId);

            Assert.Empty(resolved);
        }
        public void HandleWhenAssociationHasNoServiceDoesNotResolve()
        {
            var main  = TestSchedules.CreateScheduleWithService(calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var other = TestSchedules.CreateScheduleWithService("Z98765", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var association = TestAssociations.CreateAssociationWithServices(
                mainService: main.Service,
                associatedService: other.Service);             // Next day means other schedule will not resolve

            association.Associated.AsDynamic().Service = null; // Force the service to be null which should nt happen but can do

            var associations = main.Service.AsDynamic()._associations.RealObject as AssociationDictionary;

            var resolved = associations.Resolve(main.TimetableUid, MondayAugust12, main.RetailServiceId);

            Assert.Empty(resolved);
        }
        public void AssociationsResolvedWithAssociationOnPreviousDayWhenOnAssociatedService()
        {
            var mainCalendar = TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday);
            var mainSchedule = TestSchedules.CreateScheduleWithService(calendar: mainCalendar);
            var mainService  = mainSchedule.Service;

            var associationCalendar = TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday);
            var associationSchedule = TestSchedules.CreateScheduleWithService("Z98765", calendar: associationCalendar);
            var associationService  = associationSchedule.Service;

            var association = TestAssociations.CreateAssociationWithServices(
                mainService: mainService,
                associatedService: associationService,
                dateIndicator: AssociationDateIndicator.NextDay);

            associationService.TryResolveOn(TuesdayAugust13, out var found);
            Assert.IsType <ResolvedServiceWithAssociations>(found);
        }
        public void CanAddAssociationsWithSameStpIndicator()
        {
            var service    = TestSchedules.CreateScheduleWithService().Service;
            var permanent  = TestAssociations.CreateAssociation(indicator: StpIndicator.Permanent);
            var permanent2 = TestAssociations.CreateAssociation(indicator: StpIndicator.Permanent, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            service.AddAssociation(permanent, true);
            service.AddAssociation(permanent2, true);

            Assert.True(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.Single(associations);
            Assert.Equal(2, associations["A98765"].Count);
        }
Exemplo n.º 25
0
        public void ScheduleCancelledOnDate()
        {
            var timetable = CreateTimetable();
            var schedule  = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Weekdays));
            var schedule2 = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday));

            schedule2.StpIndicator = StpIndicator.Cancelled;

            var found = timetable.GetScheduleByTimetableUid("X12345", MondayAugust12);

            Assert.False(found.service.IsCancelled);
            Assert.Equal(schedule, found.service.Details);
            Assert.Equal(MondayAugust12, found.service.On);

            found = timetable.GetScheduleByTimetableUid("X12345", TuesdayAugust13);
            Assert.Equal(LookupStatus.Success, found.status);
            Assert.True(found.service.IsCancelled);
            Assert.Equal(TuesdayAugust13, found.service.On);
            Assert.Equal(schedule, found.service.Details);
        }
Exemplo n.º 26
0
        public void ScheduleNotRunningOnDate()
        {
            var timetable = CreateTimetable();
            var schedule  = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var schedule2 = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday));

            var found = timetable.GetScheduleByTimetableUid("X12345", MondayAugust12.AddDays(2));

            Assert.Null(found.service);
            Assert.Equal(LookupStatus.NoScheduleOnDate, found.status);
        }
Exemplo n.º 27
0
        public void GetsScheduleRunningOnDate()
        {
            var timetable = CreateTimetable();

            var schedule  = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var schedule2 = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday));

            var found = timetable.GetScheduleByTimetableUid("X12345", MondayAugust12);

            Assert.Equal(schedule, found.service.Details);
            Assert.Equal(MondayAugust12, found.service.On);

            found = timetable.GetScheduleByTimetableUid("X12345", TuesdayAugust13);
            Assert.Equal(schedule2, found.service.Details);
            Assert.Equal(TuesdayAugust13, found.service.On);
        }
Exemplo n.º 28
0
        public void GetsTocSchedulesHandlesIndividualDodgyServicesAndLogsAsWarning()
        {
            var logger    = Substitute.For <ILogger>();
            var timetable = CreateTimetable(logger);

            var schedule = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var start    = TestSchedules.Ten;
            var stops    = new ScheduleLocation[]
            {
                TestScheduleLocations.CreatePass(TestStations.Vauxhall, start.AddMinutes(10)),
                TestScheduleLocations.CreatePass(TestStations.ClaphamJunction, start.AddMinutes(20)),
                TestScheduleLocations.CreatePass(TestStations.Wimbledon, start.AddMinutes(20)),
            };
            var dodgySchedule = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "D11111", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday), stops: stops);
            var schedule3     = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98765", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var found     = timetable.GetSchedulesByToc("VT", MondayAugust12, Time.Midnight);
            var schedules = found.services.Select(s => s.Details).ToArray();

            Assert.Contains <ISchedule>(schedule, schedules);
            Assert.Contains <ISchedule>(schedule3, schedules);
            Assert.All(found.services, s => { Assert.Equal(MondayAugust12, s.On); });

            logger.Received().Warning(Arg.Any <InvalidOperationException>(), Arg.Any <string>(), Arg.Any <IService>());
        }
Exemplo n.º 29
0
        public void GetsTocSchedulesHandlesIndividualServiceError()
        {
            var logger    = Substitute.For <ILogger>();
            var timetable = CreateTimetable(logger);

            var schedule  = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var schedule2 = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "CORRUPT", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var schedule3 = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98765", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var data = timetable.AsDynamic()._timetableUidMap.RealObject as Dictionary <string, IService>;

            data["CORRUPT"] = null;    // Force an error

            var found     = timetable.GetSchedulesByToc("VT", MondayAugust12, Time.Midnight);
            var schedules = found.services.Select(s => s.Details).ToArray();

            Assert.Contains <ISchedule>(schedule, schedules);
            Assert.Contains <ISchedule>(schedule3, schedules);
            Assert.All(found.services, s => { Assert.Equal(MondayAugust12, s.On); });

            logger.Received().Error(Arg.Any <Exception>(), Arg.Any <string>(), Arg.Any <IService>());
        }
Exemplo n.º 30
0
        public void TocScheduleNotFound()
        {
            var timetable = CreateTimetable();

            var schedule  = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));
            var schedule2 = TestSchedules.CreateScheduleInTimetable(timetable, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Tuesday));
            var schedule3 = TestSchedules.CreateScheduleInTimetable(timetable, timetableId: "X98765", calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            var found = timetable.GetSchedulesByToc("GR", MondayAugust12, Time.Midnight);

            Assert.Empty(found.services);
            Assert.Equal(LookupStatus.ServiceNotFound, found.status);
        }