-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCognitiveMapTests.cs
More file actions
133 lines (116 loc) · 4.82 KB
/
CognitiveMapTests.cs
File metadata and controls
133 lines (116 loc) · 4.82 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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);
}
[Fact]
public void Additional_Headers_And_Class_Properties_Should_Also_Be_Mapped_Combined()
{
Payment payment = new Payment
{
Id = 1,
Amount = 1000,
PayMethod = "CHEQUE",
PayMethodId = 2,
ReferenceNo = "CHEQUE0001",
UserId = 242
};
//additional params (outside the class)
Dictionary<string, object> additionalParams = new Dictionary<string, object>
{
{ "ReceivedBy", "John Doe"},
{ "NewBalance", 1050 }
};
string generatedTemplate = payment.Map("{{Id}}-{{ ReferenceNo }} Confirmed. ${{ Amount:N2 }} received via {{ PayMethod }}({{PayMethodId}}) from user-id {{ UserId }}. New Balance: {{ NewBalance:N2 }}, Received By: {{ReceivedBy}}.", additionalParams);
string expectedResponse = "1-CHEQUE0001 Confirmed. $1,000.00 received via CHEQUE(2) from user-id 242. New Balance: 1,050.00, Received By: John Doe.";
Assert.Equal(generatedTemplate, expectedResponse);
}
}
}