Esempio n. 1
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 void GoesToWorksWithSplitsWhereMainStartsAtSplitPoint()
        {
            //  Start at Clapham
            var mainStops = CreateMainStops();

            mainStops = new [] {
                TestScheduleLocations.CreateOrigin(TestStations.ClaphamJunction, TestSchedules.TenTen),
                mainStops[2],
                mainStops[3]
            };
            var association = CreateSplitServices(mainStops);

            var at    = new StopSpecification(TestStations.ClaphamJunction, TestSchedules.TenTen, MondayAugust12, TimesToUse.Departures);
            var found = association.Main.Service.TryFindScheduledStop(at, out var mainStop);

            // Both trains start at Clapham so actually whole journey on split
            // Using main stop fails
            Assert.True(mainStop.GoesTo(TestStations.Woking));
            Assert.NotNull(mainStop.FoundToStop);
            Assert.True(mainStop.Association.IsIncluded);

            at    = new StopSpecification(TestStations.ClaphamJunction, TestSchedules.TenTwentyFive, MondayAugust12, TimesToUse.Departures);
            found = association.Associated.Service.TryFindScheduledStop(at, out var associationStop);

            // Using Association works
            Assert.True(associationStop.GoesTo(TestStations.Woking));
            Assert.NotNull(associationStop.FoundToStop);
            Assert.False(associationStop.Association.IsIncluded);
        }
Esempio n. 3
0
        public static ResolvedServiceStop CreateResolvedArrivalStop(
            string timetableId       = "X12345",
            StpIndicator indicator   = StpIndicator.Permanent,
            ICalendar calendar       = null,
            ScheduleLocation[] stops = null,
            int id                 = 1,
            CifService service     = null,
            string retailServiceId = null,
            DateTime on            = default(DateTime),
            bool isCancelled       = false,
            Station atLocation     = null,
            Time when              = default(Time))
        {
            on = on == default(DateTime) ? MondayAugust12 : on;
            var schedule = CreateSchedule(timetableId, indicator, calendar, stops, service, retailServiceId);
            var resolved = new ResolvedService(schedule, on, isCancelled);

            var destination = schedule.Locations.Last() as ScheduleStop;

            atLocation = atLocation ?? destination.Station;
            when       = when.Equals(default(Time)) ? destination.Arrival : when;
            var find = new StopSpecification(atLocation, when, on, TimesToUse.Arrivals);

            resolved.TryFindStop(find, out var stop);
            return(stop);
        }
        public void AssociatedGoesToAtJoinIsAssociatedStop()
        {
            var association = CreateJoinServices();
            var woking      = new StopSpecification(TestStations.Woking, TestSchedules.NineForty, MondayAugust12, TimesToUse.Departures);
            var found       = association.Associated.Service.TryFindScheduledStop(woking, out var stop);

            Assert.True(stop.GoesTo(TestStations.ClaphamJunction));

            Assert.Equal(TestSchedules.TenTen, (stop.FoundToStop.Stop as ScheduleStop).Arrival);
        }
        public void MainGoesToAtJoinIsMainStop()
        {
            var association = CreateJoinServices();
            var surbiton    = new StopSpecification(TestStations.Surbiton, TestSchedules.Ten, MondayAugust12, TimesToUse.Departures);
            var found       = association.Main.Service.TryFindScheduledStop(surbiton, out var stop);

            Assert.True(stop.GoesTo(TestStations.ClaphamJunction));

            Assert.Equal(TestSchedules.TenFifteen, (stop.FoundToStop.Stop as ScheduleStop).Arrival);
        }
Esempio n. 6
0
        public void AssociatedComesFromAtSplitIsAssociatedStop()
        {
            var association = CreateSplitServices();
            var woking      = new StopSpecification(TestStations.Woking, TestSchedules.TenFiftyFive, MondayAugust12, TimesToUse.Arrivals);
            var found       = association.Associated.Service.TryFindScheduledStop(woking, out var stop);

            Assert.True(stop.ComesFrom(TestStations.ClaphamJunction));

            Assert.Equal(TestSchedules.TenTwentyFive, (stop.FoundFromStop.Stop as ScheduleStop).Departure);
        }
Esempio n. 7
0
        public void MainComesFromAtSplitIsMainStop()
        {
            var association = CreateSplitServices();
            var waterloo    = new StopSpecification(TestStations.Waterloo, TestSchedules.TenThirty, MondayAugust12, TimesToUse.Arrivals);
            var found       = association.Main.Service.TryFindScheduledStop(waterloo, out var stop);

            Assert.True(stop.ComesFrom(TestStations.ClaphamJunction));

            Assert.Equal(TestSchedules.TenFifteen, (stop.FoundFromStop.Stop as ScheduleStop).Arrival);
        }
