Skip to content

Commit

Permalink
Add TestConfigNode class
Browse files Browse the repository at this point in the history
Makes testing with ConfigNodes by simplifying creating them
  • Loading branch information
blowfishpro committed Sep 2, 2017
1 parent a7f901e commit be37f18
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
17 changes: 17 additions & 0 deletions TestUtils/TestConfigNode.cs
@@ -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();
}
}
3 changes: 2 additions & 1 deletion TestUtils/TestUtils.csproj
Expand Up @@ -41,6 +41,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestConfigNode.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
62 changes: 62 additions & 0 deletions TestUtilsTests/TestConfigNodeTest.cs
@@ -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"));
}
}
}
1 change: 1 addition & 0 deletions TestUtilsTests/TestUtilsTests.csproj
Expand Up @@ -48,6 +48,7 @@
<ItemGroup>
<Compile Include="DummyTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestConfigNodeTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down

0 comments on commit be37f18

Please sign in to comment.