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)); }
public void TestMockedGet() { var mockHandler = new MockHttpMessageHandler(); mockHandler .Expect(HttpMethod.Get, "http://127.0.0.1") .WithHeaders("Accept", "application/json") .Respond("text/plain", "GET OK"); var client = new corerestclient.RestClient(mockHandler); var result = client.Get("http://127.0.0.1"); Assert.True(result.Contains("GET OK")); mockHandler.VerifyNoOutstandingExpectation(); }
public void TestMockedGetWithOtherAuthAndContentType() { var mockHandler = new MockHttpMessageHandler(); mockHandler .Expect(HttpMethod.Get, "http://127.0.0.1") .WithHeaders("Accept", "text/plain") .WithHeaders("Authorization", "Basic basicAuthUser:basicAuthPassword") .Respond("text/plain", "GET OK"); var client = new corerestclient.RestClient("Basic", "basicAuthUser:basicAuthPassword", "text/plain", mockHandler); var result = client.Get("http://127.0.0.1"); Assert.True(result.Contains("GET OK")); mockHandler.VerifyNoOutstandingExpectation(); }