Ejemplo n.º 1
0
        public void AddToServiceThrowsExceptionWhenNotMatchingId(bool isMain)
        {
            var schedule    = TestSchedules.CreateScheduleWithService("Q11111");
            var association = TestAssociations.CreateAssociation();

            var ex = Assert.Throws <ArgumentException>(() => association.SetService(schedule.Service, isMain));
        }
Ejemplo n.º 2
0
        public void NotConsistentLocationWhenCannotFindTheStop(bool isMain)
        {
            var association = TestAssociations.CreateAssociation(location: TestLocations.Weybridge);
            var schedule    = TestSchedules.CreateScheduleWithService();

            Assert.False(association.HasConsistentLocation(schedule, isMain));
        }
        public void AddSameAssociationWithDifferentLocationsResolveToCorrectForAssociated(string activities, AssociationCategory joinSplit, bool expectedHasAssociation)
        {
            Test(TestLocations.CLPHMJN, TestLocations.Woking);
            Test(TestLocations.Woking, TestLocations.CLPHMJN);

            void Test(Location location1, Location location2)
            {
                var stops        = CreateAssociateStopsSettingClaphamActivities(joinSplit, activities);
                var service      = TestSchedules.CreateScheduleWithService("A12345", stops: stops).Service;
                var association1 = TestAssociations.CreateAssociation(mainUid: "A67890", associatedUid: "A12345",
                                                                      category: joinSplit, location: location1);
                var association2 = TestAssociations.CreateAssociation(mainUid: "A67890", associatedUid: "A12345",
                                                                      category: joinSplit, location: location2);

                service.AddAssociation(association1, false);
                service.AddAssociation(association2, false);

                Assert.Equal(expectedHasAssociation, service.HasAssociations());
                if (expectedHasAssociation)
                {
                    var associations = service.GetAssociations()["A67890"];
                    Assert.Single(associations);
                    Assert.Equal(TestLocations.CLPHMJN, associations.Single().Value.AtLocation);
                }
            }
        }
Ejemplo n.º 4
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>());
        }
Ejemplo n.º 5
0
        public void ShortRetailServiceId(string retailServiceId, string expected)
        {
            var schedule = TestSchedules.CreateSchedule();

            schedule.RetailServiceId = retailServiceId;
            Assert.Equal(expected, schedule.NrsRetailServiceId);
        }
        public void LocationHasMultipleServicesForWhenOnSameTime()
        {
            var surbiton = TestStations.Surbiton;
            var waterloo = TestStations.Waterloo;

            var locations1 = new[]
            {
                (ScheduleLocation)TestScheduleLocations.CreateOrigin(surbiton, TestSchedules.Ten),
                TestScheduleLocations.CreateDestination(waterloo, TestSchedules.TenThirty)
            };
            var service1 = TestSchedules.CreateScheduleWithService(timetableId: "A00001", stops: locations1);

            var locations2 = new[]
            {
                (ScheduleLocation)TestScheduleLocations.CreateOrigin(surbiton, TestSchedules.Ten),
                TestScheduleLocations.CreateDestination(waterloo, TestSchedules.TenThirty)
            };
            var service2 = TestSchedules.CreateScheduleWithService(timetableId: "A00002", stops: locations2);

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

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

            Assert.Equal(2, services.Length);
        }
Ejemplo n.º 7
0
        private ScheduleLocation[] CreateMainStops(Time departs)
        {
            var mainStops = TestSchedules.CreateFourStopSchedule(departs);

            mainStops[3] = TestScheduleLocations.CreateStop(TestStations.Vauxhall, TestSchedules.TenTwenty);    // Make Vauxhall a stop
            return(mainStops);
        }
Ejemplo n.º 8
0
        private ScheduleStop CreateScheduleStop()
        {
            var stop = TestScheduleLocations.CreateStop(TestStations.Surbiton, TestSchedules.Ten);

            TestSchedules.CreateScheduleWithService(stops: new ScheduleLocation[] { stop });
            return(stop);
        }
