Ejemplo n.º 1
0
        public void WTT_Constructor_FileInfoWithDate()
        {
            //Get XElement from test .xml
            string   TestFilePath = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\TestWTT_4.8.WTT";
            FileInfo Filename     = new FileInfo(TestFilePath);

            Core.Timetables.WTT TestWTT = new Core.Timetables.WTT(Filename, new DateTime(2018, 7, 1));
            Assert.Equal("Royston Weekday July 2018 Timetable", TestWTT.Header.Name);
            Assert.Equal(3, TestWTT.TrainCategories.Count);
            Assert.Equal(new DateTime(2018, 7, 1), TestWTT.StartDate);
        }
Ejemplo n.º 2
0
        public void WTT_Constructor_JSON(string FileGroup, string Name, int TrainCategoryCount, string HeadCode, int ActivityCount)
        {
            //Get XElement from test .xml
            string TestJSONPath = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\{FileGroup}.json";
            string JSON         = File.ReadAllText(TestJSONPath);

            Core.Timetables.WTT TestWTT = new Core.Timetables.WTT(JSON);
            Assert.Equal(Name, TestWTT.Header.Name);
            Assert.Equal(TrainCategoryCount, TestWTT.TrainCategories.Count);
            List <Core.Timetables.WTTTimeTable> TimeTables = TestWTT.TimeTables.GetByHeadCode(HeadCode);

            Core.Timetables.WTTActivityCollection TestActivities = TimeTables[0].Trip.IndexOf(1).Activities;
            Assert.Equal(ActivityCount, TestActivities == null ? 0 : TestActivities.Count);
        }
Ejemplo n.º 3
0
        public void WTT_Constructor_FileInfo(string FileGroup, string Name, int TrainCategoryCount, string HeadCode, int ActivityCount)
        {
            //Get XElement from test .xml
            string   TestFilePath = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\{FileGroup}.WTT";
            FileInfo Filename     = new FileInfo(TestFilePath);

            Core.Timetables.WTT TestWTT = new Core.Timetables.WTT(Filename);
            Assert.Equal(Name, TestWTT.Header.Name);
            Assert.Equal(TrainCategoryCount, TestWTT.TrainCategories.Count);
            Assert.Equal(new DateTime(1850, 1, 1), TestWTT.StartDate);

            List <Core.Timetables.WTTTimeTable> TimeTables = TestWTT.TimeTables.GetByHeadCode(HeadCode);

            Core.Timetables.WTTActivityCollection TestActivities = TimeTables[0].Trip.IndexOf(1).Activities;
            Assert.Equal(ActivityCount, TestActivities == null ? 0 : TestActivities.Count);
        }
Ejemplo n.º 4
0
        public void WTT_Method_ToJSON()
        {
            //Create WTT From test .WTT file
            string   TestFilePath = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\TestWTT_4.8.WTT";
            FileInfo Filename     = new FileInfo(TestFilePath);

            Core.Timetables.WTT TestWTT = new Core.Timetables.WTT(Filename, new DateTime(2018, 7, 1));
            string TestJSON             = TestWTT.ToJSON();

            //Parse JSON
            JObject ParsedJSON = JObject.Parse(TestJSON);

            //Test various elements
            Assert.Equal(TestWTT.TimeTables.Count(), ParsedJSON["timeTables"].Count());
            Assert.Equal(TestWTT.TimeTables.IndexOf(0).Trip.Count(), ParsedJSON["timeTables"][0]["trip"].Count());
            Assert.Equal(TestWTT.TimeTables.GetByHeadCode("1R52").FirstOrDefault().Trip.IndexOf(1).Activities.Count(), ParsedJSON["timeTables"].Where(h => h["headcode"].ToString() == "1R52").FirstOrDefault()["trip"][1]["activities"].Count());
        }