Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions ObjectSemantics.NET.Tests/BasicMappingTests.cs

This file was deleted.

52 changes: 0 additions & 52 deletions ObjectSemantics.NET.Tests/CharacterEscapingTests.cs

This file was deleted.

105 changes: 105 additions & 0 deletions ObjectSemantics.NET.Tests/CognitiveMapTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using ObjectSemantics.NET.Tests.MoqModels;
using System;
using System.Collections.Generic;
using Xunit;

namespace ObjectSemantics.NET.Tests
{
public class CognitiveMapTests
{
[Theory]
[InlineData("John Doe")]
[InlineData("Jane Doe")]
public void Library_Entry_Point_T_Extension_Should_Work(string personName)
{
Person person = new Person
{
Name = personName
};
string generatedTemplate = person.Map("I am {{ Name }}!");
Assert.Equal($"I am {personName}!", generatedTemplate);
}

[Theory]
[InlineData("John Doe")]
[InlineData("Jane Doe")]
public void Library_Entry_Point_String_Extension_Should_Work(string personName)
{
Person person = new Person
{
Name = personName
};
string generatedTemplate = "I am {{ Name }}!".Map(person);
Assert.Equal($"I am {personName}!", generatedTemplate);
}

[Fact]
public void Additional_Headers_Should_Also_Be_Mapped()
{
Person person = new Person
{
Name = "John Doe"
};

//additional params (outside the class)
Dictionary<string, object> additionalParams = new Dictionary<string, object>
{
{ "Occupation", "Developer"},
{ "DateOfBirth", new DateTime(1995, 01, 01) }
};

string generatedTemplate = "Name: {{ Name }} | Occupation: {{ Occupation }} | DOB: {{ DateOfBirth }}".Map(person, additionalParams);

Assert.Equal($"Name: {person.Name} | Occupation: {additionalParams["Occupation"]} | DOB: {additionalParams["DateOfBirth"]}", generatedTemplate);
}


[Theory]
[InlineData("I am {{ Name }}")]
[InlineData("I am {{ Name }}")]
[InlineData("I am {{ Name }}")]
[InlineData("I am {{Name}}")]
[InlineData("I am {{ Name }}")]
public void Whitespaces_Inside_Curl_Braces_Should_Be_Ignored(string template)
{
Person person = new Person
{
Name = "John Doe"
};
string generatedTemplate = person.Map(template);
Assert.Equal($"I am John Doe", generatedTemplate);
}

[Theory]
[InlineData("{{ MissingPropX }}", "{{ MissingPropX }}")]
[InlineData("{{ MissingProp123 }}", "{{ MissingProp123 }}")]
[InlineData("{{ UnknownPropertyXyz }}", "{{ UnknownPropertyXyz }}")] //it trims the excess whitespaces
[InlineData("{{ Unknown3x}}", "{{ Unknown3x }}")] //it trims the excess whitespaces
public void None_Existing_Properties_Should_Be_Returned_If_Not_Mapped(string template, string expected)
{
Person person = new Person
{
Name = "John Doe"
};
string generatedTemplate = person.Map(template);
Assert.Equal(expected, generatedTemplate);
}


[Theory]
[InlineData("I've got \"special\" < & also >", "I&apos;ve got &quot;special&quot; &lt; &amp; also &gt;")]
[InlineData("I've got < & also >", "I&apos;ve got &lt; &amp; also &gt;")]
public void Should_Escape_Xml_Char_Values_If_Option_Is_Enabled(string value, string expected)
{
Person person = new Person()
{
Name = value
};
string generatedTemplate = person.Map("{{ Name }}", null, new TemplateMapperOptions
{
XmlCharEscaping = true
});
Assert.Equal(expected, generatedTemplate);
}
}
}
63 changes: 63 additions & 0 deletions ObjectSemantics.NET.Tests/ComplexityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using ObjectSemantics.NET.Tests.MoqModels;
using System.Collections.Generic;
using Xunit;

namespace ObjectSemantics.NET.Tests
{
public class ComplexityTests
{

[Fact]
public void Should_Handle_ForEach_Loop_Inside_If_Block_Inline()
{
Person person = new Person
{
MyCars = new List<Car>
{
new Car { Make = "BMW" },
new Car { Make = "Rolls-Royce" }
}
};

string template = @"{{ #if(MyCars > 0) }}{{ #foreach(MyCars) }}[{{ Make }}]{{ #endforeach }}{{ #endif }}";

string result = person.Map(template);

string expected = "[BMW][Rolls-Royce]";
Assert.Equal(expected, result);
}


[Fact]
public void Should_Handle_ForEach_Loop_Inside_If_Block_Multiline()
{
Person person = new Person
{
MyCars = new List<Car>
{
new Car { Make = "Toyota" },
new Car { Make = "BMW" }
}
};

string template = @"
{{ #if(MyCars > 0) }}
{{ #foreach(MyCars) }}
- {{ Make:uppercase }}
{{ #endforeach }}
{{ #endif }}";

string result = person.Map(template);

string expected = @"


- TOYOTA

- BMW

";
Assert.Equal(expected, result);
}
}
}
Loading