Example #1
0
        public async Task ShouldReturnOneCustomer()
        {
            try
            {
                IRestionClient restionClient = new RestionClient()
                                                .SetBaseAddress("http://localhost/Restion.Tests.WebApi/api");

                var restionRequest = new RestionRequest("/Customer/")
                                          .AddParameter("Name","123")
                                          .AddParameter("DateOfBirth",DateTime.Now.ToShortDateString());

                var response = await restionClient.ExecuteRequestAsync<Customer>(restionRequest);

                if (response != null)
                {
                    if (response.Exception != null)
                    {
                        Assert.Fail(response.Exception.Message);
                    }
                    else
                    {
                        response.Content.Should().NotBeNull();
                    }
                }
                else
                {
                    Assert.Fail();
                }

            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #2
0
        public async Task ShouldReturnTrueForTestHeader()
        {
            try
            {
                IRestionClient restionClient = new RestionClient()
                    .SetBaseAddress("http://localhost/Restion.Tests.WebApi/api");

                var restionRequest = new RestionRequest("/Test/").AddHeader("Test-Header", "Test-Header-Value");

                var response = await restionClient.ExecuteRequestAsync<BolleanResponse>(restionRequest);

                if (response != null)
                {
                    if (response.Exception != null)
                    {
                        Assert.Fail(response.Exception.Message);
                    }
                    else
                    {
                        response.Content.Should().Be(new BolleanResponse() {Response = true});
                    }
                }
                else
                {
                    Assert.Fail();
                }

            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #3
0
        private async Task <GoogleMapsGeoCodingApiResponse> RequestGoogleMapsReverseGeoCodeApi(GeoLocation geolocationToReverseGeocode, string placeId)
        {
            var googleMapsGeoCodeRestionRequest = new RestionRequest().WithHttpMethod(HttpMethod.Get).AddParameter("key", _apiKey);

            if (geolocationToReverseGeocode != null)
            {
                googleMapsGeoCodeRestionRequest.AddParameter("latlng", geolocationToReverseGeocode.Latitude + "," + geolocationToReverseGeocode.Longitude);
            }
            else
            {
                googleMapsGeoCodeRestionRequest.AddParameter("place_id", placeId);
            }

            var googleMapsReverseGeoCodeRestionResponse = await _restionClient.ExecuteRequestAsync <GoogleMapsGeoCodingApiResponse>(googleMapsGeoCodeRestionRequest);

            if (googleMapsReverseGeoCodeRestionResponse.Exception != null)
            {
                throw googleMapsReverseGeoCodeRestionResponse.Exception;
            }

            if (googleMapsReverseGeoCodeRestionResponse.HttpStatusCode == HttpStatusCode.OK)
            {
                return(googleMapsReverseGeoCodeRestionResponse.Content);
            }

            return(null);
        }
        public async Task ShouldReturnOnePost()
        {
            try
            {
                var restionClient = new RestionClient()
                                       .SetBaseAddress("http://jsonplaceholder.typicode.com");

                var restionRequest = new RestionRequest("/posts/1");

                var response = await restionClient.ExecuteRequestAsync<Post>(restionRequest);

                if (response != null)
                {
                    if (response.Exception != null)
                    {
                        Assert.Fail(response.Exception.Message);
                    }
                    else
                    {
                        response.Content.Should().NotBeNull();
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public async Task ShouldReturnAllPosts()
        {
            try
            {
                IRestionClient restionClient = new RestionClient()
                    .SetBaseAddress("http://jsonplaceholder.typicode.com");

                var restionRequest = new RestionRequest("/posts/");

                var response = await restionClient.ExecuteRequestAsync<List<Post>>(restionRequest);

                if (response != null)
                {
                    if (response.Exception != null)
                    {
                        Assert.Fail(response.Exception.Message);
                    }
                    else
                    {
                       response.Content.Should().NotBeNull().And.HaveCount(100);
                    }
                }

            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #6
0
        //Methods

        //Private Methods
        private async Task <GoogleMapsGeoCodingApiResponse> RequestGoogleMapsGeoCodeApi(string rawAddressToGeocode)
        {
            var googleMapsGeoCodeRestionRequest = new RestionRequest()
                                                  .WithHttpMethod(HttpMethod.Get)
                                                  .AddParameter("address", rawAddressToGeocode)
                                                  .AddParameter("key", _apiKey);

            var googleMapsGeoCodeRestionResponse = await _restionClient.ExecuteRequestAsync <GoogleMapsGeoCodingApiResponse>(googleMapsGeoCodeRestionRequest);

            if (googleMapsGeoCodeRestionResponse.Exception != null)
            {
                throw googleMapsGeoCodeRestionResponse.Exception;
            }

            if (googleMapsGeoCodeRestionResponse.HttpStatusCode == HttpStatusCode.OK)
            {
                return(googleMapsGeoCodeRestionResponse.Content);
            }

            return(null);
        }
        public async Task ShouldPostAPost()
        {
            try
            {
                IRestionClient restionClient = new RestionClient()
                                       .SetBaseAddress("http://jsonplaceholder.typicode.com");

                IRestionRequest restionRequest = new RestionRequest("/posts/")
                                         .WithHttpMethod(HttpMethod.Post)
                                         .WithContent(new Post()
                                         {
                                             Body = "Teste",
                                             Title = "Teste",
                                             UserId = 1
                                         })
                                         .WithContentMediaType(MediaTypes.ApplicationJson)
                                         .WithContentEnconding(Encoding.UTF8);

                var response = await restionClient.ExecuteRequestAsync<Post>(restionRequest);

                if (response != null)
                {
                    if (response.Exception != null)
                    {
                        Assert.Fail(response.Exception.Message);
                    }
                    else
                    {
                        response.Content.Should().NotBeNull();
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }