forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyValueDataContractDeserializerTests.cs
More file actions
87 lines (76 loc) · 3.27 KB
/
Copy pathKeyValueDataContractDeserializerTests.cs
File metadata and controls
87 lines (76 loc) · 3.27 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
using System.Collections.Generic;
using NUnit.Framework;
using ServiceStack.Common;
using ServiceStack.Serialization;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints.Tests.Support.Operations;
namespace ServiceStack.WebHost.Endpoints.Tests
{
[TestFixture]
public class KeyValueDataContractDeserializerTests
{
[Test]
public void Can_Create_RequestOfAllTypes_from_string_map()
{
var request = RequestOfAllTypes.Create(1);
var map = new Dictionary<string, string> {
{"Byte",request.Byte.ToString()},
{"Char",request.Char.ToString()},
{"DateTime",request.DateTime.ToShortestXsdDateTimeString()},
{"Decimal",request.Decimal.ToString()},
{"Double",request.Double.ToString()},
{"Float",request.Float.ToString()},
{"Guid",request.Guid.ToString()},
{"Int",request.Int.ToString()},
{"Long",request.Long.ToString()},
{"Short",request.Short.ToString()},
{"String",request.String},
{"TimeSpan",request.TimeSpan.ToString()},
{"UInt",request.UInt.ToString()},
{"ULong",request.ULong.ToString()},
};
var toRequest = KeyValueDataContractDeserializer.Instance.Parse(map, typeof(RequestOfAllTypes));
Assert.That(request.Equals(toRequest), Is.True);
}
[Test]
public void Can_Create_RequestOfAllTypes_from_partial_string_map()
{
var request = RequestOfAllTypes.Create(1);
var map = new Dictionary<string, string> {
{"Byte",request.Byte.ToString()},
{"DateTime",request.DateTime.ToShortestXsdDateTimeString()},
{"Double",request.Double.ToString()},
{"Guid",request.Guid.ToString()},
{"Long",request.Long.ToString()},
{"String",request.String},
{"UInt",request.UInt.ToString()},
};
var toRequest = (RequestOfAllTypes)KeyValueDataContractDeserializer.Instance
.Parse(map, typeof(RequestOfAllTypes));
Assert.That(toRequest.Byte, Is.EqualTo(request.Byte));
Assert.That(toRequest.DateTime, Is.EqualTo(request.DateTime));
Assert.That(toRequest.Double, Is.EqualTo(request.Double));
Assert.That(toRequest.Guid, Is.EqualTo(request.Guid));
Assert.That(toRequest.Long, Is.EqualTo(request.Long));
Assert.That(toRequest.String, Is.EqualTo(request.String));
Assert.That(toRequest.UInt, Is.EqualTo(request.UInt));
}
[Test]
public void Can_Create_RequestOfComplexTypes_from_string_map()
{
var request = RequestOfComplexTypes.Create(1);
var map = new Dictionary<string, string> {
{"IntArray",request.IntArray.Join()},
{"IntList",request.IntList.Join()},
{"IntMap",request.IntMap.Join()},
{"StringArray",request.StringArray.Join()},
{"StringList",request.StringList.Join()},
{"StringMap",request.StringMap.Join()},
{"StringIntMap",request.StringIntMap.Join()},
{"RequestOfAllTypes",TypeSerializer.SerializeToString(request.RequestOfAllTypes)},
};
var toRequest = KeyValueDataContractDeserializer.Instance.Parse(map, typeof(RequestOfComplexTypes));
Assert.That(request.Equals(toRequest), Is.True);
}
}
}