Ejemplo n.º 1
0
        public void Test_BuildWithNullPushMessageType()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage.BuildWith(data).WithPushMessageType(null);
        }
Ejemplo n.º 2
0
        public void Test_0002_KiiPushMessage_all_false()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage msg = KiiPushMessage.BuildWith(data)
                                 .EnableAPNS(false)
                                 .EnableGCM(false)
                                 .EnableMqtt(false)
                                 .SendAppID(false)
                                 .SendObjectScope(false)
                                 .SendOrigin(false)
                                 .SendSender(false)
                                 .SendToDevelopment(false)
                                 .SendTopicId(false)
                                 .SendToProduction(false)
                                 .SendWhen(false)
                                 .Build();
            JsonObject json = msg.ToJson();

            Assert.AreEqual(false, json.Get("sendAppID"));
            Assert.AreEqual(false, json.Get("sendObjectScope"));
            Assert.AreEqual(false, json.Get("sendOrigin"));
            Assert.AreEqual(false, json.Get("sendSender"));
            Assert.AreEqual(false, json.Get("sendToDevelopment"));
            Assert.AreEqual(false, json.Get("sendTopicID"));
            Assert.AreEqual(false, json.Get("sendToProduction"));
            Assert.AreEqual(false, json.Get("sendWhen"));
            Assert.AreEqual(false, json.GetJsonObject("gcm").Get("enabled"));
            Assert.AreEqual(false, json.GetJsonObject("apns").Get("enabled"));
            Assert.AreEqual(false, json.GetJsonObject("mqtt").Get("enabled"));
            Assert.AreEqual("abc", json.GetJsonObject("data").Get("payload"));
        }
Ejemplo n.º 3
0
        public void Test_BuildWithNullMqttMessage()
        {
            MqttData data = new MqttData();

            data.Put("payload", "abc");
            KiiPushMessage.BuildWith(data).WithMqttMessage(null);
        }
Ejemplo n.º 4
0
        public void Test_0006_BuildWithNullGCMMessage()
        {
            GCMData data = new GCMData();

            data.Put("payload", "abc");
            KiiPushMessage.BuildWith(data).WithGCMMessage(null);
        }
Ejemplo n.º 5
0
        public void Test_0004_BuildWithNullAPNSMessage()
        {
            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage.BuildWith(data).WithAPNSMessage(null);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Send message to this topic.
 /// </summary>
 /// <remarks></remarks>
 /// <param name="message">Message to send.</param>
 /// <exception cref='ArgumentNullException'>
 /// Is thrown when an argument is null.
 /// </exception>
 /// <exception cref='CloudException'>
 /// Is thrown when server sends error response.
 /// </exception>
 public void SendMessage(KiiPushMessage message)
 {
     this.ExecSendMessage(message, Kii.HttpClientFactory, (KiiPushMessage target, Exception e) => {
         if (e != null)
         {
             throw e;
         }
     });
 }
Ejemplo n.º 7
0
            /// <summary>
            /// Build and return KiiPushMessage.
            /// </summary>
            /// <remarks></remarks>
            /// <returns>KiiPushMessage</returns>
            public KiiPushMessage Build()
            {
                if (this.mGcm.OptBoolean("enabled"))
                {
                    if (this.mMessageData != null && !GCMData.IsValidData(this.mMessageData))
                    {
                        throw new SystemException("Data contains key that is GCM reserve word");
                    }
                }
                KiiPushMessage msg = new KiiPushMessage(this.mMessageData, this.mParent, this.mGcm, this.mApns, this.mMqtt);

                return(msg);
            }
Ejemplo n.º 8
0
        public void Test_0005_SendMessage()
        {
            this.LogIn();
            ClearClientRequest();
            client.AddResponse(200, null);

            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage message = KiiPushMessage.BuildWith(data).Build();

            KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic");

            topic.SendMessage(message);
            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]);
            Assert.AreEqual("{\"data\":{\"payload\":\"abc\"},\"gcm\":{\"enabled\":true},\"apns\":{\"enabled\":true},\"mqtt\":{\"enabled\":true}}", client.RequestBody [0]);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/messages", client.RequestUrl [0]);
        }
Ejemplo n.º 9
0
        private void ExecSendMessage(KiiPushMessage message, KiiHttpClientFactory factory, KiiPushMessageCallback callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("KiiPushMessageCallback must not be null");
            }
            if (message == null)
            {
                callback(message, new ArgumentNullException("KiiPushMessage must not be null"));
                return;
            }
            Utils.CheckInitialize(false);
            KiiHttpClient client = factory.Create(MessageUrl, Kii.AppId, Kii.AppKey, KiiHttpMethod.POST);

            KiiCloudEngine.SetAuthBearer(client);
            client.ContentType = "application/vnd.kii.SendPushMessageRequest+json";
            client.SendRequest(message.ToJson().ToString(), (ApiResponse response, Exception e) => {
                callback(message, e);
            });
        }
Ejemplo n.º 10
0
        public void Test_SendMessage_Anonymous()
        {
            this.LogIn();
            ClearClientRequest();
            client.AddResponse(new CloudException(401, null));

            KiiPushMessageData data = new KiiPushMessageData();

            data.Put("payload", "abc");
            KiiPushMessage message = KiiPushMessage.BuildWith(data).Build();

            KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic");

            Kii.LogOut();
            try {
                topic.SendMessage(message);
                Assert.Fail("CloudException has not thrown");
            } catch (CloudException e) {
                // pass
            }
            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]);
            Assert.AreEqual("{\"data\":{\"payload\":\"abc\"},\"gcm\":{\"enabled\":true},\"apns\":{\"enabled\":true},\"mqtt\":{\"enabled\":true}}", client.RequestBody [0]);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/messages", client.RequestUrl [0]);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Asynchronous call of <see cref='SendMessage(KiiPushMessage)'/>
 /// </summary>
 /// <remarks></remarks>
 /// <param name="message">Message to send.</param>
 /// <param name="callback">Callback.</param>
 /// <exception cref='ArgumentNullException'>
 /// Is thrown when an argument is null.
 /// </exception>
 /// <exception cref='CloudException'>
 /// Is thrown when server sends error response.
 /// </exception>
 public void SendMessage(KiiPushMessage message, KiiPushMessageCallback callback)
 {
     this.ExecSendMessage(message, Kii.AsyncHttpClientFactory, callback);
 }