This repository was archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDeserializationTests.cs
125 lines (107 loc) · 3.41 KB
/
DeserializationTests.cs
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
114
115
116
117
118
119
120
121
122
123
124
125
namespace CypherNet.UnitTests
{
#region
using System;
using System.Linq;
using Graph;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Queries;
using Serialization;
#endregion
[TestClass]
public class SerializationTests
{
#region JSON Constants
const string Json =
@"{
""commit"":""http://localhost:7474/db/data/transaction/6/commit"",
""results"":[
{
""columns"":[
""Actor"",
""Actor__Id"",
""Actor__Labels"",
""ActedIn"",
""ActedIn__Id"",
""ActedIn__Type"",
""Movie"",
""Movie__Id"",
""Movie__Labels""
],
""data"":[{ ""row"":
[
{
""age"":33,
""name"":""mark""
},
3745,
[""person""],
{
},
39490,
""IS_A"",
{
""title"":""developer""
},
3746,
[]
]},{""row"":[
{
""age"":21,
""name"":""John""
},
3747,
[""person""],
{
},
39491,
""IS_A"",
{
""title"":""leg""
},
3748,
[]
]}
]
}
],
""transaction"":{
""expires"":""Tue, 30 Jul 2013 15:57:59 +0000""
},
""errors"":[
]
}";
const string ErrorJson = @"{""results"":[],""errors"":[{""code"":""Neo.ClientError.Statement.InvalidSyntax"",""message"":""Invalid input 's': expected whitespace, comment, , '.', node labels, '[', \""=~\"", IN, IS, '*', '/', '%', '^', '+', '-', '<', '>', \""<=\"", \"">=\"", '=', \""<>\"", \""!=\"", AND, XOR, OR or ')' (line 1, column 36)\n\""START Node=node(1) WHERE (Node.aaa sss ddd = 1) RETURN Node as Node, id(Node) as Node__Id, labels(Node) as Node__Labels\""\n ^""}]}";
#endregion
[TestMethod]
public void DerializeJson_EntitiesOnly_ReturnsCollectionOfEntities()
{
var deserializer = new DefaultJsonSerializer(new DictionaryEntityCache());
var retval = deserializer.Deserialize<CypherResponse<DeserializationTestClass>>(Json);
Assert.AreEqual(retval.Results.Count(), 2);
dynamic actor = retval.Results.Select(r => r.Actor).First();
Assert.AreEqual(actor.age, 33);
Assert.AreEqual(actor.name, "mark");
}
[TestMethod]
public void DerializeJson_WithNeoErrors_ReturnsErrors()
{
var deserializer = new DefaultJsonSerializer(new DictionaryEntityCache());
var retval = deserializer.Deserialize<CypherResponse<DeserializationTestClass>>(ErrorJson);
Assert.IsNull(retval.Results);
Assert.IsTrue(retval.Errors.Any());
}
}
public class DeserializationTestClass
{
public DeserializationTestClass(Node actor, Relationship actedIn, Node movie)
{
Actor = actor;
ActedIn = actedIn;
Movie = movie;
}
public Node Actor { get; set; }
public Relationship ActedIn { get; set; }
public Node Movie { get; set; }
}
}