Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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));
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
 public void TestInitialize()
 {
     this.testConnection = new InMemoryConnection();
     this.client = new DdpClient(this.testConnection);
 }
Example #7
0
 private void ClearSentMessages(InMemoryConnection connection)
 {
     while (!string.IsNullOrWhiteSpace(connection.GetSentMessage())) { }
 }
Example #8
0
        private void Connect(DdpClient client, InMemoryConnection connection)
        {
            connection.Reply(
                JsonConvert.SerializeObject(new Connected() { Session = "TestSession" }));

            client.ConnectAsync().Wait();
        }
Example #9
0
        public void DdpClient_SubscribeParameters_BeforeConnectThrows()
        {
            var connection = new InMemoryConnection();
            var client = new DdpClient(connection);

            PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Subscribe("TestSub", "Test" ));
        }
Example #10
0
        public void DdpClient_CallParametersResult_BeforeConnectThrows()
        {
            var connection = new InMemoryConnection();
            var client = new DdpClient(connection);

            PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Call<string>("Test", 1 ));
        }
Example #11
0
        public void DdpClient_Call_BeforeConnectThrows()
        {
            var connection = new InMemoryConnection();
            var client = new DdpClient(connection);

            PCLTesting.ExceptionAssert.Throws<InvalidOperationException>(() => client.Call("Test"));
        }
Example #12
0
        public void DdpClient_GetCollection_GetsTypedCollection()
        {
            var connection = new InMemoryConnection();

            var client = new DdpClient(connection);

            this.Connect(client, connection);

            var collection = client.GetCollection<SimpleDdpObject>("Test");

            Assert.IsNotNull(collection);
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }