Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes testing with ConfigNodes by simplifying creating them
- Loading branch information
1 parent
a7f901e
commit be37f18
Showing
4 changed files
with
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections; | ||
|
||
namespace TestUtils | ||
{ | ||
public class TestConfigNode : ConfigNode, IEnumerable | ||
{ | ||
public TestConfigNode() : base() { } | ||
public TestConfigNode(string name) : base(name) { } | ||
|
||
public void Add(string name, string value) => AddValue(name, value); | ||
public void Add(string name, ConfigNode node) => AddNode(name, node); | ||
public void Add(ConfigNode node) => AddNode(node); | ||
|
||
public IEnumerator GetEnumerator() => throw new NotImplementedException(); | ||
} | ||
} |
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
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,62 @@ | ||
using System; | ||
using Xunit; | ||
using TestUtils; | ||
|
||
namespace TestUtilsTests | ||
{ | ||
public class TestConfigNodeTest | ||
{ | ||
[Fact] | ||
public void TestTestConfigNode() | ||
{ | ||
ConfigNode node = new TestConfigNode("NODE") | ||
{ | ||
{ "value1", "something" }, | ||
{ "value2", "something else" }, | ||
{ "multiple", "first" }, | ||
{ "multiple", "second" }, | ||
{ "NODE_1", new TestConfigNode | ||
{ | ||
{ "name", "something" }, | ||
{ "stuff", "something else" }, | ||
} | ||
}, | ||
new TestConfigNode("MULTIPLE") | ||
{ | ||
{ "value3", "blah" }, | ||
{ "value4", "bleh" }, | ||
}, | ||
new TestConfigNode("MULTIPLE") | ||
{ | ||
{ "value3", "blih" }, | ||
{ "value4", "bloh" }, | ||
}, | ||
}; | ||
|
||
Assert.Equal("something", node.GetValue("value1")); | ||
Assert.Equal("something else", node.GetValue("value2")); | ||
Assert.Equal(new[] { "first", "second" }, node.GetValues("multiple")); | ||
|
||
ConfigNode innerNode1 = node.GetNode("NODE_1"); | ||
Assert.NotNull(innerNode1); | ||
|
||
Assert.Equal("NODE_1", innerNode1.name); | ||
Assert.Equal("something", innerNode1.GetValue("name")); | ||
Assert.Equal("something else", innerNode1.GetValue("stuff")); | ||
|
||
ConfigNode[] innerNodes2 = node.GetNodes("MULTIPLE"); | ||
Assert.NotNull(innerNodes2); | ||
Assert.Equal(2, innerNodes2.Length); | ||
|
||
ConfigNode innerNode2a = innerNodes2[0]; | ||
Assert.NotNull(innerNode2a); | ||
Assert.Equal("blah", innerNode2a.GetValue("value3")); | ||
Assert.Equal("bleh", innerNode2a.GetValue("value4")); | ||
|
||
ConfigNode innerNode2b = innerNodes2[1]; | ||
Assert.NotNull(innerNode2b); | ||
Assert.Equal("blih", innerNode2b.GetValue("value3")); | ||
Assert.Equal("bloh", innerNode2b.GetValue("value4")); | ||
} | ||
} | ||
} |
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