title: Writing a unit test for a function with a web request
body: <p>This is a function that I want to write a unit test for:</p>
  
  <pre><code>public object RequestAndSerializeJSON(string url, Type type) {
      var request = (HttpWebRequest)WebRequest.Create(url);
      request.Accept = "application/json";
  
      var response = request.GetResponse();
      using (var responseStream = response.GetResponseStream())
      {
          DataContractJsonSerializer serializer = new DataContractJsonSerializer(type);
          return serializer.ReadObject(responseStream);
      }
  }
  </code></pre>
  
  <p>My first thought for testing this was to pass in a path to a file with test data in it for the url, but I can't do that because I'm casting it to an <code>HttpWebRequest</code> and it throws an error with a file path because it creates a <code>FileWebRequest</code> for file paths.</p>
  
  <p>What is a good way to do this?  I'm using the Visual Studio Test Tools for my testing.</p>