forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerializerTests.cs
140 lines (110 loc) · 4.44 KB
/
SerializerTests.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
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
134
135
136
137
138
139
140
using System.Collections.Generic;
using NetCoreForce.Client;
using NetCoreForce.Client.Attributes;
using Newtonsoft.Json;
using Xunit;
namespace NetCoreForce.Client.Tests
{
public class SampleObject
{
[JsonProperty(PropertyName = "id")]
[Updateable(false), Createable(false)]
public string Id { get; set; }
[JsonProperty(PropertyName = "noAttributes")]
public string NoAttributes { get; set; }
[JsonProperty(PropertyName = "nullProperty")]
public string NullProperty { get { return null; } }
[JsonProperty(PropertyName = "createableTrue")]
[Createable(true)]
public string CreateableTrue { get; set; }
[JsonProperty(PropertyName = "createableFalse")]
[Createable(false)]
public string CreateableFalse { get; set; }
[JsonProperty(PropertyName = "updateableTrue")]
[Updateable(true)]
public string UpdateableTrue { get; set; }
[JsonProperty(PropertyName = "updateableFalse")]
[Updateable(false)]
public string UpdateableFalse { get; set; }
public SampleObject()
{
const string sampleValue = "sample value";
Id = sampleValue;
NoAttributes = sampleValue;
CreateableTrue = sampleValue;
CreateableFalse = sampleValue;
UpdateableTrue = sampleValue;
UpdateableFalse = sampleValue;
}
}
public class SerializerTests
{
const string IdPropertyTestString = "\"id\":";
[Fact]
public void SerializeForCreate()
{
string serialized = JsonSerializer.SerializeForCreate(new SampleObject());
Assert.DoesNotContain(IdPropertyTestString, serialized);
Assert.Contains("noAttributes", serialized);
Assert.Contains("createableTrue", serialized);
Assert.DoesNotContain("createableFalse", serialized);
}
[Fact]
public void SerializeForUpdate()
{
string serialized = JsonSerializer.SerializeForUpdate(new SampleObject());
Assert.DoesNotContain(IdPropertyTestString, serialized);
Assert.Contains("noAttributes", serialized);
Assert.Contains("updateableTrue", serialized);
Assert.DoesNotContain("updateableFalse", serialized);
}
[Fact]
public void SerializeForUpdateWithObjectId()
{
string serialized = JsonSerializer.SerializeForUpdateWithObjectId(new SampleObject());
Assert.Contains(IdPropertyTestString, serialized);
Assert.Contains("noAttributes", serialized);
Assert.Contains("updateableTrue", serialized);
Assert.DoesNotContain("updateableFalse", serialized);
}
[Fact]
public void NullValueHandlingForUpdate()
{
string serialized = JsonSerializer.SerializeForUpdate(new SampleObject());
Assert.DoesNotContain("nullProperty", serialized);
}
[Fact]
public void NullValueHandlingForUpdateWithObjectId()
{
string serialized = JsonSerializer.SerializeForUpdateWithObjectId(new SampleObject());
Assert.DoesNotContain("nullProperty", serialized);
}
[Fact]
public void NullValueHandlingForCreate()
{
string serialized = JsonSerializer.SerializeForCreate(new SampleObject());
Assert.DoesNotContain("nullProperty", serialized);
}
[Fact]
public void NullValueHandling_WithFieldsToNull_ForUpdate()
{
List<string> fieldsToNull = new List<string>(){ "nullProperty"};
string serialized = JsonSerializer.SerializeForUpdate(new SampleObject(), fieldsToNull);
Assert.Contains("nullProperty", serialized);
}
[Fact]
public void NullValueHandling_WithIgnoreNulls_ForUpdate()
{
string serialized = JsonSerializer.SerializeForUpdate(new SampleObject(), ignoreNulls: false);
Assert.Contains("nullProperty", serialized);
}
[Fact]
public void NullValueHandling_WithFieldsToNull_MixedCase_ForUpdate()
{
List<string> fieldsToNull = new List<string>(){ "NullProPertY"};
string serialized = JsonSerializer.SerializeForUpdate(new SampleObject(), fieldsToNull);
Assert.Contains("nullProperty", serialized);
}
//TODO: test deserialize
}
}