Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Copyright>Austin Harris</Copyright>
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>


Expand Down
12 changes: 12 additions & 0 deletions AustinHarris.JsonRpcTestN/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,18 @@ public void TestOptionalParametersBoolsAndStrings()
Assert.IsFalse(result.Result.Contains("error"));
Assert.AreEqual(expectedResult, result.Result);
}

[TestCase("{method:\"TestDifferentOptionalParameters\",params:{location:\"loc1\", uid:\"abc123\", wavelengths: [0.0], traces: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")]
[TestCase("{method:\"TestDifferentOptionalParameters\",params:{uid:\"abc123\", wavelengths: [0.0], traces: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")]
[TestCase("{method:\"TestDifferentOptionalParameters\",params:{location:\"loc1\", uid:\"abc123\", traces: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")]
[TestCase("{method:\"TestDifferentOptionalParameters\",params:{location:\"loc1\", uid:\"abc123\", wavelengths: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")]
[TestCase("{method:\"TestDifferentOptionalParameters\",params:{uid:\"abc123\", wavelengths: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")]
public string TestDifferentOptionalParametersNamedWorking(string request)
{
var result = JsonRpcProcessor.Process(request);
result.Wait();
return result.Result;
}

[Test()]
public void TestBatchResultWrongRequests()
Expand Down
6 changes: 6 additions & 0 deletions AustinHarris.JsonRpcTestN/service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ public TreeNode TestNestedReturnType()
}
};
}

[JsonRpcMethod]
private string TestDifferentOptionalParameters(string uid, string location = null, List<float> traces = null, List<float> wavelengths = null)
{
return "this is the requested measurement";
}

}
}
8 changes: 8 additions & 0 deletions Json-Rpc/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null)
}
else
{
var foundDefault = metadata.defaultValues
.FirstOrDefault(defaul => defaul.Name == metadata.parameters[i].Name);
if (foundDefault != null)
{
parameters[i] = foundDefault.Value;
continue;
}

JsonResponse response = new JsonResponse()
{
Error = ProcessException(Rpc,
Expand Down