Exemple #1
0
        public void SimpleWithNonDefaultPort()
        {
            RestUri target = new RestUri("http://localhost:50001/", "account");

            var actual = target.ToString();

            Assert.Equal("http://localhost:50001/account", actual);
        }
Exemple #2
0
        public void WithUriTemplateParameter()
        {
            RestUri target = new RestUri("http://localhost/", "account/{id}").SetParameter("id", 1);

            var actual = target.ToString();

            Assert.Equal("http://localhost/account/1", actual);
        }
Exemple #3
0
        public Task <RestResponse <T> > PatchAsync <T>(RestUri uri, RestRequestBody requestBody, ContentType contentType)
        {
            RestRequest request = CreateRestRequest(HttpMethod.PATCH, uri);

            request.Body        = requestBody;
            request.ContentType = contentType;
            return(InvokeAsync <T>(request));
        }
Exemple #4
0
        public void SimpleWithPathPortionInUrlAndNoTrailingAndLeadingSlashes()
        {
            RestUri target = new RestUri("http://localhost/api", "account");

            var actual = target.ToString();

            Assert.Equal("http://localhost/api/account", actual);
        }
Exemple #5
0
        public void SimpleWithPathPortionInUrlAndNoTrailingAndLeadingSlashes()
        {
            RestUri target = new RestUri("http://localhost/api", "account");

            var actual = target.ToString();

            Assert.Equal("http://localhost/api/account", actual);
        }
Exemple #6
0
        public void SimpleWithPathPortionInUrlAndTrailingAndLeadingSlashesInBaseUriAndResourceUrlRespectively()
        {
            RestUri target = new RestUri("http://localhost/api/", "/account");

            var actual = target.ToString();

            Assert.Equal("http://localhost/api/account", actual);
        }
Exemple #7
0
        public void WithSingleQueryString()
        {
            RestUri target = new RestUri("http://localhost/", "account").SetQuery("id", 1);

            var actual = target.ToString();

            Assert.Equal("http://localhost/account?id=1", actual);
        }
Exemple #8
0
        public void WithUriTemplateParameter()
        {
            RestUri target = new RestUri("http://localhost/", "account/{id}").SetParameter("id", 1);

            var actual = target.ToString();

            Assert.Equal("http://localhost/account/1", actual);
        }
Exemple #9
0
        public Task <RestResponse> PutAsync(RestUri uri, RestRequestBody requestBody, ContentType contentType)//1
        {
            RestRequest request = CreateRestRequest(HttpMethod.PUT, uri);

            request.Body        = requestBody;
            request.ContentType = contentType;
            return(InvokeAsync(request));
        }
Exemple #10
0
        public void Simple()
        {
            RestUri target = new RestUri("http://localhost/", "account");

            var actual = target.ToString();

            Assert.Equal("http://localhost/account", actual);
        }
Exemple #11
0
        public void SimpleWithNonDefaultPort()
        {
            RestUri target = new RestUri("http://localhost:50001/", "account");

            var actual = target.ToString();

            Assert.Equal("http://localhost:50001/account", actual);
        }
Exemple #12
0
        public void Simple()
        {
            RestUri target = new RestUri("http://localhost/", "account");

            var actual = target.ToString();

            Assert.Equal("http://localhost/account", actual);
        }
Exemple #13
0
        public void SimpleWithPathPortionInUrlAndTrailingAndLeadingSlashesInBaseUriAndResourceUrlRespectively()
        {
            RestUri target = new RestUri("http://localhost/api/", "/account");

            var actual = target.ToString();

            Assert.Equal("http://localhost/api/account", actual);
        }
Exemple #14
0
        public void WithMultipleUriTemplateParameter()
        {
            RestUri target = new RestUri("http://localhost/", "account/{id}/{uid}/{date}/{email}").SetParameter("id", 1).SetParameter("uid", new Guid("5AAE425D-A603-43B7-86CE-D66EF0AC870C")).SetParameter("date", new DateTime(2010, 1, 1)).SetParameter("email", "*****@*****.**");

            var actual = target.ToString();
            var dateString = Uri.EscapeDataString(new DateTime(2010, 1, 1).ToString());
            var expected = string.Format("http://localhost/account/1/5aae425d-a603-43b7-86ce-d66ef0ac870c/{0}/abc%40abc.com", dateString);
            Assert.Equal(expected, actual);
        }
Exemple #15
0
        public void WithQueryStringRepeatedInBaseUrlAndUsingSetQuery()
        {
            RestUri target = new RestUri("http://localhost/account?id=1").SetQuery("id", 2);

            var actual = target.ToString();

            var expected = "http://localhost/account?id=2";

            Assert.Equal(expected, actual);
        }