Ejemplo n.º 9
0
        private static Model.FoundSummaryItem MapResolvedStop(Timetable.CifSchedule schedule = null,
                                                              Timetable.Station at           = null, Time?time = null,
                                                              Timetable.Station from         = null, Timetable.Station to = null)
        {
            schedule = schedule ?? TestSchedules.CreateScheduleWithService();
            at       = at ?? TestStations.Surbiton;
            time     = time ?? TestSchedules.Ten;
            var find = new StopSpecification(at, time.Value, TestDate, TimesToUse.Departures);

            var resolved = new ResolvedService(schedule, TestDate, false);

            resolved.TryFindStop(find, out var stop);
            if (to != null)
            {
                stop.GoesTo(to);
            }
            if (from != null)
            {
                stop.ComesFrom(from);
            }

            var mapper = ToViewProfileConfiguration.CreateMapper();

            return(mapper.Map <Timetable.ResolvedServiceStop, Model.FoundSummaryItem>(stop, opts => opts.Items["On"] = stop.On));
        }
        public static ScheduleLocation[] CreateStopsSettingClaphamActivities(string activities)
        {
            var stops = TestSchedules.CreateFourStopSchedule(TestSchedules.Ten);

            stops[2].Activities = new Activities(activities);
            return(stops);
        }
        public void ToStringReturnsServiceAndStop()
        {
            var service = TestSchedules.CreateService();
            var stop    = new ResolvedServiceStop(service, service.Details.Locations[0]);

            Assert.Equal("X12345 2019-08-12 10:00 SUR-SURBITN", stop.ToString());
        }
        public void OperatorReturnsResolvedServiceOperator()
        {
            var service = TestSchedules.CreateService();
            var stop    = new ResolvedServiceStop(service, service.Details.Locations[0]);

            Assert.Equal("VT", stop.Operator.Code);
        }
Ejemplo n.º 13
0
        public void DoNotFindStopWhenTimeDifferent()
        {
            var schedule = TestSchedules.CreateSchedule();
            var find     = CreateFindSpec(TestStations.Surbiton, TestSchedules.TenThirty);

            Assert.False(schedule.TryFindStop(find, out var stop));
        }
Ejemplo n.º 14
0
        public void AddToServiceThrowsExceptionWhenNotMatchingId(string uid, bool success)
        {
            var schedule           = TestSchedules.CreateScheduleWithService(uid);
            var associationService = TestAssociations.CreateAssociation().Main;

            Assert.Equal(success, associationService.TrySetService(schedule.Service));
        }
        public void OnReturnsResolvedServiceOn()
        {
            var service = TestSchedules.CreateService();
            var stop    = new ResolvedServiceStop(service, service.Details.Locations[0]);

            Assert.Equal(TestDate, stop.On);
        }
        private ScheduleLocation[] CreateMainStops()
        {
            var mainStops = TestSchedules.CreateThreeStopSchedule(TestSchedules.Ten);

            mainStops[2] = TestScheduleLocations.CreateStop(TestStations.Vauxhall, TestSchedules.TenTwenty);    // Make Vauxhall a stop
            return(mainStops);
        }
Ejemplo n.º 17
0
        public void DoNotFindStopWheenDoesNotStopAtStation()
        {
            var schedule = TestSchedules.CreateSchedule();
            var find     = CreateFindSpec(TestStations.Woking, TestSchedules.TenThirty);

            Assert.False(schedule.TryFindStop(find, out var stop));
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public void HasRetailServiceIdChecksUsingTheShortRetailServiceId(string retailsServiceId, string testId,
                                                                         bool expected)
        {
            var schedule = TestSchedules.CreateSchedule();

            schedule.RetailServiceId = retailsServiceId;
            Assert.Equal(expected, schedule.HasRetailServiceId(testId));
        }
Ejemplo n.º 21
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)));
        }
Ejemplo n.º 22
0
        public void ConvertCreatesNewToc()
        {
            var schedule = TestSchedules.CreateScheduleExtraDetails(toc: "SW");

            var output = MapSchedule(schedule);

            Assert.Equal("SW", output.Operator.Code);
        }
Ejemplo n.º 23
0
        public void ConvertUsesExistingToc()
        {
            var schedule = TestSchedules.CreateScheduleExtraDetails(toc: "VT");

            var output = MapSchedule(schedule);

            Assert.Same(VT, output.Operator);
        }
Ejemplo n.º 24
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);
        }
        public void NoAssociationsReturnsResolvedService()
        {
            var schedule = TestSchedules.CreateScheduleWithService();
            var service  = schedule.Service;

            service.TryResolveOn(MondayAugust12, out var found);
            Assert.IsType <ResolvedService>(found);
        }
Ejemplo n.º 26
0
        public void DoesNotThrowExceptionIsMain()
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: AssociationDateIndicator.None);

            Assert.True(association.AppliesOn(MondayAugust12, MainUid));
        }
Ejemplo n.º 27
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));
        }
Ejemplo n.º 28
0
        private ScheduleStop CreateScheduleStop(Time time, string timetableId = "X12345", ICalendar calendar = null)
        {
            calendar = calendar ?? TestSchedules.EverydayAugust2019;
            var stop = TestScheduleLocations.CreateStop(TestStations.Surbiton, time);

            TestSchedules.CreateScheduleWithService(timetableId: timetableId, calendar: calendar, stops: new ScheduleLocation[] { stop });
            return(stop);
        }
Ejemplo n.º 29
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));
        }
Ejemplo n.º 30
0
        public void ThrowsExceptionWhenDateIndicatorNotSet()
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: AssociationDateIndicator.None);

            Assert.Throws <ArgumentException>(() => association.ResolveDate(MondayAugust12, AssociatedUid));
        }