Exemple #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));
        }
        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);
                }
            }
        }
Exemple #3
0
        public void NotConsistentLocationWhenCannotFindTheStop(bool isMain)
        {
            var association = TestAssociations.CreateAssociation(location: TestLocations.Weybridge);
            var schedule    = TestSchedules.CreateScheduleWithService();

            Assert.False(association.HasConsistentLocation(schedule, isMain));
        }
Exemple #4
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));
        }
Exemple #5
0
        public void ThrowsExceptionWhenDateIndicatorNotSet()
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: AssociationDateIndicator.None);

            Assert.Throws <ArgumentException>(() => association.ResolveDate(MondayAugust12, AssociatedUid));
        }
Exemple #6
0
        public void ResolveDate(AssociationDateIndicator indicator, bool isMain, DateTime expected)
        {
            var association = TestAssociations.CreateAssociationWithServices(dateIndicator: indicator);

            var service = isMain ? association.Main.Service : association.Associated.Service;

            Assert.Equal(expected, association.ResolveDate(MondayAugust12, service.TimetableUid));
        }
Exemple #7
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));
        }
Exemple #8
0
        public void DoesNotThrowExceptionIsMain()
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                dateIndicator: AssociationDateIndicator.None);

            Assert.True(association.AppliesOn(MondayAugust12, MainUid));
        }
Exemple #9
0
        public void HasConsistentLocationOnAssociated(string activities, AssociationCategory joinSplit, bool expected)
        {
            var stops       = AssociationDictionaryTest.CreateAssociateStopsSettingClaphamActivities(joinSplit, activities);
            var schedule    = TestSchedules.CreateScheduleWithService(stops: stops);
            var association = TestAssociations.CreateAssociation(category: joinSplit);

            Assert.Equal(expected, association.HasConsistentLocation(schedule, false));
        }
Exemple #10
0
        public void ResolveDateWhenCancelledWhenNoDateIndicator(string timetableUid)
        {
            var association = TestAssociations.CreateAssociation(
                calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday),
                indicator: StpIndicator.Cancelled,
                dateIndicator: AssociationDateIndicator.None);

            Assert.Equal(MondayAugust12, association.ResolveDate(MondayAugust12, timetableUid));
        }
Exemple #11
0
        public void AddToServiceAddAssociatedService()
        {
            var schedule    = TestSchedules.CreateScheduleWithService("A98765");
            var association = TestAssociations.CreateAssociation();

            association.SetService(schedule.Service, false);
            Assert.Equal(schedule.Service, association.Associated.Service);
            Assert.Null(association.Main.Service);
        }
Exemple #12
0
        private Association CreateJoinServices()
        {
            var main       = TestSchedules.CreateScheduleWithService("X12345", retailServiceId: "VT123401").Service;
            var associated = TestSchedules.CreateScheduleWithService("A98765", retailServiceId: "VT123402",
                                                                     stops: TestSchedules.CreateWokingClaphamSchedule(TestSchedules.NineForty)).Service;
            var association = TestAssociations.CreateAssociationWithServices(main, associated);

            return(association);
        }
        private Association CreateSplitServices(ScheduleLocation[] mainStops = null)
        {
            mainStops ??= CreateMainStops();
            var main       = TestSchedules.CreateScheduleWithService("X12345", retailServiceId: "VT123401", stops: mainStops).Service;
            var associated = TestSchedules.CreateScheduleWithService("A98765", retailServiceId: "VT123402",
                                                                     stops: TestSchedules.CreateClaphamWokingSchedule(TestSchedules.TenTwentyFive)).Service;
            var association = TestAssociations.CreateAssociationWithServices(main, associated, category: AssociationCategory.Split);

            return(association);
        }
        public void FailToAddAssociation()
        {
            var service     = TestSchedules.CreateScheduleWithService().Service;
            var association = TestAssociations.CreateAssociation();

            service.AddAssociation(association, true);
            // Adding same association can result in failing to add
            Assert.False(service.AddAssociation(association, true));
            Assert.False(service.HasAssociations());
        }
        public void AssociationsReturnsResolvedServiceWithAssociations()
        {
            var schedule = TestSchedules.CreateScheduleWithService();
            var service  = schedule.Service;

            var association = TestAssociations.CreateAssociationWithServices(mainService: service);

            service.TryResolveOn(MondayAugust12, out var found);
            Assert.IsType <ResolvedServiceWithAssociations>(found);
        }
