public void DdpClient_Call_GetResult() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Call<SimpleField>("TestMethod"); var methodString = connection.GetSentMessage(); var method = JsonConvert.DeserializeObject<Method>(methodString); connection.Reply( JsonConvert.SerializeObject(new Result() { Id = method.Id, ResultObject = JToken.FromObject(new SimpleField() {integerField = 11, boolField = false, stringField = "ReturnObject"}) })); connection.Reply(JsonConvert.SerializeObject(new Updated() { Methods = new[] { method.Id } })); task.Wait(); Assert.AreEqual("TestMethod", method.MethodName); Assert.AreEqual(0, method.Parameters.Length); var result = task.Result; Assert.AreEqual(11, result.integerField); Assert.AreEqual(false, result.boolField); Assert.AreEqual("ReturnObject", result.stringField); }
public void DdpClient_Call_ServerMethodInvoked() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Call("TestMethod"); var methodString = connection.GetSentMessage(); var method = JsonConvert.DeserializeObject<Method>(methodString); connection.Reply(JsonConvert.SerializeObject(new Result() {Id = method.Id})); connection.Reply(JsonConvert.SerializeObject(new Updated() {Methods = new[] {method.Id}})); task.Wait(); Assert.AreEqual("TestMethod", method.MethodName); Assert.AreEqual(0, method.Parameters.Length); }
public void DdpClient_Call_BeforeConnectThrows() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Call("Test")); }
public void DdpClient_CallParametersResult_BeforeConnectThrows() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Call<string>("Test", 1 )); }
public void DdpClient_Call_ErrorReturned() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Call("TestMethod"); var methodString = connection.GetSentMessage(); var method = JsonConvert.DeserializeObject<Method>(methodString); connection.Reply( JsonConvert.SerializeObject(new Result() { Id = method.Id, Error = new Error() {Details = "Failed", ErrorMessage = "TestFailed", Reason = "ReasonFailed"} })); connection.Reply(JsonConvert.SerializeObject(new Updated() { Methods = new[] { method.Id } })); ExceptionAssert.ExpectAggregateException(() => task.Wait(), typeof(DdpServerException)); Assert.AreEqual("TestMethod", method.MethodName); Assert.AreEqual(0, method.Parameters.Length); Assert.IsNotNull(task.Exception); Assert.IsTrue(task.IsFaulted); }