public void TestFetchResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"sid\": \"CMdeadbeef66043a43b62be6d67c635c85\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2021-01-27T14:47:52Z\",\"date_updated\": \"2021-01-27T14:47:52Z\",\"description\": \"Test description for test campaing\",\"message_samples\": [\"Test_Sample_1\",\"Another_test_sample_2\"],\"status\": \"pending\",\"failure_reason\": null,\"use_case\": \"PUBLIC_SERVICE_ANNOUNCEMENT\",\"has_embedded_links\": true,\"has_embedded_phone\": false,\"brand_registration_sid\": \"BN0044409f7e067e279523808d267e2d85\",\"url\": \"https://messaging.twilio.com/v1/a2p/Campaigns/CMdeadbeef66043a43b62be6d67c635c85\"}" )); var response = CampaignResource.Fetch("CMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }
public void TestFetchRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Get, Twilio.Rest.Domain.Messaging, "/v1/a2p/Campaigns/CMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "" ); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { CampaignResource.Fetch("CMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }