Skip to content

Commit bf97f1f

Browse files
author
Martin Daetz
committed
add unit test
1 parent b9f435a commit bf97f1f

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

AustinHarris.JsonRpcTestN/Test.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,16 @@ public void TestExtraParameters()
18621862
Assert.IsTrue(result.Result.Contains("\"code\":-32602"));
18631863
}
18641864

1865+
[Test]
1866+
public void TestNestedReturnType()
1867+
{
1868+
var request = @"{""jsonrpc"":""2.0"",""method"":""TestNestedReturnType"",""id"":1}";
1869+
var expected = @"{""jsonrpc"":""2.0"",""result"":{""NodeId"":1,""Leafs"":[{""NodeId"":2,""Leafs"":[]},{""NodeId"":3,""Leafs"":[]}]},""id"":1}";
1870+
var result = JsonRpcProcessor.Process(request);
1871+
result.Wait();
1872+
Assert.AreEqual(expected, result.Result);
1873+
}
1874+
18651875
private static void AssertJsonAreEqual(string expectedJson, string actualJson)
18661876
{
18671877
Newtonsoft.Json.Linq.JObject expected = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(expectedJson);

AustinHarris.JsonRpcTestN/service.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
namespace AustinHarris.JsonRpcTestN
99
{
10+
public class TreeNode
11+
{
12+
public int NodeId { get; set; }
13+
14+
public IList<TreeNode> Leafs { get; set; }
15+
}
16+
1017
public class CalculatorService : JsonRpcService
1118
{
1219
[JsonRpcMethod]
@@ -354,5 +361,21 @@ public string TestPostProcessorSetsException(string inputValue)
354361
JsonRpcContext.SetException(new JsonRpcException(-27001, "This exception was thrown using: JsonRpcContext.SetException()", null));
355362
return null;
356363
}
364+
365+
[JsonRpcMethod]
366+
public TreeNode TestNestedReturnType()
367+
{
368+
return new TreeNode
369+
{
370+
NodeId = 1,
371+
Leafs =
372+
new[]
373+
{
374+
new TreeNode {NodeId = 2, Leafs = new List<TreeNode>()},
375+
new TreeNode {NodeId = 3, Leafs = new List<TreeNode>()}
376+
}
377+
};
378+
}
379+
357380
}
358381
}

0 commit comments

Comments
 (0)