public void DdpClient_ConnectAsync_CalledMultipleTimes() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); connection.Reply( JsonConvert.SerializeObject(new Connected() {Session = "TestSession"})); client.ConnectAsync().Wait(); bool exceptionCaught = false; try { client.ConnectAsync().Wait(); } catch (AggregateException e) { Assert.IsTrue(e.InnerException is InvalidOperationException); exceptionCaught = true; } Assert.IsTrue(exceptionCaught); }
public void MeteorClient_LoginPassword_NullPassword() { var websocket = new InMemoryConnection(); var client = new MeteorClient(websocket); websocket.Reply(JsonConvert.SerializeObject(new Connected() { Session = "TestSession" })); client.ConnectAsync().Wait(); PCLTesting.ExceptionAssert.Throws<ArgumentNullException>(() => client.LoginPassword("Username", String.Empty)); }
public void MeteorClient_LoginPassword_CallsServerMethod() { var websocket = new InMemoryConnection(); var client = new MeteorClient(websocket); websocket.Reply(JsonConvert.SerializeObject(new Connected() { Session = "TestSession"})); client.ConnectAsync().Wait(); var loginTask = client.LoginPassword("Username", "Password"); Method method = null; while (method == null) { var message = websocket.GetSentMessage(); var jobject = JObject.Parse(message); if (jobject["msg"] != null && jobject["msg"].Value<string>() == "method") { method = JsonConvert.DeserializeObject<Method>(message); } } websocket.Reply(JsonConvert.SerializeObject(new Result() { Id = method.Id })); websocket.Reply(JsonConvert.SerializeObject(new Updated() { Methods = new []{method.Id}})); loginTask.Wait(); Assert.AreEqual("login", method.MethodName); Assert.AreEqual(1, method.Parameters.Length); var loginParameters = JsonConvert.DeserializeObject<LoginPasswordParameters>(method.Parameters[0].ToString()); Assert.AreEqual("Username", loginParameters.User.UserName); Assert.IsTrue(!string.IsNullOrWhiteSpace(loginParameters.Password.Digest)); Assert.AreEqual("sha-256", loginParameters.Password.Algorithm); }
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_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); }
private void Connect(DdpClient client, InMemoryConnection connection) { connection.Reply( JsonConvert.SerializeObject(new Connected() { Session = "TestSession" })); client.ConnectAsync().Wait(); }
public void DdpClient_Subscribe_ServerMethodCalled() { var connection = new InMemoryConnection(); var client = new DdpClient(connection); this.Connect(client, connection); this.ClearSentMessages(connection); var task = client.Subscribe("TestSubscription"); var subscribeString = connection.GetSentMessage(); var subscribe = JsonConvert.DeserializeObject<Subscribe>(subscribeString); connection.Reply(JsonConvert.SerializeObject(new Ready() { SubscriptionsReady = new []{subscribe.Id}})); task.Wait(); Assert.IsTrue(task.IsCompleted); Assert.AreEqual("TestSubscription", subscribe.Name); }
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); }