|
| 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've got "special" < & also >")] |
| 91 | + [InlineData("I've got < & also >", "I've got < & also >")] |
| 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 | +} |
0 commit comments