Skip to content

Commit 6b9f3d7

Browse files
committed
Got Rommar's tests in. Not sure how they got lost in the merge.
1 parent f92ee3d commit 6b9f3d7

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

AustinHarris.JsonRpcTestN/Test.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,32 @@ public void TestExtraParameters()
18551855
Assert.IsTrue(result.Result.Contains("\"code\":-32602"));
18561856
}
18571857

1858+
[Test()]
1859+
public void TestCustomParameterName()
1860+
{
1861+
Func<string, string> request = (string paramName) => String.Format("{{method:'TestCustomParameterName',params:{{ {0}:'some string'}},id:1}}", paramName);
1862+
string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}";
1863+
// Check custom param name specified in attribute works
1864+
var result = JsonRpcProcessor.Process(request("myCustomParameter"));
1865+
result.Wait();
1866+
Assert.AreEqual(JObject.Parse(expectedResult), JObject.Parse(result.Result));
1867+
// Check method can't be used with its actual parameter name
1868+
result = JsonRpcProcessor.Process(request("arg"));
1869+
result.Wait();
1870+
StringAssert.Contains("-32602", result.Result); // check for 'invalid params' error code
1871+
}
1872+
1873+
[Test()]
1874+
public void TestCustomParameterWithNoSpecificName()
1875+
{
1876+
Func<string, string> request = (string paramName) => String.Format("{{method:'TestCustomParameterWithNoSpecificName',params:{{ {0}:'some string'}},id:1}}", paramName);
1877+
string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}";
1878+
// Check method can be used with its parameter name
1879+
var result = JsonRpcProcessor.Process(request("arg"));
1880+
result.Wait();
1881+
Assert.AreEqual(JObject.Parse(expectedResult), JObject.Parse(result.Result));
1882+
}
1883+
18581884
[Test]
18591885
public void TestNestedReturnType()
18601886
{

AustinHarris.JsonRpcTestN/service.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ private string devideByZero(string s)
7979
return s + j / i;
8080
}
8181

82+
83+
[JsonRpcMethod]
84+
private bool TestCustomParameterName([JsonRpcParam("myCustomParameter")] string arg)
85+
{
86+
return true;
87+
}
88+
89+
[JsonRpcMethod]
90+
private bool TestCustomParameterWithNoSpecificName([JsonRpcParam] string arg)
91+
{
92+
return true;
93+
}
94+
8295
[JsonRpcMethod]
8396
private string StringToRefException(string s, ref JsonRpcException refException)
8497
{

0 commit comments

Comments
 (0)