Esempio n. 8
0
        public void MapAssociation()
        {
            var mapper   = ToViewProfileConfiguration.CreateMapper();
            var resolved = TestSchedules.CreateServiceWithAssociation();
            var find     = new StopSpecification(TestStations.Surbiton, TestSchedules.Ten, TestDate, TimesToUse.Departures);

            resolved.TryFindStop(find, out var stop);

            var item = mapper.Map <Timetable.ResolvedServiceStop, Model.FoundSummaryItem>(stop, opts => opts.Items["On"] = stop.On);

            Assert.NotEmpty(item.Service.Associations);
            Assert.False(item.Association.IsIncluded);
        }
Esempio n. 9
0
        public void DoNotUseCancelledAssociations()
        {
            var association          = CreateJoinServices();
            var cancelledAssociation = TestAssociations.CreateAssociationWithServices(
                association.Main.Service as CifService,
                association.Associated.Service as CifService,
                StpIndicator.Cancelled);

            var waterloo = new StopSpecification(TestStations.Waterloo, TestSchedules.TenThirty, MondayAugust12, TimesToUse.Arrivals);
            var found    = cancelledAssociation.Main.Service.TryFindScheduledStop(waterloo, out var stop);

            Assert.False(stop.ComesFrom(TestStations.Woking));
            Assert.Null(stop.FoundFromStop);
        }
Esempio n. 10
0
        public static ResolvedServiceStop CreateResolvedDepartureStop(
            ResolvedService service,
            Station atLocation = null,
            Time when          = default(Time))
        {
            var origin = service.Details.Locations.First() as ScheduleStop;

            atLocation = atLocation ?? origin.Station;
            when       = when.Equals(default(Time)) ? origin.Departure : when;
            var find = new StopSpecification(atLocation, when, service.On, TimesToUse.Departures);

            service.TryFindStop(find, out var stop);
            return(stop);
        }
        public void DoNotUseCancelledAssociations()
        {
            var association          = CreateJoinServices();
            var cancelledAssociation = TestAssociations.CreateAssociationWithServices(
                association.Main.Service as CifService,
                association.Associated.Service as CifService,
                StpIndicator.Cancelled);

            var woking = new StopSpecification(TestStations.Woking, TestSchedules.NineForty, MondayAugust12, TimesToUse.Departures);
            var found  = cancelledAssociation.Associated.Service.TryFindScheduledStop(woking, out var stop);

            Assert.False(stop.GoesTo(TestStations.Waterloo));
            Assert.Null(stop.FoundToStop);
        }
Esempio n. 12
0
        public void ComesFromWorksWithSplitsWhereMainStartsAtSplitPoint()
        {
            //  Start at Clapham
            var mainStops = CreateMainStops();

            mainStops = new [] {
                TestScheduleLocations.CreateOrigin(TestStations.ClaphamJunction, TestSchedules.TenTen),
                mainStops[3]
            };
            var association = CreateSplitServices(mainStops);

            var at    = new StopSpecification(TestStations.Woking, TestSchedules.TenFiftyFive, MondayAugust12, TimesToUse.Arrivals);
            var found = association.Associated.Service.TryFindScheduledStop(at, out var stop);

            Assert.True(stop.ComesFrom(TestStations.ClaphamJunction));
            Assert.NotNull(stop.FoundFromStop);
            Assert.False(stop.Association.IsIncluded);
        }
Esempio n. 13
0
        public void ComesFromWorksWithJoinsWhereMainEndsAtJoinPoint()
        {
            //  Ends at Clapham
            var mainStops = CreateMainStops();

            mainStops = new [] {
                mainStops[0],
                TestScheduleLocations.CreateDestination(TestStations.ClaphamJunction, TestSchedules.TenFifteen)
            };
            var association = CreateJoinServices(mainStops);

            var at    = new StopSpecification(TestStations.ClaphamJunction, TestSchedules.TenFifteen, MondayAugust12, TimesToUse.Arrivals);
            var found = association.Main.Service.TryFindScheduledStop(at, out var stop);

            Assert.True(stop.ComesFrom(TestStations.Woking));
            Assert.NotNull(stop.FoundFromStop);
            Assert.True(stop.Association.IsIncluded);
        }
