Repository navigation
Expand file tree
/
Copy pathNetJSONTest.cs
More file actions
60 lines (53 loc) · 1.81 KB
/
Copy pathNetJSONTest.cs
File metadata and controls
60 lines (53 loc) · 1.81 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
#nullable enable
using System.Collections.Generic;
using System.IO;
using Xunit;
namespace NetJSON.Net9_0.Tests
{
public class Person
{
public int Id { get; set; }
public List<Address> Addresses { get; set; } // basically any class type
}
public class Address
{
public int Id { get; set; } = 1;
}
public class NetJSONTest
{
[Fact]
public void Test1()
{
var jsonString = "{\"All\":{\"ym\":\"ss\"},\"ervicesAuto\":{\"ym\":\"ss\"},\"ocessor\":{\"\":\"ss\"},\"sonalDevice\":{\"\":\"ss\"},\"rryCan\":{\"\":\"ss\"},\"licom\":{\"ymr\":\"ss\"}}";
var result = NetJSON.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonString);
Assert.True(result.ContainsKey("All") && result["All"].ContainsKey("ym") && result["All"]["ym"].Equals("ss"));
}
[Fact]
public void TestNullValueInArrayShouldBeSkipped()
{
var p = new Person()
{
Id = 1,
Addresses = new List<Address> { new Address(), null, new Address() }
};
var json = NetJSON.Serialize(p);
var p2 = NetJSON.Deserialize<Person>(json);
Assert.True(p2.Addresses.Count == 3);
}
[Fact]
public void TestForNullShouldNotThrowInvalidJson()
{
Person nullModel = null;
var json = NetJSON.Serialize(nullModel, NetJSONSettings.CurrentSettings);
var result = NetJSON.Deserialize<Person>(json);
Assert.Null(result);
}
[Fact]
public void TestForNullabeShouldNotThrowNullException()
{
Stream? nullableModal = null;
var json = NetJSON.Serialize(nullableModal);
Assert.Equal("null", json);
}
}
}