Skip to content

Commit

Permalink
Add NamespaceProvider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Nov 5, 2015
1 parent 03299e1 commit 99b82b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace XmlSchemaClassGenerator.Tests
{
public class NamespaceProviderTests
{
[Fact]
public void ContainsKeyTest()
{
var ns = new NamespaceProvider { { new NamespaceKey("x"), "c" } };
ns.GenerateNamespace = k => k.XmlSchemaNamespace != "z" ? k.XmlSchemaNamespace : null;
AssertEx.CollectionEqual(ns.Values.ToArray(), new[] { "c" });
Assert.True(ns.ContainsKey(new NamespaceKey("x")));
Assert.True(ns.ContainsKey(new NamespaceKey("y")));
Assert.True(ns.ContainsKey(new NamespaceKey("y")));
Assert.False(ns.ContainsKey(new NamespaceKey("z")));
ns.Clear();
Assert.Equal(0, ns.Count);
}

[Fact]
public void KeysTest()
{
var ns = new NamespaceProvider { { new NamespaceKey("x"), "c" }, { new NamespaceKey("y"), "d" } };
ns.Remove(new NamespaceKey("y"));
AssertEx.CollectionEqual(ns.Keys.ToArray(), new[] { new NamespaceKey("x") });
}

[Fact]
public void IndexTest()
{
var ns = new NamespaceProvider();
ns[new NamespaceKey("x")] = "c";
ns.GenerateNamespace = k => k.XmlSchemaNamespace != "z" ? k.XmlSchemaNamespace : null;
Assert.Equal(ns[new NamespaceKey("x")], "c");
Assert.Equal(ns[new NamespaceKey("y")], "y");
Assert.Equal(ns[new NamespaceKey("y")], "y");
Assert.Throws<KeyNotFoundException>(() => ns[new NamespaceKey("z")]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="AssertEx.cs" />
<Compile Include="generated\Types.generated.cs" />
<Compile Include="Glob.cs" />
<Compile Include="NamespaceProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestPriority.cs" />
<Compile Include="XsdElsterDatenabholung5.cs" />
Expand Down

0 comments on commit 99b82b3

Please sign in to comment.