forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflectionExtensionTests.cs
More file actions
86 lines (70 loc) · 2.68 KB
/
Copy pathReflectionExtensionTests.cs
File metadata and controls
86 lines (70 loc) · 2.68 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace ServiceStack.Text.Tests
{
public class TestModel
{
public TestModel()
{
var i = 0;
this.PublicInt = i++;
this.PublicGetInt = i++;
this.PublicSetInt = i++;
this.PublicIntField = i++;
this.PrivateInt = i++;
this.ProtectedInt = i++;
}
public int PublicInt { get; set; }
public int PublicGetInt { get; private set; }
public int PublicSetInt { private get; set; }
public int PublicIntField;
private int PrivateInt { get; set; }
protected int ProtectedInt { get; set; }
public int IntMethod()
{
return this.PublicInt;
}
}
[TestFixture]
public class ReflectionExtensionTests
: TestBase
{
[Test]
public void Only_serializes_public_readable_properties()
{
var model = new TestModel();
var modelStr = TypeSerializer.SerializeToString(model);
Assert.That(modelStr, Is.EqualTo("{PublicInt:0,PublicGetInt:1}"));
Serialize(model);
}
[Test]
public void Can_create_instances_of_common_collections()
{
Assert.That(typeof(IEnumerable<TestModel>).CreateInstance() as IEnumerable<TestModel>, Is.Not.Null);
Assert.That(typeof(ICollection<TestModel>).CreateInstance() as ICollection<TestModel>, Is.Not.Null);
Assert.That(typeof(IList<TestModel>).CreateInstance() as IList<TestModel>, Is.Not.Null);
Assert.That(typeof(IDictionary<string, TestModel>).CreateInstance() as IDictionary<string, TestModel>, Is.Not.Null);
Assert.That(typeof(IDictionary<int, TestModel>).CreateInstance() as IDictionary<int, TestModel>, Is.Not.Null);
Assert.That(typeof(TestModel[]).CreateInstance() as TestModel[], Is.Not.Null);
}
[Test]
public void Can_create_intances_of_generic_types()
{
Assert.That(typeof(GenericType<>).CreateInstance(), Is.Not.Null);
Assert.That(typeof(GenericType<,>).CreateInstance(), Is.Not.Null);
Assert.That(typeof(GenericType<,,>).CreateInstance(), Is.Not.Null);
Assert.That(typeof(GenericType<GenericType<object>>).CreateInstance(), Is.Not.Null);
}
[Test]
public void Can_create_intances_of_recursive_generic_type()
{
//Assert.That(typeof(GenericType<>).MakeGenericType(new[] { typeof(GenericType<>) }).CreateInstance(), Is.Not.Null);
}
}
public class GenericType<T> { }
public class GenericType<T1, T2> { }
public class GenericType<T1, T2, T3> { }
}