Exemplo 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\",\"date_created\": \"2015-07-30T20:00:00Z\",\"date_updated\": \"2015-07-30T20:01:33Z\",\"sid\": \"DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"sink_sid\": \"DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"description\": \"A subscription\",\"url\": \"https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"links\": {\"subscribed_events\": \"https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents\"}}"
                         ));

            var response = SubscriptionResource.Create("description", "DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", Promoter.ListOfOne((object)"{}"), client: twilioRestClient);

            Assert.NotNull(response);
        }
Exemplo n.º 2
0
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Events,
                "/v1/Subscriptions",
                ""
                );

            request.AddPostParam("Description", Serialize("description"));
            request.AddPostParam("SinkSid", Serialize("DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
            request.AddPostParam("Types", Serialize((object)"{}"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                SubscriptionResource.Create("description", "DGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", Promoter.ListOfOne((object)"{}"), client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }