diff --git a/MobiFlight/OutputConfig/VariableOutput.cs b/MobiFlight/OutputConfig/VariableOutput.cs index 755220ac9..b98f47d23 100644 --- a/MobiFlight/OutputConfig/VariableOutput.cs +++ b/MobiFlight/OutputConfig/VariableOutput.cs @@ -11,7 +11,12 @@ public class VariableOutput { public MobiFlightVariable Variable { get; set; } - internal void ReadXml(XmlReader reader) + public VariableOutput() + { + Variable = new MobiFlightVariable(); + } + + public void ReadXml(XmlReader reader) { if (reader["varType"] != null && reader["varType"] != "" && reader["varName"] != null && reader["varName"] != "") @@ -21,14 +26,14 @@ internal void ReadXml(XmlReader reader) } } - internal void WriteXml(XmlWriter writer) + public void WriteXml(XmlWriter writer) { writer.WriteAttributeString("type", "VariableOutput"); writer.WriteAttributeString("varType", Variable.TYPE); writer.WriteAttributeString("varName", Variable.Name); } - internal object Clone() + public object Clone() { MobiFlightVariable clone = Variable.Clone() as MobiFlightVariable; diff --git a/MobiFlightUnitTests/MobiFlight/OutputConfig/VariableOutputTests.cs b/MobiFlightUnitTests/MobiFlight/OutputConfig/VariableOutputTests.cs new file mode 100644 index 000000000..e26624d73 --- /dev/null +++ b/MobiFlightUnitTests/MobiFlight/OutputConfig/VariableOutputTests.cs @@ -0,0 +1,85 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MobiFlight.OutputConfig; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace MobiFlight.OutputConfig.Tests +{ + [TestClass()] + public class VariableOutputTests + { + [TestMethod()] + public void VariableOutputTest() + { + VariableOutput o = new VariableOutput(); + Assert.IsNotNull(o, "Object is null"); + + Assert.IsNotNull(o.Variable, "Variable is not null"); + Assert.IsNotNull(o.Variable.Name, "Variable.Name is null"); + } + + [TestMethod()] + public void CloneTest() + { + VariableOutput o = new VariableOutput(); + o.Variable.Name = "Test"; + VariableOutput c = o.Clone() as VariableOutput; + Assert.IsNotNull(c, "Clone is null"); + Assert.AreEqual(o.Variable.Name, c.Variable.Name, "Address are not the same"); + } + + [TestMethod()] + public void GetSchemaTest() + { + LcdDisplay o = new LcdDisplay(); + + Assert.IsNull(o.GetSchema(), "Schema not null"); + } + + [TestMethod()] + public void ReadXmlTest() + { + VariableOutput o = new VariableOutput(); + + String s = System.IO.File.ReadAllText(@"assets\MobiFlight\OutputConfig\VariableOutput\ReadXmlTest.1.xml"); + StringReader sr = new StringReader(s); + XmlReaderSettings settings = new XmlReaderSettings(); + settings.IgnoreWhitespace = true; + + System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(sr, settings); + xmlReader.ReadToDescendant("display"); + o.ReadXml(xmlReader); + + Assert.AreEqual("ReadXMLTest", o.Variable.Name, "Variable.Name does not match."); + } + + [TestMethod()] + public void WriteXmlTest() + { + StringWriter sw = new StringWriter(); + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = System.Text.Encoding.UTF8; + settings.Indent = true; + //settings.NewLineHandling = NewLineHandling.Entitize; + System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(sw, settings); + + VariableOutput o = new VariableOutput(); + o.Variable.Name = "WriteXMLTest"; + + xmlWriter.WriteStartElement("display"); + o.WriteXml(xmlWriter); + xmlWriter.WriteEndElement(); + xmlWriter.Flush(); + string s = sw.ToString(); + + String result = System.IO.File.ReadAllText(@"assets\MobiFlight\OutputConfig\VariableOutput\WriteXmlTest.1.xml"); + + Assert.AreEqual(s, result, "The both strings are not equal"); + } + } +} \ No newline at end of file diff --git a/MobiFlightUnitTests/MobiFlightUnitTests.csproj b/MobiFlightUnitTests/MobiFlightUnitTests.csproj index 88477faa5..63140be2f 100644 --- a/MobiFlightUnitTests/MobiFlightUnitTests.csproj +++ b/MobiFlightUnitTests/MobiFlightUnitTests.csproj @@ -80,6 +80,7 @@ + @@ -214,6 +215,14 @@ Designer Always + + Designer + Always + + + Designer + Always + Designer Always diff --git a/MobiFlightUnitTests/assets/MobiFlight/OutputConfig/VariableOutput/ReadXmlTest.1.xml b/MobiFlightUnitTests/assets/MobiFlight/OutputConfig/VariableOutput/ReadXmlTest.1.xml new file mode 100644 index 000000000..9f3828d25 Binary files /dev/null and b/MobiFlightUnitTests/assets/MobiFlight/OutputConfig/VariableOutput/ReadXmlTest.1.xml differ diff --git a/MobiFlightUnitTests/assets/MobiFlight/OutputConfig/VariableOutput/WriteXmlTest.1.xml b/MobiFlightUnitTests/assets/MobiFlight/OutputConfig/VariableOutput/WriteXmlTest.1.xml new file mode 100644 index 000000000..d95dcd9f4 Binary files /dev/null and b/MobiFlightUnitTests/assets/MobiFlight/OutputConfig/VariableOutput/WriteXmlTest.1.xml differ