Ejemplo n.º 1
0
        public void GetWithoutAuth()
        {
            var client = new corerestclient.RestClient();
            var result = client.Get("https://api.stackexchange.com/2.2/questions?page=1&pagesize=1&order=desc&sort=activity&site=stackoverflow");

            Assert.False(string.IsNullOrEmpty(result));
        }
Ejemplo n.º 2
0
        public void TestMockedDelete()
        {
            var mockHandler = new MockHttpMessageHandler();

            mockHandler
            .Expect(HttpMethod.Delete, "http://127.0.0.1")
            .WithHeaders("Accept", "application/json")
            .Respond("text/plain", "DELETE OK");
            var client = new corerestclient.RestClient(mockHandler);
            var result = client.Delete("http://127.0.0.1");

            Assert.True(result.Contains("DELETE OK"));
            mockHandler.VerifyNoOutstandingExpectation();
        }
Ejemplo n.º 3
0
        public void TestMockedPatch()
        {
            var mockHandler = new MockHttpMessageHandler();

            mockHandler
            .Expect("http://127.0.0.1")
            .WithHeaders("Accept", "application/json")
            .WithContent("PATCH CONTENT")
            .Respond("text/plain", "PATCH OK");
            var client = new corerestclient.RestClient(mockHandler);
            var result = client.Patch("http://127.0.0.1", "PATCH CONTENT");

            Assert.True(result.Contains("PATCH OK"));
            mockHandler.VerifyNoOutstandingExpectation();
        }
Ejemplo n.º 4
0
        public void TestMockedDeleteWithOtherAuthAndContentType()
        {
            var mockHandler = new MockHttpMessageHandler();

            mockHandler
            .Expect(HttpMethod.Delete, "http://127.0.0.1")
            .WithHeaders("Accept", "text/plain")
            .WithHeaders("Authorization", "Basic basicAuthUser:basicAuthPassword")
            .Respond("text/plain", "DELETE OK");
            var client = new corerestclient.RestClient("Basic", "basicAuthUser:basicAuthPassword", "text/plain", mockHandler);
            var result = client.Delete("http://127.0.0.1");

            Assert.True(result.Contains("DELETE OK"));
            mockHandler.VerifyNoOutstandingExpectation();
        }
Ejemplo n.º 5
0
        public void TestMockedGetWithAuthAndContentType()
        {
            var mockHandler = new MockHttpMessageHandler();

            mockHandler
            .Expect(HttpMethod.Get, "http://127.0.0.1")
            .WithHeaders("Accept", "text/plain")
            .WithHeaders("Authorization", "basicAuthToken")
            .Respond("text/plain", "GET OK");
            var client = new corerestclient.RestClient("basicAuthToken", "text/plain", mockHandler);
            var result = client.Get("http://127.0.0.1");

            Assert.True(result.Contains("GET OK"));
            mockHandler.VerifyNoOutstandingExpectation();
        }
Ejemplo n.º 6
0
        public void TestMockedPutWithAuth()
        {
            var mockHandler = new MockHttpMessageHandler();

            mockHandler
            .Expect(HttpMethod.Put, "http://127.0.0.1/testResource")
            .WithHeaders("Accept", "application/json")
            .WithHeaders("Authorization", "basicAuthToken")
            .WithContent("PUT CONTENT")
            .Respond("text/plain", "PUT OK");
            var client = new corerestclient.RestClient("basicAuthToken", mockHandler);
            var result = client.Put("http://127.0.0.1", "testResource", "PUT CONTENT");

            Assert.True(result.Contains("PUT OK"));
            mockHandler.VerifyNoOutstandingExpectation();
        }