Esempio n. 1
0
        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\",\"connection_policy_sid\": \"NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"sid\": \"NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"friendly_name\",\"target\": \"sip:sip-box.com:1234\",\"priority\": 1,\"weight\": 20,\"enabled\": true,\"date_created\": \"2020-03-18T23:31:36Z\",\"date_updated\": \"2020-03-18T23:31:36Z\",\"url\": \"https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = ConnectionPolicyTargetResource.Create("NYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new Uri("https://example.com"), client: twilioRestClient);

            Assert.NotNull(response);
        }
Esempio n. 2
0
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Voice,
                "/v1/ConnectionPolicies/NYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Targets",
                ""
                );

            request.AddPostParam("Target", Serialize(new Uri("https://example.com")));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                ConnectionPolicyTargetResource.Create("NYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new Uri("https://example.com"), client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }