Skip to content

Commit

Permalink
#5 XUnit tests
Browse files Browse the repository at this point in the history
- Refactor test method names to snake case
  • Loading branch information
araszka committed May 29, 2023
1 parent 1f7f30d commit 176e439
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 44 deletions.
46 changes: 23 additions & 23 deletions tests/ManiaTemplates.Tests/Components/MtComponentAttributesTest.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using ManiaTemplates.Components;

namespace ManiaTemplates.Tests.Components;

public class MtComponentAttributesTest
{
private readonly MtComponentAttributes _mtComponentAttributes = new();

public MtComponentAttributesTest()
{
_mtComponentAttributes["key"] = "value";
Assert.Single(_mtComponentAttributes);
}

[Fact]
public void ShouldRemoveExisting()
{
var result = _mtComponentAttributes.Pull("key");

Assert.Equal("value", result);
Assert.Empty(_mtComponentAttributes);
}
}
using ManiaTemplates.Components;

namespace ManiaTemplates.Tests.Components;

public class MtComponentAttributesTest
{
private readonly MtComponentAttributes _mtComponentAttributes = new();

public MtComponentAttributesTest()
{
_mtComponentAttributes["key"] = "value";
Assert.Single(_mtComponentAttributes);
}

[Fact]
public void Should_Remove_Existing()
{
var result = _mtComponentAttributes.Pull("key");

Assert.Equal("value", result);
Assert.Empty(_mtComponentAttributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public MtComponentMapTest()
}

[Fact]
public void ShouldOverloadEntries()
public void Should_Overload_Entries()
{
var test = new MtComponentImport { Tag = "test", TemplateKey = "test" };
var entry = new MtComponentImport { Tag = "entry", TemplateKey = "entry" };
Expand Down
14 changes: 7 additions & 7 deletions tests/ManiaTemplates.Tests/Components/MtComponentScriptTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MtComponentScriptTest()
[InlineData("<script resource='res' main=''/>", true, false)]
[InlineData("<script resource='res' once=''/>", false, true)]
[InlineData("<script resource='res' main='' once=''/>", true, true)]
public void ShouldLoadManiaScript(string input, bool expectedMain, bool expectedOnce)
public void Should_Load_ManiaScript(string input, bool expectedMain, bool expectedOnce)
{
var document = new XmlDocument();
document.LoadXml(input);
Expand All @@ -35,7 +35,7 @@ public void ShouldLoadManiaScript(string input, bool expectedMain, bool expected
[Theory]
[InlineData("<script/>")]
[InlineData("<script main='false' once='true' />")]
public void ShouldFailToLoadEmptyManiaScript(string input)
public void Should_Fail_To_Load_Empty_ManiaScript(string input)
{
var document = new XmlDocument();
document.LoadXml(input);
Expand All @@ -45,16 +45,16 @@ public void ShouldFailToLoadEmptyManiaScript(string input)
}

[Fact]
public void ScriptsWithDifferentContentDifferentHashCodes()
public void Should_Load_ManiaScript_With_Different_Hash_Codes()
{
const string Input1 = "<script>a</script>";
const string firstInput = "<script>a</script>";
var document1 = new XmlDocument();
document1.LoadXml(Input1);
document1.LoadXml(firstInput);
var script1 = MtComponentScript.FromNode(_templateEngine, document1.DocumentElement!);

const string Input2 = "<script resource='res'/>";
const string secondInput = "<script resource='res'/>";
var document2 = new XmlDocument();
document2.LoadXml(Input2);
document2.LoadXml(secondInput);
var script2 = MtComponentScript.FromNode(_templateEngine, document2.DocumentElement!);

Assert.NotEqual(script1, script2);
Expand Down
18 changes: 10 additions & 8 deletions tests/ManiaTemplates.Tests/Components/MtComponentTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Reflection;
using FluentAssertions;
using ManiaTemplates.Components;
using ManiaTemplates.Exceptions;

namespace ManiaTemplates.Tests.Components;

Expand All @@ -10,9 +9,10 @@ public class MtComponentTest
private readonly ManiaTemplateEngine _engine = new();

[Fact]
public void ShouldReadEmptyTemplate()
public void Should_Read_Empty_Template()
{
const string Component = "<component/>";
const string component = "<component/>";

var expected = new MtComponent
{
Namespaces = new(),
Expand All @@ -23,15 +23,15 @@ public void ShouldReadEmptyTemplate()
TemplateContent = ""
};

var result = MtComponent.FromTemplate(_engine, Component);
var result = MtComponent.FromTemplate(_engine, component);

result.Should().BeEquivalentTo(expected);
}

[Fact]
public void ShouldPopulatedTemplate()
public void Should_Populate_Template()
{
const string Component = """
const string component = """
<component>
<property type="int" name="number" default="0"/>
<property type="string" name="text"/>
Expand All @@ -52,8 +52,10 @@ public void ShouldPopulatedTemplate()
<script>scriptText3</script>
</component>
""";

_engine.GetType().GetField("_maniaScripts", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(_engine,
new Dictionary<string, string> { { "res", "resourceScript" } });

var expected = new MtComponent
{
Namespaces = new() { "namespace" },
Expand All @@ -79,7 +81,7 @@ public void ShouldPopulatedTemplate()
TemplateContent = @"<node attr=""value"" /><slot />"
};

var result = MtComponent.FromTemplate(_engine, Component);
var result = MtComponent.FromTemplate(_engine, component);

result.Should().BeEquivalentTo(expected);
}
Expand All @@ -89,7 +91,7 @@ public void ShouldPopulatedTemplate()
[InlineData(@"<property type=""int""/>", "property", "name")]
[InlineData(@"<import/>", "import", "component")]
[InlineData(@"<using/>", "using", "namespace")]
public void ShouldNotReadTemplateMissingAttributes(string content, string nodeName, string attributeName)
public void Should_Not_Read_Template_Missing_Attributes(string content, string nodeName, string attributeName)
{
var component = $"<component>{content}</component>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ public class ManialinkEngineTest

[Theory]
[ClassData(typeof(TestDataProvider))]
public void ShouldConvertTemplatesToResult(string template, dynamic data, string expected)
public void Should_Convert_Templates_To_Result(string template, dynamic data, string expected)
{
_maniaTemplateEngine.AddTemplateFromString("test", template);
_maniaTemplateEngine.PreProcess("test", new[] { typeof(ManiaTemplateEngine).Assembly });

var result = _maniaTemplateEngine.Render("test", data, new[] { typeof(ManiaTemplateEngine).Assembly });

Assert.Equal(expected, result, ignoreWhiteSpaceDifferences: true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections;
using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;

namespace ManiaTemplates.Tests.IntegrationTests;

Expand Down
4 changes: 2 additions & 2 deletions tests/ManiaTemplates.Tests/Lib/MtTransformerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MtTransformerTest()
}

[Fact]
public void ShouldBuildManialink()
public void Should_Build_Manialink()
{
var components = new Dictionary<string, MtComponent>
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public void ShouldBuildManialink()
Assert.Equal(expected, StripLineBreaks(TransformCodeToOrderNumber(result)));
}

private string StripLineBreaks(string input)
private static string StripLineBreaks(string input)
{
return input.Replace("\r", "").Replace("\n", "");
}
Expand Down

0 comments on commit 176e439

Please sign in to comment.