public async Task SendAsync_WithRequestOptions_Success()
        {
            var httpClientMock = new HttpClientMock();
            var httpClient     = new DefaultHttpClient(httpClientMock.HttpClient);
            var client         = new DummyClient(httpClient, null);
            var path           = "/x";
            var url            = $"{MercadoPagoConfig.BaseUrl}{path}";
            var request        = new DummyRequest("hello");

            var requestOptions = new RequestOptions
            {
                AccessToken   = Guid.NewGuid().ToString(),
                RetryStrategy = new DefaultRetryStrategy(0),
            };

            requestOptions.CustomHeaders.Add("X-Custom-Header", "custom");
            requestOptions.CustomHeaders.Add(Headers.ContentType, "plain/text");       // should not add
            requestOptions.CustomHeaders.Add(Headers.Authorization, "Basic user:123"); // should not add

            var httpResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{'name':'world'}"),
            };

            httpResponse.Headers.Add("X-Custom-Response-Header", "456");

            // Mock
            httpClientMock.MockRequest(url, System.Net.Http.HttpMethod.Put, httpResponse);

            DummyResource dummyResource =
                await client.SendAsync(path, MercadoPagoCore.Http.HttpMethod.Put, request, requestOptions);

            Assert.NotNull(dummyResource);
            Assert.Equal("world", dummyResource.Name);
        }
        public async Task SendAsync_WithBodyIdempotent_Success()
        {
            var httpClientMock = new HttpClientMock();
            var httpClient     = new DefaultHttpClient(httpClientMock.HttpClient);
            var client         = new DummyClient(httpClient, null);
            var path           = "/x";
            var url            = $"{MercadoPagoConfig.BaseUrl}{path}";
            var request        = new DummyIdempotentRequest("hello");

            var httpResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{'name':'world'}"),
            };

            httpResponse.Headers.Add("X-Custom-Response-Header", "456");

            // Mock
            httpClientMock.MockRequest(url, System.Net.Http.HttpMethod.Post, httpResponse);

            DummyResource dummyResource =
                await client.SendAsync(path, MercadoPagoCore.Http.HttpMethod.Post, request);

            Assert.NotNull(dummyResource);
            Assert.Equal("world", dummyResource.Name);
        }
Beispiel #3
0
        public void Send_WithoutBody_Success()
        {
            var httpClientMock = new HttpClientMock();
            var httpClient     = new DefaultHttpClient(httpClientMock.HttpClient);
            var client         = new DummyClient(httpClient, null);
            var path           = "/x";
            var url            = $"{MercadoPagoConfig.BaseUrl}{path}";

            var httpResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{'name':'world'}"),
            };

            httpResponse.Headers.Add("X-Custom-Response-Header", "456");

            // Mock
            httpClientMock.MockRequest(url, System.Net.Http.HttpMethod.Get, httpResponse);

            DummyResource dummyResource =
                client.Send(path, MercadoPago.Http.HttpMethod.GET, null);

            Assert.NotNull(dummyResource);
            Assert.Equal("world", dummyResource.Name);
        }