Exemple #16
0
        public void WithQueryStringNotInNameValueFormatOption2()
        {
            RestUri target = new RestUri("http://localhost/", "account").SetQuery("123456", QueryStringParameter.None);

            var actual = target.ToString();

            var expected = "http://localhost/account?123456";

            Assert.Equal(expected, actual);
        }
Exemple #17
0
        public void WithMultipleUriTemplateParameter()
        {
            RestUri target = new RestUri("http://localhost/", "account/{id}/{uid}/{date}/{email}").SetParameter("id", 1).SetParameter("uid", new Guid("5AAE425D-A603-43B7-86CE-D66EF0AC870C")).SetParameter("date", new DateTime(2010, 1, 1)).SetParameter("email", "*****@*****.**");

            var actual     = target.ToString();
            var dateString = Uri.EscapeDataString(new DateTime(2010, 1, 1).ToString());
            var expected   = string.Format("http://localhost/account/1/5aae425d-a603-43b7-86ce-d66ef0ac870c/{0}/abc%40abc.com", dateString);

            Assert.Equal(expected, actual);
        }
Exemple #18
0
        public void WithOnlyQueryStringInResourceUrl()
        {
            RestUri target = new RestUri("http://localhost/account", "?id=1");

            var actual = target.ToString();

            var expected = "http://localhost/account?id=1";

            Assert.Equal(expected, actual);
        }
Exemple #19
0
        public void WithQueryStringNotInNameValueFormatOption3()
        {
            RestUri target = new RestUri("http://localhost/", "account?123456").SetQuery("id", "1");

            var actual = target.ToString();

            var expected = "http://localhost/account?123456&id=1";

            Assert.Equal(expected, actual);
        }
Exemple #20
0
        public void WithEmbededUrlInQueryString()
        {
            RestUri target = new RestUri("http://localhost/account/")
                             .SetQuery("redirectTo", "http://localhost/login");

            var actual = target.ToString();

            var expected = "http://localhost/account?redirectTo=http%3A%2F%2Flocalhost%2Flogin";

            Assert.Equal(expected, actual);
        }
Exemple #21
0
        public void WithEmbededUrlWithPortInUriTemplate()
        {
            RestUri target = new RestUri("http://localhost/account/{redirectTo}")
                             .SetParameter("redirectTo", "http://localhost:80/login");

            var actual = target.ToString();

            var expected = "http://localhost/account/http%3A%2F%2Flocalhost%3A80%2Flogin";

            Assert.Equal(expected, actual);
        }
Exemple #22
0
        public void WithMultipleQueryStrings()
        {
            RestUri target = new RestUri("http://localhost/", "account").SetQuery("id", 1).SetQuery("date", new DateTime(2010, 1, 1)).SetQuery("uid", new Guid("5AAE425D-A603-43B7-86CE-D66EF0AC870C"));

            var actual = target.ToString();

            var dateString = Uri.EscapeDataString(new DateTime(2010, 1, 1).ToString());
            var expected   = string.Format("http://localhost/account?id=1&date={0}&uid=5aae425d-a603-43b7-86ce-d66ef0ac870c", dateString);

            Assert.Equal(expected, actual);
        }
Exemple #23
0
        private RestRequest CreateRestRequest(HttpMethod method, RestUri uri)
        {
            var restRequest = new RestRequest(method, uri);

            foreach (Cookie cookie in _cookies)
            {
                restRequest.AddCookie(cookie);
            }

            foreach (var header in _headers)
            {
                if (header.Key is string)
                {
                    restRequest.AddHeader(header.Key.ToString(), header.Value.ToString());
                }
                else if (header.Key is HttpRequestHeader)
                {
                    restRequest.AddHeader((HttpRequestHeader)header.Key, header.Value.ToString());
                }
            }

            restRequest.AllowAutoRedirect      = AllowAutoRedirect;
            restRequest.AuthenticationLevel    = AuthenticationLevel;
            restRequest.AutomaticDecompression = AutomaticDecompression;
            restRequest.CachePolicy            = CachePolicy;
            if (ClientCertificates != null)
            {
                foreach (var cert in ClientCertificates)
                {
                    restRequest.ClientCertificates.Add(cert);
                }
            }
            restRequest.Credentials = Credentials;
            restRequest.KeepAlive   = KeepAlive;
            restRequest.MaximumAutomaticRedirections = MaximumAutomaticRedirections;
            restRequest.Referer             = Referer;
            restRequest.TcpKeepAlive        = TcpKeepAlive;
            restRequest.TcpKeepAliveTimeOut = TcpKeepAliveTimeOut;
            restRequest.TimeOut             = TimeOut;
            restRequest.UserAgent           = UserAgent;

            return(restRequest);
        }