Esempio n. 14
0
        public void ComesFromWorksWithJoinFromAssociated(Station atStation, Time departs, Station @from, bool isFrom, bool involvesAssociation)
        {
            var association = CreateJoinServices();
            var at          = new StopSpecification(atStation, departs, MondayAugust12, TimesToUse.Arrivals);
            var found       = association.Associated.Service.TryFindScheduledStop(at, out var stop);

            if (isFrom)
            {
                Assert.True(stop.ComesFrom(@from));
                Assert.NotNull(stop.FoundFromStop);
            }
            else
            {
                Assert.False(stop.ComesFrom(@from));
                Assert.Null(stop.FoundFromStop);
            }
            Assert.Equal(involvesAssociation, stop.Association.IsIncluded);
        }
        public void GoesToWorksWithJoins(Station station, bool isTo, bool involvesAssociation)
        {
            var association = CreateJoinServices();
            var woking      = new StopSpecification(TestStations.Woking, TestSchedules.NineForty, MondayAugust12, TimesToUse.Departures);
            var found       = association.Associated.Service.TryFindScheduledStop(woking, out var stop);

            if (isTo)
            {
                Assert.True(stop.GoesTo(station));
                Assert.NotNull(stop.FoundToStop);
            }
            else
            {
                Assert.False(stop.GoesTo(station));
                Assert.Null(stop.FoundToStop);
            }
            Assert.Equal(involvesAssociation, stop.Association.IsIncluded);
        }
        public void GoesToWorksWithSplitsFromAssociated(Station from, Time departs, Station to, bool isTo, bool involvesAssociation)
        {
            var association = CreateSplitServices();
            var at          = new StopSpecification(from, departs, MondayAugust12, TimesToUse.Departures);
            var found       = association.Associated.Service.TryFindScheduledStop(at, out var stop);

            if (isTo)
            {
                Assert.True(stop.GoesTo(to));
                Assert.NotNull(stop.FoundToStop);
            }
            else
            {
                Assert.False(stop.GoesTo(to));
                Assert.Null(stop.FoundToStop);
            }
            Assert.Equal(involvesAssociation, stop.Association.IsIncluded);
        }
        public void GoesToWorksWithSplitsWhereMainTerminatesAtSplitPoint()
        {
            //  Stop at Clapham
            var mainStops = CreateMainStops();

            mainStops = new [] {
                mainStops[0],
                TestScheduleLocations.CreateDestination(TestStations.ClaphamJunction, TestSchedules.TenFifteen)
            };
            var association = CreateSplitServices(mainStops);

            var at    = new StopSpecification(TestStations.Surbiton, TestSchedules.Ten, MondayAugust12, TimesToUse.Departures);
            var found = association.Main.Service.TryFindScheduledStop(at, out var stop);

            Assert.True(stop.GoesTo(TestStations.Woking));
            Assert.NotNull(stop.FoundToStop);
            Assert.True(stop.Association.IsIncluded);
        }
Esempio n. 18
0
        public void ComesFromWorksWithSplits(Station station, bool isFrom, bool involvesAssociation)
        {
            var association = CreateSplitServices();
            var woking      = new StopSpecification(TestStations.Woking, TestSchedules.TenFiftyFive, MondayAugust12, TimesToUse.Arrivals);
            var found       = association.Associated.Service.TryFindScheduledStop(woking, out var stop);

            if (isFrom)
            {
                Assert.True(stop.ComesFrom(station));
                Assert.NotNull(stop.FoundFromStop);
            }
            else
            {
                Assert.False(stop.ComesFrom(station));
                Assert.Null(stop.FoundFromStop);
            }
            Assert.Equal(involvesAssociation, stop.Association.IsIncluded);
        }
        public void GoesToWorksWithJoinsWhereMainStopsAtJoinPoint()
        {
            //  Ends at Clapham
            var mainStops = CreateMainStops();

            mainStops = new [] {
                mainStops[0],
                TestScheduleLocations.CreateDestination(TestStations.ClaphamJunction, TestSchedules.TenFifteen)
            };
            var association = CreateJoinServices(mainStops);

            var at    = new StopSpecification(TestStations.Woking, TestSchedules.NineForty, MondayAugust12, TimesToUse.Departures);
            var found = association.Associated.Service.TryFindScheduledStop(at, out var stop);

            // Neither train goes beyond Clapham so actually whole journey on join
            Assert.True(stop.GoesTo(TestStations.ClaphamJunction));
            Assert.NotNull(stop.FoundToStop);
            Assert.False(stop.Association.IsIncluded);
        }
Esempio n. 20
0
        public void MapIncludeAssociation(Station station, bool expected)
        {
            var mapper = ToViewProfileConfiguration.CreateMapper();

            var association = CreateJoinServices();
            var woking      = new StopSpecification(TestStations.Woking, TestSchedules.NineForty, TestDate, TimesToUse.Departures);
            var found       = association.Associated.Service.TryFindScheduledStop(woking, out var stop);

            stop.GoesTo(station);

            var item = mapper.Map <Timetable.ResolvedServiceStop, Model.FoundSummaryItem>(stop, opts => opts.Items["On"] = stop.On);

            Assert.NotEmpty(item.Service.Associations);
            Assert.Equal(expected, item.Association.IsIncluded);
            if (expected)
            {
                Assert.Equal("X12345", item.Association.TimetableUid);
            }
        }
        public void GoesToWorksWithJoinsWhereMainStartsAtJoinPoint()
        {
            //  Starts at Clapham
            var mainStops = CreateMainStops();

            mainStops = new [] {
                TestScheduleLocations.CreateOrigin(TestStations.ClaphamJunction, TestSchedules.TenFifteen),
                mainStops[2],
                mainStops[3]
            };
            var association = CreateJoinServices(mainStops);

            var at    = new StopSpecification(TestStations.Woking, TestSchedules.NineForty, MondayAugust12, TimesToUse.Departures);
            var found = association.Associated.Service.TryFindScheduledStop(at, out var stop);

            Assert.True(stop.GoesTo(TestStations.Waterloo));
            Assert.NotNull(stop.FoundToStop);
            Assert.True(stop.Association.IsIncluded);
        }