Esempio n. 1
0
        public void WTTCautionSpeed_Constructor_XElement()
        {
            string   TestXMLPath         = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\TestThreeBridges_4.8.xml";
            XElement XMLTestCautionSpeed = XDocument.Load(TestXMLPath).Element("SimSigTimetable").Element("CautionSpeedSets").Element("CautionSpeedSet").Element("CautionSpeeds").Element("CautionSpeed");

            GroundFrame.Core.Timetables.WTTCautionSpeed TestCautionSpeed = new Timetables.WTTCautionSpeed(XMLTestCautionSpeed);

            //Run tests
            Assert.Equal(XMLTestCautionSpeed.Element("AspectPassed") == null ? WTTSignalAspect.Red : (WTTSignalAspect)Convert.ToInt32(XMLTestCautionSpeed.Element("AspectPassed").Value), TestCautionSpeed.AspectPassed);

            if (XMLTestCautionSpeed.Element("FromLineSpeed") == null)
            {
                Assert.Null(TestCautionSpeed.FromLineSpeed);
            }
            else
            {
                Assert.Equal(Convert.ToInt32(XMLTestCautionSpeed.Element("FromLineSpeed").Value), TestCautionSpeed.FromLineSpeed.MPH);
            }

            Assert.Equal(XMLTestCautionSpeed.Element("ReduceNowValue") == null ? 0 : Convert.ToInt32(XMLTestCautionSpeed.Element("ReduceNowValue").Value), TestCautionSpeed.ReduceNowValue);
            Assert.Equal(XMLTestCautionSpeed.Element("approachNextValue") == null ? 0 : Convert.ToInt32(XMLTestCautionSpeed.Element("approachNextValue").Value), TestCautionSpeed.ApproachNextValue);

            if (XMLTestCautionSpeed.Element("approachNextDistance") == null)
            {
                Assert.Null(TestCautionSpeed.ApproachNextDistance);
            }
            else
            {
                Assert.Equal(new Length(Convert.ToInt32(XMLTestCautionSpeed.Element("approachNextDistance").Value)).Meters, TestCautionSpeed.ApproachNextDistance.Meters);
            }

            Assert.Equal(XMLTestCautionSpeed.Element("NowValueType") == null ? WTTNumberType.NotApplicable : (WTTNumberType)Convert.ToInt32(XMLTestCautionSpeed.Element("NowValueType").Value), TestCautionSpeed.NowValueType);
            Assert.Equal(XMLTestCautionSpeed.Element("NextValueType") == null ? WTTNumberType.NotApplicable : (WTTNumberType)Convert.ToInt32(XMLTestCautionSpeed.Element("NextValueType").Value), TestCautionSpeed.NextValueType);
        }
Esempio n. 2
0
        public void WTTCautionSpeedSet_Method_Add()
        {
            string   TestXMLPath            = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\TestThreeBridges_4.8.xml";
            XElement XMLTestCautionSpeedSet = XDocument.Load(TestXMLPath).Element("SimSigTimetable").Element("CautionSpeedSets").Element("CautionSpeedSet");

            GroundFrame.Core.Timetables.WTTCautionSpeedSet TestCautionSpeedSet = new Timetables.WTTCautionSpeedSet(XMLTestCautionSpeedSet);

            //Test Before
            Assert.Equal(XMLTestCautionSpeedSet.Elements("CautionSpeeds").Elements("CautionSpeed").Count(), TestCautionSpeedSet.CautionSpeeds.Count);

            Timetables.WTTCautionSpeed RemovedCautionSpeed = TestCautionSpeedSet.CautionSpeeds[0];

            //Remove 1
            TestCautionSpeedSet.RemoveAt(0);
            //Test After - Should be 1 Less
            Assert.Equal(XMLTestCautionSpeedSet.Elements("CautionSpeeds").Elements("CautionSpeed").Count() - 1, TestCautionSpeedSet.CautionSpeeds.Count);

            //Add Back
            TestCautionSpeedSet.CautionSpeeds.Add(RemovedCautionSpeed);
            //Test After - Should be same as begining
            Assert.Equal(XMLTestCautionSpeedSet.Elements("CautionSpeeds").Elements("CautionSpeed").Count(), TestCautionSpeedSet.CautionSpeeds.Count);
        }