forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackingFieldTests.cs
More file actions
75 lines (58 loc) · 1.54 KB
/
BackingFieldTests.cs
File metadata and controls
75 lines (58 loc) · 1.54 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
using System;
using NUnit.Framework;
namespace ServiceStack.Text.Tests.JsonTests
{
#region Test types
public class GetOnlyWithBacking
{
long backing;
public GetOnlyWithBacking(long i)
{
backing = i;
}
public long Property
{
get { return backing; }
}
}
public class GetSetWithBacking
{
long backing;
public GetSetWithBacking(long i)
{
Property = i;
}
public long Property
{
get { return backing; }
set { backing = value; }
}
}
#endregion
[TestFixture]
public class BackingFieldTests
{ [Test]
public void Backed_get_set_properties_can_be_deserialised()
{
var original = new GetSetWithBacking(123344044);
var str1 = original.ToJson();
var copy = str1.FromJson<GetSetWithBacking>();
Console.WriteLine(str1);
Assert.That(copy.Property, Is.EqualTo(original.Property));
}
[Ignore("By Design: Deserialization doesn't use constructor injection, Properties need to be writeable")]
[Test]
public void Backed_get_properties_can_be_deserialised()
{
var original = new GetOnlyWithBacking(123344044);
var str1 = original.ToJson();
var copy = str1.FromJson<GetOnlyWithBacking>();
Console.WriteLine(str1);
// ReflectionExtensions.cs Line 417 is being used to determine *deserialisable*
// for properties type based on if the property is *readable*, not *writable* -- by design
//Rule: To be emitted properties should be readable, to be deserialized properties should be writeable
Assert.That(copy.Property, Is.EqualTo(original.Property));
}
}
}