public void TryGetScheduleNoSchedules()
        {
            var service = new CifService("X12345", Substitute.For <ILogger>());

            Assert.False(service.TryGetSchedule((StpIndicator.Permanent, TestSchedules.EverydayAugust2019), out var schedule));
            Assert.Null(schedule);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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));
        }
Esempio n. 5
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);
        }
Esempio n. 7
0
        public static CifSchedule CreateScheduleWithService(string timetableId       = "X12345",
                                                            StpIndicator indicator   = StpIndicator.Permanent,
                                                            ICalendar calendar       = null,
                                                            ScheduleLocation[] stops = null,
                                                            CifService service       = null,
                                                            string retailServiceId   = null)
        {
            service = service ?? new CifService(timetableId, Substitute.For <ILogger>());

            return(CreateSchedule(timetableId, indicator, calendar, stops, service, retailServiceId));
        }
Esempio n. 8
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 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 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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public static ResolvedService CreateService(
            string timetableId       = "X12345",
            StpIndicator indicator   = StpIndicator.Permanent,
            ICalendar calendar       = null,
            ScheduleLocation[] stops = null,
            CifService service       = null,
            string retailServiceId   = null,
            DateTime on      = default(DateTime),
            bool isCancelled = false)
        {
            on = on == default(DateTime) ? MondayAugust12 : on;
            var schedule = CreateSchedule(timetableId, indicator, calendar, stops, service, retailServiceId);

            return(new ResolvedService(schedule, on, isCancelled));
        }
Esempio n. 14
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);
            }
        }
Esempio n. 17
0
        public static CifSchedule CreateSchedule(string timetableId             = "X12345",
                                                 StpIndicator indicator         = StpIndicator.Permanent,
                                                 ICalendar calendar             = null,
                                                 ScheduleLocation[] stops       = null,
                                                 CifService service             = null,
                                                 string retailServiceId         = null,
                                                 AccomodationClass sleeperClass = AccomodationClass.None)
        {
            retailServiceId = retailServiceId ?? $"VT{timetableId.Substring(1, 4)}00";

            var schedule = new CifSchedule()
            {
                TimetableUid         = timetableId,
                StpIndicator         = indicator,
                RetailServiceId      = retailServiceId,
                TrainIdentity        = $"9Z{timetableId.Substring(1, 2)}",
                Operator             = new Toc(retailServiceId.Substring(0, 2)),
                Status               = ServiceStatus.PermanentPassenger,
                Category             = ServiceCategory.ExpressPassenger,
                ReservationIndicator = ReservationIndicator.Supported,
                SeatClass            = AccomodationClass.Both,
                SleeperClass         = sleeperClass,
                Calendar             = calendar ?? EverydayAugust2019,
            };

            if (service != null)
            {
                schedule.AddToService(service);
            }

            if (indicator != StpIndicator.Cancelled)
            {
                stops = stops ?? DefaultLocations;
                foreach (var location in stops)
                {
                    location.SetParent(schedule);
                }
            }

            return(schedule);
        }
        public static Association CreateAssociationWithServices(
            CifService mainService                 = null,
            CifService associatedService           = null,
            StpIndicator indicator                 = StpIndicator.Permanent,
            ICalendar calendar                     = null,
            Location location                      = null,
            AssociationCategory category           = AssociationCategory.Join,
            AssociationDateIndicator dateIndicator = AssociationDateIndicator.Standard,
            string associatedUid                   = "A98765",
            string retailServiceId                 = "VT123402"
            )
        {
            mainService       = mainService ?? TestSchedules.CreateScheduleWithService("X12345").Service;
            associatedService = associatedService ?? TestSchedules.CreateScheduleWithService(associatedUid, retailServiceId: retailServiceId).Service;

            var association = CreateAssociation(mainService.TimetableUid, associatedService.TimetableUid, indicator, calendar, location, category,
                                                dateIndicator);

            mainService.AddAssociation(association, true);
            associatedService.AddAssociation(association, false);

            return(association);
        }
Esempio n. 19
0
 internal static SortedList <(StpIndicator indicator, ICalendar calendar), CifSchedule> GetSchedules(this CifService service)
 {
     return((SortedList <(StpIndicator indicator, ICalendar calendar), CifSchedule>)service.AsDynamic()._multipleSchedules.RealObject);
 }