Ejemplo n.º 1
0
        public void TestEncode()
        {
            MutablePushState state = new MutablePushState
            {
                Data = new Dictionary <string, object>
                {
                    ["alert"] = "Some Alert"
                },
                Channels = new List <string> {
                    "channel"
                }
            };

            IDictionary <string, object> expected = new Dictionary <string, object>
            {
                ["data"] = new Dictionary <string, object>
                {
                    ["alert"] = "Some Alert"
                },
                ["where"] = new Dictionary <string, object>
                {
                    ["channels"] = new Dictionary <string, object>
                    {
                        ["$in"] = new List <string> {
                            "channel"
                        }
                    }
                }
            };

            Assert.AreEqual(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(ParsePushEncoder.Instance.Encode(state)));
        }
 /// <summary>
 /// Creates a push which will target every device. The Data field must be set before calling SendAsync.
 /// </summary>
 public ParsePush(IServiceHub serviceHub)
 {
     Services = serviceHub ?? ParseClient.Instance;
     State    = new MutablePushState {
         Query = Services.GetInstallationQuery()
     };
 }
Ejemplo n.º 3
0
        public void TestMutatedClone()
        {
            MutablePushState state = new MutablePushState();

            IPushState mutated = state.MutatedClone(s => s.Alert = "test");

            Assert.AreEqual(null, state.Alert);
            Assert.AreEqual("test", mutated.Alert);
        }
Ejemplo n.º 4
0
        public Task TestSendPush()
        {
            MutableServiceHub hub = new MutableServiceHub {
            };
            ParseClient client    = new ParseClient(new ServerConnectionData {
                Test = true
            }, hub);

            MutablePushState state = new MutablePushState
            {
                Query = Client.GetInstallationQuery()
            };

            ParsePush thePush = new ParsePush(client);

            hub.PushController = GetMockedPushController(state);

            thePush.Alert = "Alert";
            state.Alert   = "Alert";

            return(thePush.SendAsync().ContinueWith(task =>
            {
                Assert.IsTrue(task.IsCompleted);
                Assert.IsFalse(task.IsFaulted);

                thePush.Channels = new List <string> {
                    { "channel" }
                };
                state.Channels = new List <string> {
                    { "channel" }
                };

                return thePush.SendAsync();
            }).Unwrap().ContinueWith(task =>
            {
                Assert.IsTrue(task.IsCompleted);
                Assert.IsFalse(task.IsFaulted);

                ParseQuery <ParseInstallation> query = new ParseQuery <ParseInstallation>(client, "aClass");

                thePush.Query = query;
                state.Query = query;

                return thePush.SendAsync();
            }).Unwrap().ContinueWith(task =>
            {
                Assert.IsTrue(task.IsCompleted);
                Assert.IsFalse(task.IsFaulted);
            }));
        }
Ejemplo n.º 5
0
        public void TestEncodeEmpty()
        {
            MutablePushState state = new MutablePushState();

            Assert.Throws <InvalidOperationException>(() => ParsePushEncoder.Instance.Encode(state));
            state.Alert = "alert";

            Assert.Throws <InvalidOperationException>(() => ParsePushEncoder.Instance.Encode(state));
            state.Channels = new List <string> {
                { "channel" }
            };

            Assert.DoesNotThrow(() => ParsePushEncoder.Instance.Encode(state));
        }
Ejemplo n.º 6
0
        public void TestEquals()
        {
            MutablePushState state = new MutablePushState {
                Alert = "test"
            };

            MutablePushState otherState = new MutablePushState {
                Alert = "test"
            };

            Assert.AreNotEqual(null, state);
            Assert.AreNotEqual("test", state);

            Assert.AreEqual(state, otherState);
        }
Ejemplo n.º 7
0
        public Task TestSendPush()
        {
            MutablePushState state = new MutablePushState
            {
                Query = ParseInstallation.Query
            };

            ParsePush thePush = new ParsePush();

            ParsePushPlugins.Instance = new ParsePushPlugins
            {
                PushController = GetMockedPushController(state)
            };

            thePush.Alert = "Alert";
            state.Alert   = "Alert";

            return(thePush.SendAsync().ContinueWith(t =>
            {
                Assert.IsTrue(t.IsCompleted);
                Assert.IsFalse(t.IsFaulted);

                thePush.Channels = new List <string> {
                    { "channel" }
                };
                state.Channels = new List <string> {
                    { "channel" }
                };

                return thePush.SendAsync();
            }).Unwrap().ContinueWith(t =>
            {
                Assert.IsTrue(t.IsCompleted);
                Assert.IsFalse(t.IsFaulted);

                ParseQuery <ParseInstallation> query = new ParseQuery <ParseInstallation>("aClass");
                thePush.Query = query;
                state.Query = query;

                return thePush.SendAsync();
            }).Unwrap().ContinueWith(t =>
            {
                Assert.IsTrue(t.IsCompleted);
                Assert.IsFalse(t.IsFaulted);
            }));
        }
Ejemplo n.º 8
0
        public void TestEncode()
        {
            MutablePushState state = new MutablePushState {
                Data = new Dictionary <string, object> {
                    { "alert", "Some Alert" }
                },
                Channels = new List <string> {
                    { "channel" }
                }
            };

            IDictionary <string, object> expected = new Dictionary <string, object> {
                {
                    "data", new Dictionary <string, object> {
                        {
                            "alert", "Some Alert"
                        }
                    }
                },
                {
                    "where", new Dictionary <string, object> {
                        {
                            "channels", new Dictionary <string, object> {
                                {
                                    "$in", new List <string> {
                                        { "channel" }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            Assert.AreEqual(expected, ParsePushEncoder.Instance.Encode(state));
        }