Exemple #24
0
        private RestUri CreateRestUri(Uri baseUri, string resourceUri, object parameters)
        {
            var uri = new RestUri(baseUri, resourceUri);

            var nameValuePairs = parameters.ToDictionary();

            foreach (var nameValue in nameValuePairs)
            {
                if (resourceUri.IndexOf("{" + nameValue.Key + "}") > -1)
                {
                    uri.SetParameter(nameValue.Key, nameValue.Value);
                }
                else
                {
                    uri.SetQuery(nameValue.Key, nameValue.Value);
                }
            }

            return(uri);
        }
Exemple #25
0
 public Task <RestResponse <T> > DeleteAsync <T>(RestUri uri)
 {
     return(InvokeAsync <T>(CreateRestRequest(HttpMethod.DELETE, uri)));
 }
Exemple #26
0
        public void WithQueryStringRepeatedInBaseUrlAndUsingSetQuery()
        {
            RestUri target = new RestUri("http://localhost/account?id=1").SetQuery("id", 2);

            var actual = target.ToString();

            var expected = "http://localhost/account?id=2";
            Assert.Equal(expected, actual);
        }
Exemple #27
0
        public void WithEmbededUrlWithPortInUriTemplate()
        {
            RestUri target = new RestUri("http://localhost/account/{redirectTo}")
                .SetParameter("redirectTo", "http://localhost:80/login");

            var actual = target.ToString();

            var expected = "http://localhost/account/http%3A%2F%2Flocalhost%3A80%2Flogin";
            Assert.Equal(expected, actual);
        }
Exemple #28
0
        public void WithMultipleQueryStrings()
        {
            RestUri target = new RestUri("http://localhost/", "account").SetQuery("id", 1).SetQuery("date", new DateTime(2010, 1, 1)).SetQuery("uid", new Guid("5AAE425D-A603-43B7-86CE-D66EF0AC870C"));

            var actual = target.ToString();

            var dateString = Uri.EscapeDataString(new DateTime(2010, 1, 1).ToString());
            var expected = string.Format("http://localhost/account?id=1&date={0}&uid=5aae425d-a603-43b7-86ce-d66ef0ac870c", dateString);
            Assert.Equal(expected, actual);
        }
Exemple #29
0
 public RestRequestBuilder(HttpMethod method, RestUri uri)
 {
     _request = new RestRequest(method, uri);
 }
Exemple #30
0
 public Task <RestResponse <T> > PatchAsync <T>(RestUri uri, RestRequestBody requestBody)
 {
     return(PatchAsync <T>(uri, requestBody, ContentType.ApplicationX_WWW_Form_UrlEncoded));
 }
Exemple #31
0
 public RestResponse <T> Patch <T>(RestUri uri, RestRequestBody requestBody, ContentType contentType)
 {
     return(PatchAsync <T>(uri, requestBody, contentType).Result);
 }
Exemple #32
0
 public RestResponse Patch(RestUri uri, RestRequestBody requestBody)
 {
     return(PatchAsync(uri, requestBody).Result);
 }
        public void NamedParametersAreReplaced()
        {
            var restUri = new RestUri("http://domain.ext/{foo}/index.{ext}", new { foo = "bar", ext = "html" });

            Assert.Equal("http://domain.ext/bar/index.html", restUri.AbsoluteUri);
        }
        public void Patch_overload1()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PatchPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var uri = new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1");
            var contentType = ContentType.ApplicationX_WWW_Form_UrlEncoded;
            var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" });

            //Act
            using (RestResponse actual = target.Patch(uri, body, contentType))
            {
                //Assert
                Assert.True(StubModule.PatchPerson);
                Assert.NotNull(actual);
                Assert.True(actual.IsSuccessStatusCode);

                var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault();
                Assert.NotNull(person);
                Assert.Equal("*****@*****.**", person.Email);
            }
        }
Exemple #35
0
 public static RestRequestBuilder CreateRequest(HttpMethod method, RestUri uri)
 {
     return(new RestRequestBuilder(method, uri));
 }
Exemple #36
0
        public void WithOnlyQueryStringInResourceUrl()
        {
            RestUri target = new RestUri("http://localhost/account", "?id=1");

            var actual = target.ToString();

            var expected = "http://localhost/account?id=1";
            Assert.Equal(expected, actual);
        }
 public static RestRequestBuilder CreateRequest(HttpMethod method, RestUri uri)
 {
     return new RestRequestBuilder(method, uri);
 }
