Skip to content

Commit 491cf96

Browse files
authored
Merge pull request #18 from swagfin/optimized-engine
Optimized engine
2 parents 5b97a66 + 20478fc commit 491cf96

39 files changed

Lines changed: 1326 additions & 1213 deletions

ObjectSemantics.NET.Tests/BasicMappingTests.cs

Lines changed: 0 additions & 92 deletions
This file was deleted.

ObjectSemantics.NET.Tests/CharacterEscapingTests.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using ObjectSemantics.NET.Tests.MoqModels;
2+
using System;
3+
using System.Collections.Generic;
4+
using Xunit;
5+
6+
namespace ObjectSemantics.NET.Tests
7+
{
8+
public class CognitiveMapTests
9+
{
10+
[Theory]
11+
[InlineData("John Doe")]
12+
[InlineData("Jane Doe")]
13+
public void Library_Entry_Point_T_Extension_Should_Work(string personName)
14+
{
15+
Person person = new Person
16+
{
17+
Name = personName
18+
};
19+
string generatedTemplate = person.Map("I am {{ Name }}!");
20+
Assert.Equal($"I am {personName}!", generatedTemplate);
21+
}
22+
23+
[Theory]
24+
[InlineData("John Doe")]
25+
[InlineData("Jane Doe")]
26+
public void Library_Entry_Point_String_Extension_Should_Work(string personName)
27+
{
28+
Person person = new Person
29+
{
30+
Name = personName
31+
};
32+
string generatedTemplate = "I am {{ Name }}!".Map(person);
33+
Assert.Equal($"I am {personName}!", generatedTemplate);
34+
}
35+
36+
[Fact]
37+
public void Additional_Headers_Should_Also_Be_Mapped()
38+
{
39+
Person person = new Person
40+
{
41+
Name = "John Doe"
42+
};
43+
44+
//additional params (outside the class)
45+
Dictionary<string, object> additionalParams = new Dictionary<string, object>
46+
{
47+
{ "Occupation", "Developer"},
48+
{ "DateOfBirth", new DateTime(1995, 01, 01) }
49+
};
50+
51+
string generatedTemplate = "Name: {{ Name }} | Occupation: {{ Occupation }} | DOB: {{ DateOfBirth }}".Map(person, additionalParams);
52+
53+
Assert.Equal($"Name: {person.Name} | Occupation: {additionalParams["Occupation"]} | DOB: {additionalParams["DateOfBirth"]}", generatedTemplate);
54+
}
55+
56+
57+
[Theory]
58+
[InlineData("I am {{ Name }}")]
59+
[InlineData("I am {{ Name }}")]
60+
[InlineData("I am {{ Name }}")]
61+
[InlineData("I am {{Name}}")]
62+
[InlineData("I am {{ Name }}")]
63+
public void Whitespaces_Inside_Curl_Braces_Should_Be_Ignored(string template)
64+
{
65+
Person person = new Person
66+
{
67+
Name = "John Doe"
68+
};
69+
string generatedTemplate = person.Map(template);
70+
Assert.Equal($"I am John Doe", generatedTemplate);
71+
}
72+
73+
[Theory]
74+
[InlineData("{{ MissingPropX }}", "{{ MissingPropX }}")]
75+
[InlineData("{{ MissingProp123 }}", "{{ MissingProp123 }}")]
76+
[InlineData("{{ UnknownPropertyXyz }}", "{{ UnknownPropertyXyz }}")] //it trims the excess whitespaces
77+
[InlineData("{{ Unknown3x}}", "{{ Unknown3x }}")] //it trims the excess whitespaces
78+
public void None_Existing_Properties_Should_Be_Returned_If_Not_Mapped(string template, string expected)
79+
{
80+
Person person = new Person
81+
{
82+
Name = "John Doe"
83+
};
84+
string generatedTemplate = person.Map(template);
85+
Assert.Equal(expected, generatedTemplate);
86+
}
87+
88+
89+
[Theory]
90+
[InlineData("I've got \"special\" < & also >", "I&apos;ve got &quot;special&quot; &lt; &amp; also &gt;")]
91+
[InlineData("I've got < & also >", "I&apos;ve got &lt; &amp; also &gt;")]
92+
public void Should_Escape_Xml_Char_Values_If_Option_Is_Enabled(string value, string expected)
93+
{
94+
Person person = new Person()
95+
{
96+
Name = value
97+
};
98+
string generatedTemplate = person.Map("{{ Name }}", null, new TemplateMapperOptions
99+
{
100+
XmlCharEscaping = true
101+
});
102+
Assert.Equal(expected, generatedTemplate);
103+
}
104+
}
105+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using ObjectSemantics.NET.Tests.MoqModels;
2+
using System.Collections.Generic;
3+
using Xunit;
4+
5+
namespace ObjectSemantics.NET.Tests
6+
{
7+
public class ComplexityTests
8+
{
9+
10+
[Fact]
11+
public void Should_Handle_ForEach_Loop_Inside_If_Block_Inline()
12+
{
13+
Person person = new Person
14+
{
15+
MyCars = new List<Car>
16+
{
17+
new Car { Make = "BMW" },
18+
new Car { Make = "Rolls-Royce" }
19+
}
20+
};
21+
22+
string template = @"{{ #if(MyCars > 0) }}{{ #foreach(MyCars) }}[{{ Make }}]{{ #endforeach }}{{ #endif }}";
23+
24+
string result = person.Map(template);
25+
26+
string expected = "[BMW][Rolls-Royce]";
27+
Assert.Equal(expected, result);
28+
}
29+
30+
31+
[Fact]
32+
public void Should_Handle_ForEach_Loop_Inside_If_Block_Multiline()
33+
{
34+
Person person = new Person
35+
{
36+
MyCars = new List<Car>
37+
{
38+
new Car { Make = "Toyota" },
39+
new Car { Make = "BMW" }
40+
}
41+
};
42+
43+
string template = @"
44+
{{ #if(MyCars > 0) }}
45+
{{ #foreach(MyCars) }}
46+
- {{ Make:uppercase }}
47+
{{ #endforeach }}
48+
{{ #endif }}";
49+
50+
string result = person.Map(template);
51+
52+
string expected = @"
53+
54+
55+
- TOYOTA
56+
57+
- BMW
58+
59+
";
60+
Assert.Equal(expected, result);
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)