public void TestCreateResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"bg_color\": \"#fff\",\"caller\": \"Owl Bank\",\"created_at\": \"2019-05-01T20:00:00Z\",\"font_color\": \"#000\",\"from\": \"+15000000000\",\"logo\": \"https://www.twilio.com/marketing/bundles/company/img/logos/red/twilio-logo-red.png\",\"reason\": \"Hello Jhon, your appointment has been confirmed.\",\"status\": \"unknown\",\"to\": \"+573000000000\",\"use_case\": \"conversational\",\"url\": \"https://preview.twilio.com/TrustedComms/Business/BrandedCalls\"}" )); var response = BrandedCallResource.Create("from", "to", "reason", client: twilioRestClient); Assert.NotNull(response); }
public void TestCreateRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Post, Twilio.Rest.Domain.Preview, "/TrustedComms/Business/BrandedCalls", "" ); request.AddPostParam("From", Serialize("from")); request.AddPostParam("To", Serialize("to")); request.AddPostParam("Reason", Serialize("reason")); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { BrandedCallResource.Create("from", "to", "reason", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }