-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
fca9192
commit f7e5a41
Showing
8 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
MobiFlightUnitTests/MobiFlight/InputConfig/AnalogInputConfigTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using MobiFlight.InputConfig; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
|
||
namespace MobiFlight.InputConfig.Tests | ||
{ | ||
[TestClass()] | ||
public class AnalogInputConfigTests | ||
{ | ||
[TestMethod()] | ||
public void CloneTest() | ||
{ | ||
AnalogInputConfig o = generateTestObject(); | ||
AnalogInputConfig c = (AnalogInputConfig) o.Clone(); | ||
|
||
Assert.AreNotSame(o, c, "Cloned object is the same"); | ||
Assert.AreEqual((o.onChange as VariableInputAction).Variable.Name, (c.onChange as VariableInputAction).Variable.Name, "onChange is not correct"); | ||
} | ||
|
||
private AnalogInputConfig generateTestObject() | ||
{ | ||
AnalogInputConfig o = new AnalogInputConfig(); | ||
o.onChange = new VariableInputAction(); | ||
(o.onChange as VariableInputAction).Variable.Name = "AnalogInputConfigTest"; | ||
return o; | ||
} | ||
|
||
[TestMethod()] | ||
public void GetSchemaTest() | ||
{ | ||
ButtonInputConfig o = new ButtonInputConfig(); | ||
Assert.IsNull(o.GetSchema()); | ||
} | ||
|
||
[TestMethod()] | ||
public void ReadXmlTest() | ||
{ | ||
AnalogInputConfig o = new AnalogInputConfig(); | ||
String s = System.IO.File.ReadAllText(@"assets\MobiFlight\InputConfig\AnalogInputConfig\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("analog"); | ||
o.ReadXml(xmlReader); | ||
|
||
Assert.AreEqual("AnalogInputConfigReadXML", (o.onChange as VariableInputAction).Variable.Name, "Variable.Name are not Equal"); | ||
|
||
} | ||
|
||
[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); | ||
|
||
AnalogInputConfig o = generateTestObject(); | ||
xmlWriter.WriteStartElement("analog"); | ||
o.WriteXml(xmlWriter); | ||
xmlWriter.WriteEndElement(); | ||
xmlWriter.Flush(); | ||
string s = sw.ToString(); | ||
|
||
String result = System.IO.File.ReadAllText(@"assets\MobiFlight\InputConfig\AnalogInputConfig\WriteXmlTest.1.xml"); | ||
|
||
Assert.AreEqual(result, s, "The both strings are not equal"); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
MobiFlightUnitTests/MobiFlight/InputConfig/VariableInputActionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using MobiFlight.InputConfig; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
|
||
namespace MobiFlight.InputConfig.Tests | ||
{ | ||
[TestClass()] | ||
public class VariableInputActionTests | ||
{ | ||
[TestMethod()] | ||
public void CloneTest() | ||
{ | ||
VariableInputAction o = generateTestObject(); | ||
VariableInputAction c = (VariableInputAction) o.Clone(); | ||
Assert.AreNotSame(o, c, "Clone is the same object"); | ||
Assert.AreEqual(o.Variable.TYPE, c.Variable.TYPE, "EventId not the same"); | ||
Assert.AreEqual(o.Variable.Name, c.Variable.Name, "EventId not the same"); | ||
Assert.AreEqual(o.Variable.Expression, c.Variable.Expression, "EventId not the same"); | ||
} | ||
|
||
private VariableInputAction generateTestObject() | ||
{ | ||
VariableInputAction o = new VariableInputAction(); | ||
o.Variable.Name = "VariableInputActionTests"; | ||
o.Variable.TYPE = "string"; | ||
o.Variable.Text = "VariableInputActionTests"; | ||
o.Variable.Expression = "$+1"; | ||
return o; | ||
} | ||
|
||
[TestMethod()] | ||
public void ReadXmlTest() | ||
{ | ||
VariableInputAction o = new VariableInputAction(); | ||
String s = System.IO.File.ReadAllText(@"assets\MobiFlight\InputConfig\VariableInputAction\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("onPress"); | ||
o.ReadXml(xmlReader); | ||
|
||
Assert.AreEqual(o.Variable.TYPE, "string", "Variable.TYPE are not the same"); | ||
Assert.AreEqual(o.Variable.Name, "VariableInputActionReadXMLTests", "Param not the same"); | ||
} | ||
|
||
[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); | ||
|
||
VariableInputAction o = generateTestObject(); | ||
o.Variable.Name = "VariableInputActionWriteXMLTests"; | ||
xmlWriter.WriteStartElement("onPress"); | ||
o.WriteXml(xmlWriter); | ||
xmlWriter.WriteEndElement(); | ||
xmlWriter.Flush(); | ||
string s = sw.ToString(); | ||
|
||
String result = System.IO.File.ReadAllText(@"assets\MobiFlight\InputConfig\VariableInputAction\WriteXmlTest.1.xml"); | ||
|
||
Assert.AreEqual(s, result, "The both strings are not equal"); | ||
} | ||
|
||
[TestMethod()] | ||
public void executeTest() | ||
{ | ||
VariableInputAction o = generateTestObject(); | ||
MobiFlightUnitTests.mock.FSUIPC.FSUIPCCacheMock mock = new MobiFlightUnitTests.mock.FSUIPC.FSUIPCCacheMock(); | ||
MobiFlightUnitTests.mock.SimConnectMSFS.SimConnectCacheMock simConnectMock = new MobiFlightUnitTests.mock.SimConnectMSFS.SimConnectCacheMock(); | ||
MobiFlightUnitTests.mock.MobiFlight.MobiFlightCacheMock mobiflightCacheMock = new MobiFlightUnitTests.mock.MobiFlight.MobiFlightCacheMock(); | ||
o.Variable.TYPE = "number"; | ||
o.Variable.Expression = "$+1"; | ||
|
||
o.execute(mock, simConnectMock, mobiflightCacheMock, null, new List<ConfigRefValue>()); | ||
Assert.AreEqual(mobiflightCacheMock.GetMobiFlightVariable("VariableInputActionTests").Number, 1, "The number is not correct."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+346 Bytes
MobiFlightUnitTests/assets/MobiFlight/InputConfig/AnalogInputConfig/ReadXmlTest.1.xml
Binary file not shown.
Binary file added
BIN
+342 Bytes
MobiFlightUnitTests/assets/MobiFlight/InputConfig/AnalogInputConfig/WriteXmlTest.1.xml
Binary file not shown.
Binary file added
BIN
+320 Bytes
MobiFlightUnitTests/assets/MobiFlight/InputConfig/VariableInputAction/ReadXmlTest.1.xml
Binary file not shown.
Binary file added
BIN
+320 Bytes
MobiFlightUnitTests/assets/MobiFlight/InputConfig/VariableInputAction/WriteXmlTest.1.xml
Binary file not shown.