public void MakeAFailedSmsRequestWithNotRequiredFieldsTest() { try { MessagesRequester messagesRequester = new MessagesRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da"); Type messagesRequesterType = typeof(MessagesRequester); MethodInfo persyUrlMethodInfo = messagesRequesterType.GetMethod("setPersyUrl", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(System.String) }, null); persyUrlMethodInfo.Invoke(messagesRequester, new Object[] { "http://MakeAInitialSmsRequestTest:3000" }); WebRequest.RegisterPrefix("http://MakeAInitialSmsRequestTest:3000", new TestWebRequestCreate()); string to = ""; string from = "+12248806205"; string text = "Hello World"; 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\" : \"sending\"}"); Message msg = messagesRequester.create(from, to, text); } catch (PersyException /* pe */) { Assert.IsTrue(true); return; } // if no exception, it fails Assert.Fail(); }
public void MakeAInitialSmsRequestWithOptionalFieldsTest() { try { MessagesRequester messagesRequester = new MessagesRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5", "AC736ca2078721a9a41fb47f07bf40d9e21cb304da"); Type messagesRequesterType = typeof(MessagesRequester); MethodInfo persyUrlMethodInfo = messagesRequesterType.GetMethod("setPersyUrl", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(System.String) }, null); persyUrlMethodInfo.Invoke(messagesRequester, new Object[] { "http://MakeAInitialSmsRequestTest:3000" }); WebRequest.RegisterPrefix("http://MakeAInitialSmsRequestTest:3000", new TestWebRequestCreate()); string to = "+18475978014"; string from = "+12248806205"; string text = "Hello World"; string notifUrl = "http://server/msgNotif"; MessageOptions options = new MessageOptions(); options.setNotificationUrl(notifUrl); 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\" : \"sending\", \"notificationUrl\" : \"" + notifUrl + "\"}"); Message msg = messagesRequester.create(from, to, text, options); Assert.IsNotNull(msg); Assert.IsNotNull(msg.getUri); Assert.AreEqual(msg.getUri, "/Accounts/AC736ca2078721a9a41fb47f07bf40d9e21cb304da/Messages/MM16ac1bcbd6f4895c89a798571e89e1e715892924"); Assert.AreEqual(msg.getRevision, 1); Assert.IsNotNull(msg.getDateCreated); Assert.IsNotNull(msg.getDateUpdated); Assert.AreEqual(msg.getDirection, com.persephony.EMessageDirection.Outbound); Assert.AreEqual(msg.getStatus, com.persephony.EMessageStatus.Sending); Assert.AreEqual(msg.getFrom, from); Assert.AreEqual(msg.getTo, to); Assert.AreEqual(msg.getText, text); Assert.AreEqual(msg.getNotificationUrl, notifUrl); } catch (PersyException pe) { Assert.Fail(pe.Message); } }