Пример #1
0
        public void DoNotFindStopWheenDoesNotStopAtStation()
        {
            var schedule = TestSchedules.CreateSchedule();
            var find     = CreateFindSpec(TestStations.Woking, TestSchedules.TenThirty);

            Assert.False(schedule.TryFindStop(find, out var stop));
        }
Пример #2
0
        public void DoNotFindStopWhenTimeDifferent()
        {
            var schedule = TestSchedules.CreateSchedule();
            var find     = CreateFindSpec(TestStations.Surbiton, TestSchedules.TenThirty);

            Assert.False(schedule.TryFindStop(find, out var stop));
        }
Пример #3
0
        public void ShortRetailServiceId(string retailServiceId, string expected)
        {
            var schedule = TestSchedules.CreateSchedule();

            schedule.RetailServiceId = retailServiceId;
            Assert.Equal(expected, schedule.NrsRetailServiceId);
        }
Пример #4
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 StartsBeforeSkipsCancelledServices()
        {
            var service = CreateServiceStartingAt(Time.StartRailDay.AddMinutes(-1)).Service;

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

            Assert.True(service.StartsBefore(Time.StartRailDay));
        }
Пример #6
0
        public void CannotAddScheduleWithDifferentTimetableUid()
        {
            var schedule = TestSchedules.CreateSchedule(timetableId: "A00002", indicator: StpIndicator.Permanent);

            var service = new CifService("A00001", Substitute.For <ILogger>());

            Assert.Throws <ArgumentException>(() => schedule.AddToService(service));
        }
Пример #7
0
        public void HasRetailServiceIdChecksUsingTheShortRetailServiceId(string retailsServiceId, string testId,
                                                                         bool expected)
        {
            var schedule = TestSchedules.CreateSchedule();

            schedule.RetailServiceId = retailsServiceId;
            Assert.Equal(expected, schedule.HasRetailServiceId(testId));
        }
Пример #8
0
        private static ScheduleStop CreateStop(string timetableUid)
        {
            var service  = new CifService(timetableUid, Substitute.For <ILogger>());
            var schedule = TestSchedules.CreateSchedule(timetableId: timetableUid, service: service);
            var stop     = schedule.Destination;

            return(stop);
        }
Пример #9
0
        public void FindStopIsIndependentOfWhetherCancelled(bool isCancelled)
        {
            var service = new ResolvedService(TestSchedules.CreateSchedule(), DateTime.Today, isCancelled);

            var find = CreateFindSpec(TestSchedules.Ten);

            Assert.True(service.TryFindStop(find, out var stop));
            Assert.NotNull(stop);
        }
Пример #10
0
        public void DoNotFindStop()
        {
            var service = new ResolvedService(TestSchedules.CreateSchedule(), DateTime.Today, false);

            var find = CreateFindSpec(TestSchedules.TenThirty);

            Assert.False(service.TryFindStop(find, out var stop));
            Assert.Null(stop);
        }
        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);
        }
Пример #12
0
        public void ParentSetToService()
        {
            var service  = new CifService("X12345", Substitute.For <ILogger>());
            var schedule = TestSchedules.CreateSchedule();

            schedule.AddToService(service);

            Assert.Same(service, schedule.Service);
        }
        public void CannotAddSameSchedulesTwice()
        {
            var service   = new CifService("X12345", Substitute.For <ILogger>());
            var permanent = TestSchedules.CreateSchedule(indicator: StpIndicator.Permanent, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            service.Add(permanent);
            var ex = Assert.Throws <ArgumentException>(() => service.Add(permanent));

            Assert.StartsWith("Schedule already added", ex.Message);
        }
        public void CancelledScheduleReturned(StpIndicator lowIndicator)
        {
            var baseSchedule = TestSchedules.CreateScheduleWithService(indicator: lowIndicator, calendar: TestSchedules.EverydayAugust2019);
            var service      = baseSchedule.Service;

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

            service.TryResolveOn(MondayAugust12, out var found);
            Assert.True(found.IsCancelled);
            Assert.Equal(baseSchedule, found.Details);
        }
Пример #15
0
        public void DoesNotAddTocIfDoesNotStop()
        {
            var test     = TestStations.Waterloo;
            var service  = new CifService("X12345", Substitute.For <ILogger>());
            var schedule = TestSchedules.CreateSchedule(timetableId: "X12345", service: service, stops: TestSchedules.CreateThreeStopSchedule(TestSchedules.Ten));
            var stop     = schedule.Locations[2]; // Pass

            test.Add(stop);

            Assert.Empty(test.TocServices);
        }
        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);
        }
        public void LocationHasOnlyOneEntryForMultipleSchedules()
        {
            var permanent = TestSchedules.CreateScheduleWithService();
            var overlay   = TestSchedules.CreateSchedule(indicator: StpIndicator.Override, service: permanent.Service);

            var destination = permanent.Locations.Last().Station.Timetable;

            var arrivals = destination.GetArrivalTimes();
            var services = arrivals.GetServices(TestSchedules.TenThirty);

            Assert.Single(services);
        }
        public void MultipleScheduleRecordsWithCancelReturnsHighestPriority()
        {
            var baseSchedule = TestSchedules.CreateScheduleWithService(indicator: StpIndicator.Permanent, calendar: TestSchedules.EverydayAugust2019);
            var service      = baseSchedule.Service;

            TestSchedules.CreateSchedule(indicator: StpIndicator.Cancelled, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday), service: service);
            var overrideSchedule = TestSchedules.CreateSchedule(indicator: StpIndicator.Override, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday), service: service);

            service.TryResolveOn(MondayAugust12, out var found);
            Assert.True(found.IsCancelled);
            Assert.Equal(overrideSchedule, found.Details);
        }
