public void OnReturnsResolvedServiceOn()
        {
            var service = TestSchedules.CreateService();
            var stop    = new ResolvedServiceStop(service, service.Details.Locations[0]);

            Assert.Equal(TestDate, stop.On);
        }
        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);
        }
        public void StopIsNextDay(Time startTime, bool expected)
        {
            var stops   = TestSchedules.CreateThreeStopSchedule(startTime);
            var service = TestSchedules.CreateService(stops: stops);
            var clapham = service.Details.Locations[1];
            var stop    = new ResolvedServiceStop(service, clapham);

            Assert.Equal(expected, stop.IsNextDay(true));
        }
        public void GoesToWithNoAssociation()
        {
            var service = TestSchedules.CreateService();
            var clapham = service.Details.Locations[1];
            var stop    = new ResolvedServiceStop(service, clapham);

            Assert.True(stop.GoesTo(TestStations.Waterloo));
            Assert.False(stop.Association.IsIncluded);
            Assert.Equal(IncludedAssociation.NoAssociation, stop.Association);
        }
        public void RemovedCancelledService()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(isCancelled: true),
            };

            var notCancelled = FilterCancelled(services);

            Assert.Empty(notCancelled);
        }
Exemplo n.º 7
0
        public void SetsAssociationStopWhenConstructed()
        {
            var main        = TestSchedules.CreateService();
            var association = TestSchedules.CreateAssociation(main, "X98765");

            Assert.Null(association.Stop);

            var withAssociation = new ResolvedServiceWithAssociations(main, new [] { association });

            Assert.NotNull(association.Stop);
        }
        public void TwoServicesNotCancelledDoNotDedup()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(),
                TestSchedules.CreateService("Z12345"),
            };

            var deduped = Deduplicate(services);

            Assert.Equal(services, deduped);
        }
        public void TwoServicesDifferentRsidDoNotDedup()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(),
                TestSchedules.CreateService("Z12345",retailServiceId: "VT9999",  isCancelled: true),
            };

            var deduped = Deduplicate(services);

            Assert.Equal(services, deduped);
        }
        public void TwoServicesDifferentHeadcodeDoNotDedup()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(isCancelled: true),
                TestSchedules.CreateService("X98765")
            };

            var deduped = Deduplicate(services);

            Assert.Equal(services, deduped);
        }
        public void OnlyDepartureNextDay(bool useDeparture, bool expected)
        {
            var stops   = TestSchedules.CreateThreeStopSchedule(new Time(new TimeSpan(23, 40, 0)));
            var service = TestSchedules.CreateService(stops: stops);
            var clapham = service.Details.Locations[1] as ScheduleStop;

            clapham.Departure = new Time(new TimeSpan(0, 5, 0)).AddDay();

            var stop = new ResolvedServiceStop(service, clapham);

            Assert.Equal(expected, stop.IsNextDay(useDeparture));
        }
Exemplo n.º 12
0
        public void ComesFromIsFalseIfNotPublicDeparture(string activity, bool expected)
        {
            var service  = TestSchedules.CreateService();
            var waterloo = service.Details.Locations[3];
            var clapham  = service.Details.Locations[1] as ScheduleStop;

            clapham.Activities = new Activities(activity);

            var stop = new ResolvedServiceStop(service, waterloo);

            Assert.Equal(expected, stop.ComesFrom(clapham.Station));
            Assert.Equal(expected, stop.FoundFromStop != null);
        }
Exemplo n.º 13
0
        public void DeduplicateAlsoRemovesBrokenAssociations()
        {
            var service1 = TestSchedules.CreateServiceWithAssociation();

            Assert.True(service1.HasAssociations());
            service1.Associations[0].AsDynamic().Stop = null;
            var service2 = TestSchedules.CreateService("Z98765");

            var filters  = CreateFilter();
            var filtered = filters.Deduplicate(new [] { service1, service2 });

            Assert.False(service1.HasAssociations());
        }
