public void ReturnStringArray() { Response <object> reply = default; var handler = new TestHandlerFake(); var server = new JsonRpcServer(); var clientMock = new Mock <JsonRpcServer.ClientConnection>(1, "localhost", _fakePipe, _process, Encoding.UTF8); clientMock.Setup(x => x.WriteAsJson(It.IsAny <object>())).Callback <object>(o => reply = (Response <object>)o); var reqOring = new Request() { Id = 3, Method = "ReturnStringArray" }; var json = Serializer.Serialize(reqOring); var req = Serializer.Deserialize <Request>(json); server.Bind(handler); server.ExecuteHandler(clientMock.Object, req.Id, req.Method, req.Params); reply.Should().NotBeNull(); reply.Id.Should().Be(3); reply.Error.Should().BeNull(); reply.Result.Should().BeEquivalentTo(new string[] { "one", "two", "three" }); }
public void Call_GivenDateTime() { Response reply = default; var handler = new TestHandlerFake(); var server = new JsonRpcServer(); var clientMock = new Mock <JsonRpcServer.ClientConnection>(1, "localhost", _fakePipe, _process, Encoding.UTF8); clientMock.Setup(x => x.WriteAsJson(It.IsAny <object>())).Callback <object>(o => reply = (Response)o); var now = DateTime.Now; var reqOring = new Request() { Id = 81, Method = "DateTimeTest", Params = new object[] { now } }; var json = Serializer.Serialize(reqOring); var req = Serializer.Deserialize <Request>(json); server.Bind(handler); server.ExecuteHandler(clientMock.Object, req.Id, req.Method, req.Params); reply.Should().NotBeNull(); reply.Id.Should().Be(81); reply.Error.Should().BeNull(); }
public void NoReturnOnNotify() { string reply = null; var handler = new TestHandlerFake(); var server = new JsonRpcServer(); var clientMock = new Mock <JsonRpcServer.ClientConnection>(1, "localhost", _fakePipe, _process, Encoding.UTF8); clientMock.Setup(x => x.WriteString(It.IsAny <string>())).Callback <string>(s => reply = s); server.Bind(handler); server.ExecuteHandler(clientMock.Object, -1, "ReturnStringArray", null); reply.Should().BeNull(); }
public void Call_WithDefaultArgsValues() { Response reply = default; var handler = new TestHandlerFake(); var server = new JsonRpcServer(); var clientMock = new Mock <JsonRpcServer.ClientConnection>(1, "localhost", _fakePipe, _process, Encoding.UTF8); clientMock.Setup(x => x.WriteAsJson(It.IsAny <object>())).Callback <object>(o => reply = (Response)o); server.Bind(handler); server.ExecuteHandler(clientMock.Object, 31, "DefaultArgs", new object[] { 123 }); reply.Should().NotBeNull(); reply.Id.Should().Be(31); reply.Error.Should().BeNull(); }
public void Call_GivenTypesArgs() { Response <object> reply = default; var handler = new TestHandlerFake(); var server = new JsonRpcServer(); var clientMock = new Mock <JsonRpcServer.ClientConnection>(1, "localhost", _fakePipe, _process, Encoding.UTF8); clientMock.Setup(x => x.WriteAsJson(It.IsAny <object>())).Callback <object>(o => reply = (Response <object>)o); server.Bind(handler); server.ExecuteHandler(clientMock.Object, 1, "FirstTest", new object[] { 1, "string", false, null }); reply.Should().NotBeNull(); reply.Id.Should().Be(1); reply.Result.Should().Be(23); }
public void Call_GivenIntStringBoolNull() { Response <object> reply = default; var handler = new TestHandlerFake(); var server = new JsonRpcServer(); var clientMock = new Mock <JsonRpcServer.ClientConnection>(1, "localhost", _fakePipe, _process, Encoding.UTF8); clientMock.Setup(x => x.WriteAsJson(It.IsAny <object>())).Callback <object>(o => reply = (Response <object>)o); var reqOring = new Request() { Id = 1, Method = "FirstTest", Params = new object[] { 1, "string", false, null } }; var json = Serializer.Serialize(reqOring); var req = Serializer.Deserialize <Request>(json); server.Bind(handler); server.ExecuteHandler(clientMock.Object, req.Id, req.Method, req.Params); reply.Should().NotBeNull(); reply.Id.Should().Be(1); reply.Result.Should().Be(23); }