In your code you can not intercept the calls to HttpWebRequestHttpWebRequest because you create the object in the same method. If you let another object create the HttpWebRequestHttpWebRequest, you can pass in a mock object and use that to test.
So instead of this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url); Use this:
IHttpWebRequest request = this.WebRequestFactory.Create(_url); In your unit test, you can pass in a WebRequestFactoryWebRequestFactory which creates a mock object.
Furthermore, you can split of your stream reading code in a seperateseparate function:
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { byte[] data = ReadStream(response.GetResponseStream()); return ExtractResponse(Encoding.UTF8.GetString(data)); } This makes it possible to test ReadStream() seperatelyReadStream() separately.
To do more of an integration test, you can set up your own HTTP server which returns test data, and pass the URL of that server to your method.