Exemplo n.º 1
0
        public void LogErrorIfNotTerminatedASchedule()
        {
            var records = new IRecord[]
            {
                new ScheduleDetails()
                {
                    TimetableUid = "Service1"
                },
                new ScheduleExtraData(),
                new OriginLocation(),
                new IntermediateLocation(),
                new ScheduleDetails()
                {
                    TimetableUid = "Service2", Action = RecordAction.Delete
                },
            };

            var parser = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(records);
            var logger = Substitute.For <ILogger>();

            var consolidator = new ScheduleConsolidator(parser, logger);

            var returned = consolidator.Read(_dummy).ToArray();

            logger.ReceivedWithAnyArgs().Error <IRecord>(Arg.Any <string>(), Arg.Any <IRecord>());
        }
Exemplo n.º 2
0
        public void DoesNotReturnServiceUntilTerminated()
        {
            var parser = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(new[] { new ScheduleDetails() });

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy);

            Assert.Empty(returned);
        }
Exemplo n.º 3
0
        public void ReturnServiceWhenTerminated()
        {
            var parser = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(new IRecord[] { new ScheduleDetails(), new TerminalLocation() });

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy).Single();;

            Assert.IsType <Schedule>(returned);
        }
Exemplo n.º 4
0
        public void ImmediatelyReturnNonServiceRecords(IRecord record)
        {
            var parser = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(new[] { record });

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy).Single();

            Assert.Equal(record, returned);
        }
Exemplo n.º 5
0
        public void MultipleServicesReturned()
        {
            var records = new IRecord[] { new ScheduleDetails(), new TerminalLocation(), new ScheduleDetails(), new TerminalLocation() };
            var parser  = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(records);

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy).ToArray();

            Assert.Equal(2, returned.Length);
        }
Exemplo n.º 6
0
        public void ReturnScheduleRecordsInService(IRecord record)
        {
            var records = new IRecord[] { new ScheduleDetails(), record, new TerminalLocation() };
            var parser  = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(records);

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy).Single() as Schedule;

            Assert.Contains(record, returned.Records);
        }
Exemplo n.º 7
0
        public void ReturnAllRecords()
        {
            var records = new IRecord[] { new ScheduleDetails(), new IntermediateLocation(), new TerminalLocation() };
            var parser  = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(records);

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy).Single() as Schedule;

            Assert.Equal(records.Length, returned.Records.Count);
            Assert.All(returned.Records, r => Assert.Contains(r, records));
        }
Exemplo n.º 8
0
        public void ReturnAllRecordsWHenHaveDelete()
        {
            var records = new IRecord[] { new ScheduleDetails()
                                          {
                                              Action = RecordAction.Delete
                                          }, new Trailer(), };
            var parser = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(records);

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy);

            Assert.Equal(records.Length, returned.Count());
        }
Exemplo n.º 9
0
        public void HandleRecordsInOrderInCif()
        {
            var records = new IRecord[]
            {
                new Header(),
                new TiplocInsertAmend(),
                new Association(),
                new ScheduleDetails()
                {
                    TimetableUid = "Service1"
                },
                new ScheduleExtraData(),
                new OriginLocation(),
                new IntermediateLocation(),
                new TerminalLocation(),
                new ScheduleDetails()
                {
                    TimetableUid = "Service2"
                },
                new ScheduleExtraData(),
                new OriginLocation(),
                new IntermediateLocation(),
                new ScheduleChange(),
                new IntermediateLocation(),
                new TerminalLocation(),
                new Trailer()
            };

            var parser = Substitute.For <IParser>();

            parser.Read(Arg.Any <TextReader>()).Returns(records);

            var consolidator = new ScheduleConsolidator(parser, Substitute.For <ILogger>());

            var returned = consolidator.Read(_dummy).ToArray();

            Assert.Equal(6, returned.Length);
            Assert.Equal("Service1", ((Schedule)returned[3]).GetId().TimetableUid);
            Assert.Equal("Service2", ((Schedule)returned[4]).GetId().TimetableUid);
        }