示例#1
0
        public void TestParseKiiObject()
        {
            List <string> errors = new List <string>();

            for (int i = 0; i < OBJECT_TEST_CASES.Length; i++)
            {
                TestCase         tc      = OBJECT_TEST_CASES[i];
                PushToAppMessage message = (PushToAppMessage)ReceivedMessage.Parse(tc.GetPushMessage());
                ExpectResult     result  = tc.result;
                Console.WriteLine("No: " + (i + 1) + " message: " + tc.GetPushMessage());
                try
                {
                    Assert.IsNotNull(message);
                    if (result.Value == null)
                    {
                        Assert.IsFalse(message.ContainsKiiObject());
                        Assert.IsNull(message.KiiObject);
                    }
                    else
                    {
                        Assert.IsNotNull(message.KiiObject);
                        Assert.AreEqual(result.Value, message.KiiObject.Uri.ToString());
                        Assert.IsTrue(message.ContainsKiiObject());
                    }
                }
                catch (AssertionException e)
                {
                    errors.Add("TestCase: " + (i + 1) + " message:" + e.Message);
                }
            }
            if (errors.Count > 0)
            {
                StringBuilder sb = new StringBuilder("One or More testcase failed. \n");
                foreach (string error in errors)
                {
                    sb.Append(error);
                }
                Assert.Fail(sb.ToString());
            }
        }
        public void Test_0013_ToJson()
        {
            LogIn();
            StringBuilder json = new StringBuilder();

            json.AppendLine("{");
            json.AppendLine("\"aps\" : {\"content-available\":1},");
            json.AppendLine("\"string-property\" : \"abc\",");
            json.AppendLine("\"int-property\" : 10,");
            json.AppendLine("\"bool-property\" : true,");
            json.AppendLine("\"double-property\" : 10.5,");
            json.AppendLine("\"st\" : \"APP\",");
            json.AppendLine("\"sg\" : \"GROUP-000001-AAAAAA\",");
            json.AppendLine("\"su\" : \"USER-000001-BBBBBB\",");
            json.AppendLine("\"bi\" : \"BUCKET-000001-AAAAAA\",");
            json.AppendLine("\"oi\" : \"OBJECT-000001-AAAAAA\",");
            json.AppendLine("\"bt\" : \"SYNC\"");
            json.AppendLine("}");

            ReceivedMessage msg = ReceivedMessage.Parse(json.ToString());

            Assert.AreEqual(1, msg.ToJson().GetJsonObject("aps").GetInt("content-available"));
        }
        public void Test_0003_Parse_GCM_DirectPush()
        {
            LogIn();
            StringBuilder json = new StringBuilder();

            json.AppendLine("{");
            json.AppendLine("\"string-property\" : \"abc\",");
            json.AppendLine("\"int-property\" : 10,");
            json.AppendLine("\"bool-property\" : true,");
            json.AppendLine("\"double-property\" : 10.5,");
            json.AppendLine("\"sender\" : \"USER-000001-AAAAAA\",");
            json.AppendLine("\"objectScopeType\" : \"APP\"");
            json.AppendLine("}");

            DirectPushMessage message = (DirectPushMessage)ReceivedMessage.Parse(json.ToString());

            Assert.AreEqual("abc", message.GetString("string-property"));
            Assert.AreEqual(10, message.GetInt("int-property"));
            Assert.AreEqual(true, message.GetBoolean("bool-property"));
            Assert.AreEqual(10.5, message.GetDouble("double-property"));
            Assert.AreEqual(ReceivedMessage.MessageType.DIRECT_PUSH, message.PushMessageType);
            Assert.AreEqual(ReceivedMessage.Scope.APP, message.ObjectScope);
        }
示例#4
0
        public void TestParseSender()
        {
            List <string> errors = new List <string>();

            for (int i = 0; i < SENDER_TEST_CASES.Length; i++)
            {
                TestCase         tc      = SENDER_TEST_CASES[i];
                PushToAppMessage message = (PushToAppMessage)ReceivedMessage.Parse(tc.GetPushMessage());
                ExpectResult     result  = tc.result;
                try
                {
                    if (result.Value == null)
                    {
                        Assert.IsNull(message.Sender);
                    }
                    else
                    {
                        Assert.IsNotNull(message.Sender);
                        Assert.AreEqual(result.Value, message.Sender.Uri.ToString());
                    }
                }
                catch (AssertionException e)
                {
                    errors.Add("TestCase: " + (i + 1) + " message:" + e.Message);
                }
            }
            if (errors.Count > 0)
            {
                StringBuilder sb = new StringBuilder("One or More testcase failed. \n");
                foreach (string error in errors)
                {
                    sb.Append(error);
                }
                Assert.Fail(sb.ToString());
            }
        }