forked from sendgrid/sendgrid-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemplateDataSerialisationTests.cs
40 lines (33 loc) · 1.4 KB
/
TemplateDataSerialisationTests.cs
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
using Newtonsoft.Json;
using SendGrid.Helpers.Mail;
using Xunit;
namespace SendGrid.Tests
{
public class TemplateDataSerialisationTests
{
[Fact]
public void TestSetTemplateDataWorksWithSpecifiedJsonPropertyNames()
{
var msg = new SendGridMessage();
var dynamicTemplateData = new TestTemplateData
{
MyCamelCaseProperty = "camelCase",
MyKebabCaseProperty = "kebab-case",
MyPascalCaseProperty = "PascalCase",
MySnakeCaseProperty = "snake_case",
};
msg.SetTemplateData(dynamicTemplateData);
Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"myCamelCaseProperty\":\"camelCase\",\"my-kebab-case-property\":\"kebab-case\",\"MyPascalCaseProperty\":\"PascalCase\",\"my_snake_case_property\":\"snake_case\"}}]}", msg.Serialize());
}
private class TestTemplateData
{
[JsonProperty("myCamelCaseProperty")]
public string MyCamelCaseProperty { get; set; }
[JsonProperty("my-kebab-case-property")]
public string MyKebabCaseProperty { get; set; }
public string MyPascalCaseProperty { get; set; }
[JsonProperty("my_snake_case_property")]
public string MySnakeCaseProperty { get; set; }
}
}
}