/
SystemTextJsonExtensionTest.cs
52 lines (44 loc) · 1.9 KB
/
SystemTextJsonExtensionTest.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
41
42
43
44
45
46
47
48
49
50
51
52
using Developer.ExtensionCore;
using Developer.TestProject.FilesTest;
using System.Text.Json;
namespace Developer.TestProject
{
[TestClass]
public class SystemTextJsonExtensionTest
{
private readonly PersonTest _personTest;
private readonly PersonAddressTest _address;
private readonly List<PersonTelephoneTest> _phones;
private readonly JsonSerializerOptions _options;
public SystemTextJsonExtensionTest()
{
_address = new("Rua Teste", "123", "Brasil", "São Paulo", "SP");
_phones = new() { new PersonTelephoneTest("Cel", "123"), new PersonTelephoneTest("Res", "456") };
_personTest = new("Batman", 30, new List<string>() { "Combater o Crime", "Andar de Batmóvel" }, _address, _phones);
_options = new()
{
WriteIndented = true,
PropertyNameCaseInsensitive = true,
ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve
};
}
[TestMethod]
public void Test_ToSystemTextJsonSerializeJson()
{
string json = _personTest.ToSystemTextJsonSerializeJson();
Assert.IsTrue(json.IsNullOrEmptyOrWhiteSpace() == false);
json = _personTest.ToSystemTextJsonSerializeJson(_options);
Assert.IsTrue(json.IsNullOrEmptyOrWhiteSpace() == false);
}
[TestMethod]
public void Test_ToNewtonsoftDeserializeJson()
{
string json = _personTest.ToSystemTextJsonSerializeJson();
PersonTest personTest = json.ToSystemTextJsonDeserializeJson<PersonTest>();
Assert.IsTrue(personTest != null);
json = _personTest.ToSystemTextJsonSerializeJson(_options);
personTest = json.ToSystemTextJsonDeserializeJson<PersonTest>(_options);
Assert.IsTrue(personTest != null);
}
}
}