Skip to content

Commit

Permalink
#373 - Added unit test for variable output
Browse files Browse the repository at this point in the history
  • Loading branch information
DocMoebiuz committed Jul 18, 2021
1 parent f7e5a41 commit 19d6f98
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
11 changes: 8 additions & 3 deletions MobiFlight/OutputConfig/VariableOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"] != "")
Expand All @@ -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;

Expand Down
85 changes: 85 additions & 0 deletions MobiFlightUnitTests/MobiFlight/OutputConfig/VariableOutputTests.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
9 changes: 9 additions & 0 deletions MobiFlightUnitTests/MobiFlightUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="MobiFlight\MobiFlightLcdDisplayTests.cs" />
<Compile Include="MobiFlight\MobiFlightModuleTests.cs" />
<Compile Include="MobiFlight\OutputConfigItemTests.cs" />
<Compile Include="MobiFlight\OutputConfig\VariableOutputTests.cs" />
<Compile Include="MobiFlight\OutputConfig\LcdDisplayTests.cs" />
<Compile Include="MobiFlight\TransformationTests.cs" />
<Compile Include="mock\Base\KeyboardInputMock.cs" />
Expand Down Expand Up @@ -214,6 +215,14 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="assets\MobiFlight\OutputConfig\VariableOutput\ReadXmlTest.1.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="assets\MobiFlight\OutputConfig\VariableOutput\WriteXmlTest.1.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="assets\MobiFlight\OutputConfig\OutputConfigItem\ReadXmlTest.6.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 19d6f98

Please sign in to comment.