public void WillValidatePathParams()
        {
            var        client   = MockClient.Build(SuccessResponse(System.Net.HttpStatusCode.OK));
            MyResource resource = client.GetResource("benjamin", "param1", new DateTime(2020, 01, 01));

            Assert.Throws <Recurly.RecurlyError>(() => client.GetResource("", "param1", new DateTime(2020, 01, 01)));
        }
예제 #2
0
        private MockClient GetPagerSuccessClient()
        {
            var page1Response = PagerSuccessPage1Response();
            Func <IRestRequest, bool> page1Matcher = delegate(IRestRequest request)
            {
                if (request.Resource == "/resources")
                {
                    return(true);
                }
                return(false);
            };
            var page2Response = PagerSuccessPage2Response();
            Func <IRestRequest, bool> page2Matcher = delegate(IRestRequest request)
            {
                if (request.Resource == "/next-page")
                {
                    return(true);
                }
                return(false);
            };
            var mockCollection = new Dictionary <Func <IRestRequest, bool>, Mock <IRestResponse <Pager <MyResource> > > > {
                { page1Matcher, page1Response },
                { page2Matcher, page2Response },
            };

            return(MockClient.Build(mockCollection));
        }
        public async void CanProperlyFetchAResourceAsync()
        {
            var        client   = MockClient.Build(SuccessResponse(System.Net.HttpStatusCode.OK));
            MyResource resource = await client.GetResourceAsync("benjamin", "param1", new DateTime(2020, 01, 01));

            Assert.Equal("benjamin", resource.MyString);
        }
        public void CanProperlyCreateAResource()
        {
            var client  = MockClient.Build(SuccessResponse(System.Net.HttpStatusCode.Created));
            var request = new MyResourceCreate()
            {
                MyString = "benjamin"
            };
            MyResource resource = client.CreateResource(request);

            Assert.Equal("benjamin", resource.MyString);
        }
        public void WillEncodeForwardSlashesInURL()
        {
            Func <IRestRequest, bool> matcher = delegate(IRestRequest request)
            {
                Assert.Equal("/my_resources/douglas%2F", request.Resource);
                return(true);
            };
            var client = MockClient.Build(matcher, NotFoundResponse());

            Assert.Throws <Recurly.Errors.NotFound>(() => client.GetResource("douglas/", "param1", new DateTime(2020, 01, 01)));
        }
        public void WillIncludeCustomHeaders()
        {
            var options = new RequestOptions();

            options.AddHeader("Accept-Language", "en-US");
            var matcher = MockClient.HeaderMatcher(new Dictionary <string, object> {
                { "Accept-Language", "en-US" },
            });
            var client = MockClient.Build(matcher, NotFoundResponse());

            Assert.Throws <Recurly.Errors.NotFound>(() => client.GetResource("douglas/", "param1", new DateTime(2020, 01, 01), options));
        }
        public void WillAddQueryStringParameters()
        {
            var options = new RequestOptions();

            options.AddHeader("Accept-Language", "en-US");
            var date          = new DateTime(2020, 01, 01);
            var paramsMatcher = MockClient.QueryParameterMatcher(new Dictionary <string, object> {
                { "param_1", "param1" },
                { "param_2", Recurly.Utils.ISO8601(date) },
            });

            var        client   = MockClient.Build(paramsMatcher, SuccessResponse(System.Net.HttpStatusCode.OK));
            MyResource resource = client.GetResource("benjamin", "param1", date, options);

            Assert.Equal("benjamin", resource.MyString);
        }
예제 #8
0
        public void EmptyEnumerableTest()
        {
            var client = MockClient.Build(PagerEmptyResponse());
            var pager  = Pager <MyResource> .Build("/resources", new Dictionary <string, object> {
            }, null, client);

            var i = 0;

            foreach (MyResource r in pager)
            {
                Assert.True(false, "Should not be iterating anything if response is empty");
            }

            // There should be 0 resources
            Assert.Equal(0, i);
        }
예제 #9
0
        public void PagerFirstTest()
        {
            var paramsMatcher = MockClient.QueryParameterMatcher(new Dictionary <string, object> {
                { "limit", "1" },
                { "a", "1" },
            });
            var client = MockClient.Build(paramsMatcher, PagerFirstResponse());

            var queryParams = new Dictionary <string, object> {
                { "limit", "200" },
                { "a", "1" },
            };
            var pager = Pager <MyResource> .Build("/resources", queryParams, null, client);

            var resource = pager.First();

            Assert.Equal("First Resource", resource.MyString);
        }
        public void WillThrowAnExceptionWhenResponseHasErrorException()
        {
            var client = MockClient.Build(ErroredResponse());

            Assert.Throws <Recurly.RecurlyError>(() => client.GetResource("benjamin", "param1", new DateTime(2020, 01, 01)));
        }
        public void WillThrowNotFoundExceptionForNon200()
        {
            var client = MockClient.Build(NotFoundResponse());

            Assert.Throws <Recurly.Errors.NotFound>(() => client.GetResource("benjamin", "param1", new DateTime(2020, 01, 01)));
        }