/// <summary> /// Test what happens when we get a 404 response from a call. /// </summary> // [Test] public void Test404Response() { TestHelpers.InMethod(); TestHelpers.EnableLogging(); if (!Util.IsPlatformMono) Assert.Ignore("Ignoring test since can only currently run on Mono"); string rawResponse = "boom"; TestWebRequestCreate twrc = new TestWebRequestCreate(); TestWebRequest twr = new TestWebRequest(); //twr.OnEndGetResponse += ar => new TestHttpWebResponse(null, new StreamingContext()); twr.OnEndGetResponse += ar => { SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new FormatterConverter()); StreamingContext sc = new StreamingContext(); // WebHeaderCollection headers = new WebHeaderCollection(); // si.AddValue("m_HttpResponseHeaders", headers); si.AddValue("uri", new Uri("test://arrg")); // si.AddValue("m_Certificate", null); si.AddValue("version", HttpVersion.Version11); si.AddValue("statusCode", HttpStatusCode.NotFound); si.AddValue("contentLength", 0); si.AddValue("method", "GET"); si.AddValue("statusDescription", "Not Found"); si.AddValue("contentType", null); si.AddValue("cookieCollection", new CookieCollection()); TestHttpWebResponse thwr = new TestHttpWebResponse(si, sc); thwr.Response = rawResponse; throw new WebException("no message", null, WebExceptionStatus.ProtocolError, thwr); }; twrc.NextRequest = twr; WebRequest.RegisterPrefix("test", twrc); HttpRequestClass hr = new HttpRequestClass(); hr.Url = "test://something"; hr.SendRequest(); Assert.That(hr.Status, Is.EqualTo((int)HttpStatusCode.NotFound)); Assert.That(hr.ResponseBody, Is.EqualTo(rawResponse)); }