public void TestErrorHandling() { // Arrange var fakeResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError); var fakeWebRequestChannel = new FakeWebRequestChannel(fakeResponse); var httpClient = new HttpClient(fakeWebRequestChannel); var agent = new RestAgent(httpClient); // Act agent.NavigateTo(new Link() { Target = new Uri("http://example.org/") }); var content = agent.CurrentContent; // Assert Assert.IsNull(content); Assert.AreEqual(HttpStatusCode.InternalServerError, agent.CurrentStatusCode); }
public void TestRedirectHandling() { // Arrange var responses = new List<HttpResponseMessage>(); var redirectResponse = new HttpResponseMessage(HttpStatusCode.Redirect); redirectResponse.Headers.Location = new Uri("http://example.org/redirectlocation"); responses.Add(redirectResponse); var targetResponse = new HttpResponseMessage(HttpStatusCode.OK); responses.Add(targetResponse); var fakeWebRequestChannel = new FakeWebRequestChannel(responses); var httpClient = new HttpClient(fakeWebRequestChannel); var agent = new RestAgent(httpClient); // Act agent.NavigateTo(new Link() { Target = new Uri("http://example.org/") }); var content = agent.CurrentContent; // Assert Assert.IsNull(content); Assert.AreEqual(HttpStatusCode.OK, agent.CurrentStatusCode); Assert.AreEqual("http://example.org/redirectlocation", agent.CurrentLocation.Target.AbsoluteUri); }