Exemplo n.º 14
0
        public void BrokenAssociationsNotRemovedIfReturningDebugResponses()
        {
            var service1 = TestSchedules.CreateServiceWithAssociation();

            Assert.True(service1.HasAssociations());
            service1.Associations[0].AsDynamic().Stop = null;
            var service2 = TestSchedules.CreateService("Z98765");

            var filters  = new ServiceFilters(true, Substitute.For <ILogger>());
            var filtered = filters.RemoveBrokenServices(new [] { service1, service2 });

            Assert.True(service1.HasAssociations());
        }
        public void TwoServicesCancelledFirstDedup()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(isCancelled: true),
                TestSchedules.CreateService("Z12345")
            };

            var deduped = Deduplicate(services);

            Assert.Single(deduped);
            Assert.Equal(services[1], deduped[0]);
        }
        public void GoesToOnlyIfHasPublicArrival(string activity, bool expected)
        {
            var service  = TestSchedules.CreateService();
            var surbiton = service.Details.Locations[0];
            var clapham  = service.Details.Locations[1] as ScheduleStop;

            clapham.Activities = new Activities(activity);

            var stop = new ResolvedServiceStop(service, surbiton);

            Assert.Equal(expected, stop.GoesTo(clapham.Station));
            Assert.Equal(expected, stop.FoundToStop != null);
        }
Exemplo n.º 17
0
        public void RemoveCancelledAssociation()
        {
            var main         = TestSchedules.CreateService();
            var association1 = TestSchedules.CreateAssociation(main, "X98765", true);
            var association2 = TestSchedules.CreateAssociation(main, "X56789");

            var withAssociation = new ResolvedServiceWithAssociations(main, new [] { association1, association2 });

            withAssociation.RemoveCancelledAssociations();

            Assert.Single(withAssociation.Associations);
            Assert.Equal(association2, withAssociation.Associations[0]);
        }
Exemplo n.º 18
0
        public void AllAssociationsAreCancelled()
        {
            var main         = TestSchedules.CreateService();
            var association1 = TestSchedules.CreateAssociation(main, "X98765", true);
            var association2 = TestSchedules.CreateAssociation(main, "X56789", true);

            var withAssociation = new ResolvedServiceWithAssociations(main, new [] { association1, association2 });

            withAssociation.RemoveCancelledAssociations();

            Assert.False(withAssociation.HasAssociations());
            Assert.Empty(withAssociation.Associations);
        }
        public void MultipleServicesCancelled()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(isCancelled: true),
                TestSchedules.CreateService("Z12345"),
                TestSchedules.CreateService("A12345", isCancelled: true)
            };

            var notCancelled = FilterCancelled(services);

            Assert.Single(notCancelled);
            Assert.Equal(services[1], notCancelled[0]);
        }
Exemplo n.º 20
0
        public void RemoveAssociationWithCancelledService()
        {
            var main         = TestSchedules.CreateService();
            var associated   = TestSchedules.CreateService("X98765", stops: TestSchedules.CreateWokingClaphamSchedule(TestSchedules.NineForty), isCancelled: true);
            var association1 = TestSchedules.CreateAssociation(main, associated);
            var association2 = TestSchedules.CreateAssociation(main, "X56789");

            var withAssociation = new ResolvedServiceWithAssociations(main, new [] { association1, association2 });

            withAssociation.RemoveCancelledAssociations();

            Assert.Single(withAssociation.Associations);
            Assert.Equal(association2, withAssociation.Associations[0]);
        }
Exemplo n.º 21
0
        public void SetsAssociationWhenMultipleAssociations()
        {
            var main         = TestSchedules.CreateService();
            var association1 = TestSchedules.CreateAssociation(main, "X98765");
            var association2 = TestSchedules.CreateAssociation(main, "X56789");

            Assert.Null(association1.Stop);
            Assert.Null(association2.Stop);

            var withAssociation = new ResolvedServiceWithAssociations(main, new [] { association1, association2 });

            Assert.NotNull(association1.Stop);
            Assert.NotNull(association2.Stop);
        }
Exemplo n.º 22
0
        public void RemoveBrokenWhenCancelledAssociation()
        {
            var main            = TestSchedules.CreateService();
            var association1    = TestSchedules.CreateAssociation(main, "X98765", true);
            var association2    = TestSchedules.CreateAssociation(main, "X56789");
            var withAssociation = new ResolvedServiceWithAssociations(main, new [] { association1, association2 });

            association2.AsDynamic().Stop = new ResolvedAssociationStop(association2.Stop.Stop, null);

            withAssociation.RemoveBrokenAssociations();

            Assert.Single(withAssociation.Associations);
            Assert.Equal(association1, withAssociation.Associations[0]);
        }
        private ITimetableLookup CreateTimetableMock(Time dayBoundary, LookupStatus status)
        {
            var services = status == LookupStatus.Success
                ? new[] { TestSchedules.CreateService() }
                : new ResolvedService[0];

            var data = Substitute.For <ITimetableLookup>();

            data.GetSchedulesByToc(Arg.Any <string>(), Arg.Any <DateTime>(), dayBoundary)
            .Returns((LookupStatus.Success, services));
            data.CreateTocFilter()
            .Returns(new TocServicesFilter(data, Timetable.Test.Data.Filters.Instance));
            return(data);
        }
        public void ThreeServicesOnlyOneDedup()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService(isCancelled: true),
                TestSchedules.CreateService("Z12345"),
                TestSchedules.CreateService("X98765", isCancelled: true)
            };

            var deduped = Deduplicate(services);

            Assert.Equal(2, deduped.Length);
            Assert.Contains(services[1], deduped);
            Assert.Contains(services[2], deduped);
        }
