public void WTTTrainCategory_Constructor_JSON() { //Get XElement from test .xml string TestXMLPath = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\TestWTT_4.8.xml"; XElement XMLTestTrainCategory = XDocument.Load(TestXMLPath).Element("SimSigTimetable").Element("TrainCategories").Descendants().First(); GroundFrame.Core.Timetables.WTTTrainCategory TestCategory = new Core.Timetables.WTTTrainCategory(XMLTestTrainCategory); //Create JSON string TestJSON = TestCategory.ToJSON(); //Create new ojbect from JSON GroundFrame.Core.Timetables.WTTTrainCategory TestJSONCategory = new Timetables.WTTTrainCategory(TestJSON); //Test Assert.Equal(XMLTestTrainCategory.Attribute("ID").Value.ToString(), TestJSONCategory.SimSigID); Assert.Equal(XMLTestTrainCategory.Element("Description").Value.ToString(), TestJSONCategory.Description); Assert.Equal((WTTAccelBrakeIndex)Convert.ToInt32(XMLTestTrainCategory.Element("AccelBrakeIndex").Value), TestJSONCategory.AccelBrakeIndex); Assert.Equal(XMLTestTrainCategory.Element("IsFreight").Value == "0" ? false : true, TestJSONCategory.IsFreight); Assert.Equal(XMLTestTrainCategory.Element("CanUseGoodsLines").Value == "0" ? false : true, TestJSONCategory.CanUseGoodsLines); Assert.Equal(new GroundFrame.Core.Timetables.WTTSpeed(Convert.ToInt32(XMLTestTrainCategory.Element("MaxSpeed").Value.ToString())).MPH, TestJSONCategory.MaxSpeed.MPH); Assert.Equal(new GroundFrame.Core.Length(Convert.ToInt32(XMLTestTrainCategory.Element("TrainLength").Value.ToString())).Meters, TestJSONCategory.TrainLength.Meters); Assert.Equal(new GroundFrame.Core.Timetables.WTTSpeedClass(Convert.ToInt32(XMLTestTrainCategory.Element("SpeedClass").Value.ToString())).Bitwise, TestJSONCategory.SpeedClass.Bitwise); Assert.Equal((WTTPowerToWeightCategory)Convert.ToInt32(XMLTestTrainCategory.Element("PowerToWeightCategory").Value), TestJSONCategory.PowerToWeightCategory); Assert.Equal(new GroundFrame.Core.Electrification(XMLTestTrainCategory.Element("Electrification").Value.ToString()).Overhead, TestJSONCategory.Electrification.Overhead); Assert.Equal(XMLTestTrainCategory.Element("CautionSpeedSet")?.Value.ToString(), TestJSONCategory.CautionSpeedSet); if (XMLTestTrainCategory.Element("DwellTimes") == null) { Assert.Null(TestJSONCategory.DwellTimes); } else { //TODO: Test Dwell Times } }
public void WTTTrainCategory_Method_ToJSON() { //Get XElement from test .xml string TestXMLPath = $"{System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}\\Resources\\TestWTT_4.8.xml"; XElement XMLTestTrainCategory = XDocument.Load(TestXMLPath).Element("SimSigTimetable").Element("TrainCategories").Descendants().First(); GroundFrame.Core.Timetables.WTTTrainCategory TestCategory = new Core.Timetables.WTTTrainCategory(XMLTestTrainCategory); //Create JSON string TestJSON = TestCategory.ToJSON(); //Create new ojbect from JSON GroundFrame.Core.Timetables.WTTTrainCategory TestJSONCategory = new Timetables.WTTTrainCategory(TestJSON); //Test Assert.Equal(TestJSON, TestJSONCategory.ToJSON()); }