Beispiel #1
0
        public void GetMessageListWithFiltersTest()
        {
            try
            {
                MessagesRequester requester = new MessagesRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(requester, "http://GetMessageListTest:3000");
                }

                string to   = "+18475978014";
                string from = "+12248806205";
                string text = "Hello World";

                WebRequest.RegisterPrefix("http://GetMessageListTest:3000", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"total\":1,\"start\":0,\"end\":0,\"page\":0,\"numPages\":1,\"pageSize\":2,\"nextPageUri\":null, \"messages\" : [{\"uri\" : \"/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages/MM16ac1bcbd6f4895c89a798571e89e1e715892926\", \"revision\" : 1, \"dateCreated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"dateUpdated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"messageId\" : \"MM16ac1bcbd6f4895c89a798571e89e1e715892926\", \"accountId\" : \"AC736ca2078721a9a41fb47f07bf40d9e21cb304da\", \"from\" : \"" + from + "\", \"to\" : \"" + to + "\", \"text\" : \"" + text + "\", \"direction\" : \"inbound\", \"status\" : \"received\"}]}");

                MessagesSearchFilter filters = new MessagesSearchFilter();
                filters.setFrom(from);
                filters.setDirection(com.persephony.EMessageDirection.Inbound);
                DateTime now           = DateTime.Now;
                DateTime yesterday     = now.AddDays(-1);
                string   dateFormatStr = "yyyy-MM-dd HH:mm:ss";
                filters.setBeginTime(yesterday.ToString(dateFormatStr));
                filters.setEndTime(now.ToString(dateFormatStr));
                MessageList msgList = requester.get(filters);

                Assert.IsNotNull(msgList);

                Assert.AreEqual(msgList.getLocalSize, 1);
                Assert.AreEqual((msgList.export()).Count, 1);

                Message msg = msgList.get(0) as Message;

                Assert.IsNotNull(msg);
                Assert.AreEqual(msg.getMessageId, "MM16ac1bcbd6f4895c89a798571e89e1e715892926");
                Assert.AreEqual(msg.getFrom, from);
            }
            catch (PersyException pe)
            {
                Assert.Fail(pe.Message);
            }
        }
Beispiel #2
0
        public void GetMessageTest()
        {
            try
            {
                MessagesRequester requester = new MessagesRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(requester, "http://GetMessageTest:3000");
                }

                WebRequest.RegisterPrefix("http://GetMessageTest:3000", new TestWebRequestCreate());

                string to       = "+18475978014";
                string from     = "+12248806205";
                string text     = "Hello World";
                string notifUrl = "http://server/msgNotif";

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"uri\" : \"/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages/MM16ac1bcbd6f4895c89a798571e89e1e715892924\", \"revision\" : 1, \"dateCreated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"dateUpdated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"messageId\" : \"MM16ac1bcbd6f4895c89a798571e89e1e715892924\", \"accountId\" : \"AC736ca2078721a9a41fb47f07bf40d9e21cb304da\", \"from\" : \"" + from + "\", \"to\" : \"" + to + "\", \"text\" : \"" + text + "\", \"direction\" : \"outbound\", \"status\" : \"queued\", \"notificationUrl\" : \"" + notifUrl + "\"}");

                Message msg = requester.get("MM16ac1bcbd6f4895c89a798571e89e1e715892924");

                Assert.IsNotNull(msg);
                Assert.AreEqual(msg.getMessageId, "MM16ac1bcbd6f4895c89a798571e89e1e715892924");
                Assert.AreEqual(msg.getFrom, from);
                Assert.AreEqual(msg.getTo, to);
                Assert.AreEqual(msg.getText, text);
                Assert.AreEqual(msg.getDirection, com.persephony.EMessageDirection.Outbound);
                Assert.AreEqual(msg.getStatus, com.persephony.EMessageStatus.Queued);
                Assert.AreEqual(msg.getNotificationUrl, notifUrl);
            }
            catch (PersyException pe)
            {
                Assert.Fail(pe.Message);
            }
        }
Beispiel #3
0
        public void GetMessageListTest()
        {
            try
            {
                MessagesRequester requester = new MessagesRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(requester, "http://GetMessageListTest:3000");
                }

                string to   = "+18475978014";
                string from = "+12248806205";
                string text = "Hello World";

                WebRequest.RegisterPrefix("http://GetMessageListTest:3000", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"total\":3,\"start\":0,\"end\":1,\"page\":0,\"numPages\":2,\"pageSize\":2,\"nextPageUri\":\"/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages&cursor=492dc883a811bd0204204ea9047122f93a2788a2\", \"messages\" : [{\"uri\" : \"/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages/MM16ac1bcbd6f4895c89a798571e89e1e715892924\", \"revision\" : 1, \"dateCreated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"dateUpdated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"messageId\" : \"MM16ac1bcbd6f4895c89a798571e89e1e715892924\", \"accountId\" : \"AC736ca2078721a9a41fb47f07bf40d9e21cb304da\", \"from\" : \"" + from + "\", \"to\" : \"" + to + "\", \"text\" : \"" + text + "\", \"direction\" : \"inbound\", \"status\" : \"received\"}, {\"uri\" : \"/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages/MM16ac1bcbd6f4895c89a798571e89e1e715892925\", \"revision\" : 1, \"dateCreated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"dateUpdated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"messageId\" : \"MM16ac1bcbd6f4895c89a798571e89e1e715892925\", \"accountId\" : \"AC736ca2078721a9a41fb47f07bf40d9e21cb304da\", \"from\" : \"" + from + "\", \"to\" : \"" + to + "\", \"text\" : \"" + text + "\", \"direction\" : \"inbound\", \"status\" : \"received\"}]}");


                MessageList msgList = requester.get();

                Assert.IsNotNull(msgList);

                Assert.AreEqual(msgList.getLocalSize, 2);
                Assert.AreEqual((msgList.export()).Count, 2);

                Message msg = msgList.get(0) as Message;

                Assert.IsNotNull(msg);
                Assert.AreEqual(msg.getMessageId, "MM16ac1bcbd6f4895c89a798571e89e1e715892924");

                type      = typeof(APIRequester);
                fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(msgList, "http://GetMessageListTest:3000");
                }

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"total\":3,\"start\":2,\"end\":2,\"page\":1,\"numPages\":2,\"pageSize\":2,\"nextPageUri\":null, \"messages\" : [{\"uri\" : \"/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages/MM16ac1bcbd6f4895c89a798571e89e1e715892926\", \"revision\" : 1, \"dateCreated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"dateUpdated\" : \"Thu, 23 Jun 2016 17:30:06 GMT\", \"messageId\" : \"MM16ac1bcbd6f4895c89a798571e89e1e715892926\", \"accountId\" : \"AC736ca2078721a9a41fb47f07bf40d9e21cb304da\", \"from\" : \"" + from + "\", \"to\" : \"" + to + "\", \"text\" : \"" + text + "\", \"direction\" : \"inbound\", \"status\" : \"received\"}]}");

                msgList.loadNextPage();

                Assert.IsNotNull(msgList);

                Assert.AreEqual(msgList.getLocalSize, 3);
                Assert.AreEqual((msgList.export()).Count, 3);

                msg = msgList.get(2) as Message;
                Assert.IsNotNull(msg);
                Assert.AreEqual(msg.getMessageId, "MM16ac1bcbd6f4895c89a798571e89e1e715892926");
            }
            catch (PersyException pe)
            {
                Assert.Fail(pe.Message);
            }
        }