Exemplo n.º 25
0
        public void FilterStopsAlsoRemovesBrokenAssociations()
        {
            var service1 = TestSchedules.CreateServiceWithAssociation();
            var stop1    = TestSchedules.CreateResolvedDepartureStop(service1);

            Assert.True(stop1.Service.HasAssociations());
            service1.Associations[0].AsDynamic().Stop = null;
            var service2 = TestSchedules.CreateService("Z98765");
            var stop2    = TestSchedules.CreateResolvedDepartureStop(service2);

            var filters  = CreateFilter();
            var filtered = filters.Filter(new [] { stop1, stop2 }, true);

            Assert.False(stop1.Service.HasAssociations());
        }
Exemplo n.º 26
0
        public void BrokenAssociationsNotRemovedFromStopsIfReturningDebugResponses()
        {
            var service1 = TestSchedules.CreateServiceWithAssociation();
            var stop1    = TestSchedules.CreateResolvedDepartureStop(service1);

            Assert.True(stop1.Service.HasAssociations());
            service1.Associations[0].AsDynamic().Stop = null;
            var service2 = TestSchedules.CreateService("Z98765");
            var stop2    = TestSchedules.CreateResolvedDepartureStop(service2);

            var filters  = new ServiceFilters(true, Substitute.For <ILogger>());
            var filtered = filters.Filter(new [] { stop1, stop2 }, true);

            Assert.True(stop1.Service.HasAssociations());
        }
        public void DedupMultipleDifferentServices()
        {
            ResolvedService[] services =
            {
                TestSchedules.CreateService("A98765"),
                TestSchedules.CreateService(isCancelled: true),
                TestSchedules.CreateService("Z12345"),
                TestSchedules.CreateService("X98765", isCancelled: true)
            };

            var deduped = Deduplicate(services);

            Assert.Equal(2, deduped.Length);
            Assert.Contains(services[0], deduped);
            Assert.Contains(services[2], deduped);
        }
Exemplo n.º 28
0
        public async Task ServiceByTimetableUidReturnsCancelledWithReason()
        {
            var data = Substitute.For <ITimetableLookup>();

            data.GetScheduleByTimetableUid(Arg.Any <string>(), Arg.Any <DateTime>())
            .Returns((LookupStatus.Success, TestSchedules.CreateService(isCancelled: true)));

            var controller = new ServiceController(data, _config.CreateMapper(), Substitute.For <ILogger>());
            var response   = await controller.GetServiceByTimetableId("X12345", April1) as ObjectResult;

            Assert.Equal(200, response.StatusCode);
            var service = GetService(response);;

            Assert.Equal("X12345", service.TimetableUid);
            Assert.True(service.IsCancelled);
        }
        public void GoesTo(Station station, bool isTo)
        {
            var service = TestSchedules.CreateService();
            var clapham = service.Details.Locations[1];
            var stop    = new ResolvedServiceStop(service, clapham);

            if (isTo)
            {
                Assert.True(stop.GoesTo(station));
                Assert.NotNull(stop.FoundToStop);
            }
            else
            {
                Assert.False(stop.GoesTo(station));
                Assert.Null(stop.FoundToStop);
            }
        }
Exemplo n.º 30
0
        public async Task ServiceByRetailServiceIdReturnsCancelledWithReason()
        {
            var data = Substitute.For <ITimetableLookup>();

            data.GetScheduleByRetailServiceId(Arg.Any <string>(), Arg.Any <DateTime>())
            .Returns((LookupStatus.Success, new [] { TestSchedules.CreateService(isCancelled: true) }));

            var controller = new ServiceController(data, _config.CreateMapper(), Substitute.For <ILogger>());
            var response   = await controller.GetServiceByRetailServiceId("VT1234", April1) as ObjectResult;;

            Assert.Equal(200, response.StatusCode);

            var services = response.Value as Model.Service[];
            var service  = services[0];

            Assert.Equal("VT123400", service.RetailServiceId);
            Assert.True(service.IsCancelled);
        }