Exemple #16
0
        private Association CreateJoinServices(Time associationDeparts, ScheduleLocation[] mainStops = null)
        {
            mainStops ??= CreateMainStops();
            var main       = TestSchedules.CreateScheduleWithService("X12345", retailServiceId: "VT123401", stops: mainStops).Service;
            var associated = TestSchedules.CreateScheduleWithService("A98765", retailServiceId: "VT123402",
                                                                     stops: TestSchedules.CreateWokingClaphamSchedule(associationDeparts)).Service;
            var association = TestAssociations.CreateAssociationWithServices(main, associated);

            return(association);
        }
        private Association CreateJoinServices(ScheduleLocation[] mainStops = null)
        {
            mainStops = mainStops ?? TestSchedules.CreateThreeStopSchedule(TestSchedules.Ten);
            var main       = TestSchedules.CreateScheduleWithService("X12345", retailServiceId: "VT123401", stops: mainStops).Service;
            var associated = TestSchedules.CreateScheduleWithService("A98765", retailServiceId: "VT123402",
                                                                     stops: TestSchedules.CreateWokingClaphamSchedule(TestSchedules.NineForty)).Service;
            var association = TestAssociations.CreateAssociationWithServices(main, associated);

            return(association);
        }
        public void WhenIsAssociatedAddMainUid()
        {
            var service     = TestSchedules.CreateScheduleWithService("A98765").Service;
            var association = TestAssociations.CreateAssociation();

            Assert.True(service.AddAssociation(association, false));
            Assert.True(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.NotEmpty(associations["X12345"]);
        }
        public void WhenIsMainAddsAssociatedUid()
        {
            var service     = TestSchedules.CreateScheduleWithService().Service;
            var association = TestAssociations.CreateAssociation();

            Assert.True(service.AddAssociation(association, true));
            Assert.True(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.NotEmpty(associations["A98765"]);
        }
        public void IsMain(string timetableId, bool expected)
        {
            var association = new ResolvedAssociation(
                TestAssociations.CreateAssociation(),
                DateTime.Today,
                false,
                null);

            ;

            Assert.Equal(expected, association.IsMain(timetableId));
        }
        [InlineData("VT567802", true)]    // Allow associations with different Retail Service Ids example LIV-EUS Saturdays 20:04 LNWR
        public void ResolveAssociationsWithDifferentRetailServiceId(string associatedRetailServiceId, bool hasAssociation)
        {
            var schedule = TestSchedules.CreateScheduleWithService(retailServiceId: "VT123401");
            var service  = schedule.Service;

            var association = TestAssociations.CreateAssociationWithServices(indicator: StpIndicator.Permanent, mainService: service, retailServiceId: associatedRetailServiceId);

            var associations = service.AsDynamic()._associations.RealObject as AssociationDictionary;

            var resolved = associations.Resolve(service.TimetableUid, MondayAugust12, schedule.NrsRetailServiceId);

            Assert.Equal(hasAssociation, resolved.Any());
        }
        public void IsSplit(AssociationCategory category, bool expected)
        {
            var association = TestAssociations.CreateAssociationWithServices(category: category);
            var resolved    = new ResolvedAssociation(
                association,
                DateTime.Today,
                false,
                null);

            ;

            Assert.Equal(expected, resolved.IsSplit);
        }
        public void AddSameAssociationTwiceResultsInNeitherBeingAdded()
        {
            var service   = TestSchedules.CreateScheduleWithService().Service;
            var permanent = TestAssociations.CreateAssociation();

            service.AddAssociation(permanent, true);
            service.AddAssociation(permanent, true);

            Assert.False(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.Empty(associations);
        }
        public void ResolveAssociationsHighIndicatorsTakePriorityOverLow(StpIndicator lowIndicator, StpIndicator highIndicator)
        {
            var schedule = TestSchedules.CreateScheduleWithService();
            var service  = schedule.Service;

            var low          = TestAssociations.CreateAssociationWithServices(indicator: lowIndicator, mainService: service);
            var high         = TestAssociations.CreateAssociationWithServices(indicator: highIndicator, mainService: service);
            var associations = service.AsDynamic()._associations.RealObject as AssociationDictionary;

            var resolved = associations.Resolve(service.TimetableUid, MondayAugust12, schedule.NrsRetailServiceId);

            Assert.Equal(high, resolved[0].Details);
        }
        public void ResolveAssociationsCancelledAssociationsReturned(StpIndicator lowIndicator)
        {
            var schedule = TestSchedules.CreateScheduleWithService();
            var service  = schedule.Service;

            var low          = TestAssociations.CreateAssociationWithServices(indicator: lowIndicator, mainService: service);
            var cancelled    = TestAssociations.CreateAssociationWithServices(indicator: StpIndicator.Cancelled, mainService: service);
            var associations = service.AsDynamic()._associations.RealObject as AssociationDictionary;

            var resolved = associations.Resolve(service.TimetableUid, MondayAugust12, schedule.NrsRetailServiceId);

            Assert.True(resolved[0].IsCancelled);
            Assert.Equal(low, resolved[0].Details);
        }
        public void AddReversedAssociationTwiceResultsInNeitherBeingAdded()
        {
            var service     = TestSchedules.CreateScheduleWithService("A12345").Service;
            var association = TestAssociations.CreateAssociation(mainUid: "A12345", associatedUid: "A67890");
            var reversed    = TestAssociations.CreateAssociation(mainUid: "A67890", associatedUid: "A12345");

            service.AddAssociation(association, true);
            service.AddAssociation(reversed, false);

            Assert.False(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.Empty(associations);
        }
Exemple #27
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);
        }
        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);
        }
        public void CanAddAssociationsWithSameStpIndicator()
        {
            var service    = TestSchedules.CreateScheduleWithService().Service;
            var permanent  = TestAssociations.CreateAssociation(indicator: StpIndicator.Permanent);
            var permanent2 = TestAssociations.CreateAssociation(indicator: StpIndicator.Permanent, calendar: TestSchedules.CreateAugust2019Calendar(DaysFlag.Monday));

            service.AddAssociation(permanent, true);
            service.AddAssociation(permanent2, true);

            Assert.True(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.Single(associations);
            Assert.Equal(2, associations["A98765"].Count);
        }
        public void CanAddAssociationWithDifferentStpIndicator()
        {
            var service   = TestSchedules.CreateScheduleWithService().Service;
            var permanent = TestAssociations.CreateAssociation(indicator: StpIndicator.Permanent);
            var overlay   = TestAssociations.CreateAssociation(indicator: StpIndicator.Override);

            service.AddAssociation(permanent, true);
            service.AddAssociation(overlay, true);

            Assert.True(service.HasAssociations());
            var associations = service.GetAssociations();

            Assert.Single(associations);
            Assert.Equal(2, associations["A98765"].Count);
        }