Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 5371b14

Browse files
committed
Add Test verifying setters are only called for properties in JSON
1 parent fbcd507 commit 5371b14

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/ServiceStack.Text.Tests/JsonObjectTests.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.Collections.Generic;
2+
using System.Linq;
23
using NUnit.Framework;
34

45
namespace ServiceStack.Text.Tests
@@ -128,5 +129,42 @@ public void Can_deserialize_JSON_Object()
128129
Assert.That(items["value"], Is.EqualTo("val1"));
129130
Assert.That(items["type"], Is.EqualTo("val2"));
130131
}
132+
133+
public class Customer
134+
{
135+
public static List<object> Setters = new List<object>();
136+
137+
private string name;
138+
private int age;
139+
private string address;
140+
141+
public string Name
142+
{
143+
get { return name; }
144+
set { name = value; Setters.Add(value); }
145+
}
146+
147+
public int Age
148+
{
149+
get { return age; }
150+
set { age = value; Setters.Add(value); }
151+
}
152+
153+
public string Address
154+
{
155+
get { return address; }
156+
set { address = value; Setters.Add(value); }
157+
}
158+
}
159+
160+
[Test]
161+
public void Only_sets_Setters_with_JSON()
162+
{
163+
var dto = "{\"Name\":\"Foo\"}".FromJson<Customer>();
164+
165+
Assert.That(dto.Name, Is.EqualTo("Foo"));
166+
Assert.That(Customer.Setters.Count, Is.EqualTo(1));
167+
Assert.That(Customer.Setters[0], Is.EqualTo(dto.Name));
168+
}
131169
}
132170
}

0 commit comments

Comments
 (0)