Exemple #38
0
        public void WithQueryStringNotInNameValueFormatOption2()
        {
            RestUri target = new RestUri("http://localhost/", "account").SetQuery("123456", QueryStringParameter.None);

            var actual = target.ToString();

            var expected = "http://localhost/account?123456";
            Assert.Equal(expected, actual);
        }
Exemple #39
0
        public void WithEmbededUrlInQueryString()
        {
            RestUri target = new RestUri("http://localhost/account/")
                .SetQuery("redirectTo", "http://localhost/login");

            var actual = target.ToString();

            var expected = "http://localhost/account?redirectTo=http%3A%2F%2Flocalhost%2Flogin";
            Assert.Equal(expected, actual);
        }
Exemple #40
0
 public RestResponse <T> Delete <T>(RestUri uri)
 {
     return(DeleteAsync <T>(uri).Result);
 }
 public RestRequestBuilder(HttpMethod method, RestUri uri)
 {
     _request = new RestRequest(method, uri);
 }
Exemple #42
0
 public RestResponse <T> Get <T>(RestUri uri)
 {
     return(GetAsync <T>(uri).Result);
 }
Exemple #43
0
        public void WithQueryStringNotInNameValueFormatOption3()
        {
            RestUri target = new RestUri("http://localhost/", "account?123456").SetQuery("id", "1");

            var actual = target.ToString();

            var expected = "http://localhost/account?123456&id=1";
            Assert.Equal(expected, actual);
        }
Exemple #44
0
 public Task <RestResponse <T> > GetAsync <T>(RestUri uri)
 {
     return(InvokeAsync <T>(CreateRestRequest(HttpMethod.GET, uri)));
 }
Exemple #45
0
 public RestResponse Delete(RestUri uri)
 {
     return(DeleteAsync(uri).Result);
 }
Exemple #46
0
 public RestResponse <T> Patch <T>(RestUri uri, RestRequestBody requestBody)
 {
     return(PatchAsync <T>(uri, requestBody).Result);
 }
        public void Post_overload2()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PostPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var uri = new RestUri(_MyUri, "/Person");
            var body = new RestObjectRequestBody<Person>(new Person { Id = 2, Email = "*****@*****.**" });

            //Act
            using (RestResponse actual = target.Post(uri, body))
            {
                //Assert
                Assert.True(StubModule.PostPerson);
                Assert.NotNull(actual);
                Assert.True(actual.IsSuccessStatusCode);
                var person = StubModule.TestHarness.Where(x => x.Id == 2).FirstOrDefault();
                Assert.NotNull(person);
                Assert.Equal("*****@*****.**", person.Email);
            }
        }
        public void PatchAsync_overload2()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PatchPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var uri = new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1");
            var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" });

            //Act
            target.PatchAsync(uri, body).ContinueWith(task =>
            {
                using (RestResponse actual = task.Result)
                {
                    //Assert
                    Assert.True(StubModule.PatchPerson);
                    Assert.NotNull(actual);
                    Assert.True(actual.IsSuccessStatusCode);

                    var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault();
                    Assert.NotNull(person);
                    Assert.Equal("*****@*****.**", person.Email);
                }
            }).Wait();
        }
Exemple #49
0
        public void WithSingleQueryString()
        {
            RestUri target = new RestUri("http://localhost/", "account").SetQuery("id", 1);

            var actual = target.ToString();

            Assert.Equal("http://localhost/account?id=1", actual);
        }
        public void PostAsync_overload1()
        {
            //Arrange
            RestInvoker target = new RestInvoker(_MyUri.OriginalString);
            StubModule.HaltProcessing = TimeSpan.FromSeconds(0);
            StubModule.PostPerson = false;
            StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } };

            var uri = new RestUri(_MyUri, "/Person");
            var contentType = ContentType.ApplicationX_WWW_Form_UrlEncoded;
            var body = new RestObjectRequestBody<Person>(new Person { Id = 2, Email = "*****@*****.**" });

            //Act
            target.PostAsync(uri, body, contentType).ContinueWith(task =>
            {
                using (RestResponse actual = task.Result)
                {
                    //Assert
                    Assert.True(StubModule.PostPerson);
                    Assert.NotNull(actual);
                    Assert.True(actual.IsSuccessStatusCode);
                    var person = StubModule.TestHarness.Where(x => x.Id == 2).FirstOrDefault();
                    Assert.NotNull(person);
                    Assert.Equal("*****@*****.**", person.Email);
                }
            }).Wait();
        }