Пример #19
0
        public void InDepartures(Station location, bool expectedContains)
        {
            var schedule = TestSchedules.CreateSchedule();

            if (expectedContains)
            {
                Assert.Contains <Station>(location, schedule.Departures.Select(d => d.Station));
            }
            else
            {
                Assert.DoesNotContain <Station>(location, schedule.Departures.Select(d => d.Station));
            }
        }
Пример #20
0
        public void InArrivals(Station location, bool expectedContains)
        {
            var schedule = TestSchedules.CreateSchedule();

            if (expectedContains)
            {
                Assert.Contains <Station>(location, schedule.Arrivals.Select(a => a.Station));
            }
            else
            {
                Assert.DoesNotContain <Station>(location, schedule.Arrivals.Select(a => a.Station));
            }
        }
Пример #21
0
        public void GetStopFindsStop(Location location, int sequence, bool expectedException)
        {
            var schedule = TestSchedules.CreateSchedule();

            if (expectedException)
            {
                Assert.Throws <ArgumentException>(() => schedule.GetStop(location, sequence));
            }
            else
            {
                Assert.NotNull(schedule.GetStop(location, sequence));
            }
        }
        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));

            service.Add(permanent);
            service.Add(permanent2);

            var schedules = service.GetSchedules();

            Assert.Equal(2, schedules.Count);
        }
        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);
        }
        public void CanAddSchedulesWithDifferentStpIndicator()
        {
            var service   = new CifService("X12345", Substitute.For <ILogger>());
            var permanent = TestSchedules.CreateSchedule(indicator: StpIndicator.Permanent, calendar: TestSchedules.EverydayAugust2019);
            var overlay   = TestSchedules.CreateSchedule(indicator: StpIndicator.Override, calendar: TestSchedules.EverydayAugust2019);

            service.Add(permanent);
            service.Add(overlay);

            var schedules = service.GetSchedules();

            Assert.Equal(2, schedules.Count);
        }
Пример #25
0
        public void CanAddSchedulesWithDifferentStpIndicator()
        {
            var service   = new CifService("X12345", Substitute.For <ILogger>());
            var permanent = TestSchedules.CreateSchedule(indicator: StpIndicator.Permanent,
                                                         calendar: TestSchedules.EverydayAugust2019);
            var overlay = TestSchedules.CreateSchedule(indicator: StpIndicator.Override,
                                                       calendar: TestSchedules.EverydayAugust2019);

            permanent.AddToService(service);
            overlay.AddToService(service);

            Assert.Same(service, permanent.Service);
            Assert.Same(service, overlay.Service);
        }
Пример #26
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);
        }
Пример #27
0
        public void AddScheduleLocationAddsTocIfNotAlreadyAdded()
        {
            var test = TestStations.Waterloo;
            var stop = CreateStop("X12345");

            test.Add(stop);

            var service  = new CifService("X98765", Substitute.For <ILogger>());
            var schedule = TestSchedules.CreateSchedule("X98765", retailServiceId: "SW123400");
            var stop2    = schedule.Destination;

            test.Add(stop2);

            Assert.Equal(2, test.TocServices.Count);
        }
        public void TryGetScheduleMultipleSchedulesDifferentStp(StpIndicator indicator, bool expectedFound, bool isPermanent)
        {
            var service   = new CifService("X12345", Substitute.For <ILogger>());
            var permanent = TestSchedules.CreateSchedule(indicator: StpIndicator.Permanent, calendar: TestSchedules.EverydayAugust2019);
            var overlay   = TestSchedules.CreateSchedule(indicator: StpIndicator.Override, calendar: TestSchedules.EverydayAugust2019);

            service.Add(permanent);
            service.Add(overlay);

            Assert.Equal(expectedFound, service.TryGetSchedule((indicator, TestSchedules.EverydayAugust2019), out var schedule));
            if (expectedFound)
            {
                var expected = isPermanent ? permanent : overlay;
                Assert.Equal(expected, schedule);
            }
        }
        public void TryGetScheduleMultipleSchedulesDifferentCalendar(ICalendar calendar, bool expectedFound, bool isFirst)
        {
            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));

            service.Add(permanent);
            service.Add(permanent2);

            Assert.Equal(expectedFound, service.TryGetSchedule((StpIndicator.Permanent, calendar), out var schedule));
            if (expectedFound)
            {
                var expected = isFirst ? permanent : permanent2;
                Assert.Equal(expected, schedule);
            }
        }
Пример #30
0
        public void FindStop(Station station, Time time, TimesToUse arrivalOrDeparture)
        {
            var schedule = TestSchedules.CreateSchedule();
            var find     = CreateFindSpec(station, time, arrivalOrDeparture);

            Assert.True(schedule.TryFindStop(find, out var stop));
            Assert.Equal(station, stop.Station);

            if (find.UseArrival)
            {
                IArrival arrival = (IArrival)stop;
                Assert.Equal(time, arrival.Time);
            }
            else
            {
                IDeparture departure = (IDeparture)stop;
                Assert.Equal(time, departure.Time);
            }
        }