forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializerTests.cs
More file actions
113 lines (89 loc) · 3.48 KB
/
SerializerTests.cs
File metadata and controls
113 lines (89 loc) · 3.48 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
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
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);
}
//TODO: test deserialize
}
}