public void TestCreateRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Post, Twilio.Rest.Domain.Messaging, "/v1/a2p/Campaigns", "" ); request.AddPostParam("BrandRegistrationSid", Serialize("BNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")); request.AddPostParam("UseCase", Serialize("use_case")); request.AddPostParam("Description", Serialize("description")); request.AddPostParam("MessageSamples", Serialize("message_samples")); request.AddPostParam("HasEmbeddedLinks", Serialize(true)); request.AddPostParam("HasEmbeddedPhone", Serialize(true)); request.AddPostParam("MessagingServiceSid", Serialize("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { CampaignResource.Create("BNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "use_case", "description", Promoter.ListOfOne("message_samples"), true, true, "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
public void TestCreateResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"sid\": \"CMdeadbeef66043a43b62be6d67c635c85\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MG3u3kcgofdljponkatswl3ad3ev0c123u\",\"brand_registration_sid\": \"BN0044409f7e067e279523808d267e2d85\",\"date_created\": \"2021-01-27T14:47:52Z\",\"date_updated\": \"2021-01-27T14:47:52Z\",\"description\": \"Send marketing messages about sales and offers to opted in customers.\",\"message_samples\": [\"EXPRESS: Denim Days Event is ON\",\"LAST CHANCE: Book your next flight for just 1 (ONE) EUR\"],\"status\": \"pending\",\"failure_reason\": null,\"use_case\": \"2FA\",\"has_embedded_links\": true,\"has_embedded_phone\": false,\"url\": \"https://messaging.twilio.com/v1/a2p/Campaigns/CMdeadbeef66043a43b62be6d67c635c85\"}" )); var response = CampaignResource.Create("BNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "use_case", "description", Promoter.ListOfOne("message_samples"), true, true, "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }