-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCognitiveMapTests.cs
More file actions
105 lines (94 loc) · 3.7 KB
/
CognitiveMapTests.cs
File metadata and controls
105 lines (94 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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've got "special" < & also >")]
[InlineData("I've got < & also >", "I've got < & also >")]
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);
}
}
}