title: Unit test for http web request and response in c#
body: <p>I want to write a unit test for http web request and response method. Please find the below method,</p>
  
  <pre><code> public string GetEmployeeId()
          {
  
                  var tokenRequest = (HttpWebRequest)WebRequest.Create("http://www.goggle.com");
                  tokenRequest.Method = "POST";
                  tokenRequest.ContentType = "application/x-www-form-urlencoded";
  
                  var bytes = Encoding.UTF8.GetBytes(GetKeys(credentials));
                  tokenRequest.ContentLength = bytes.Length;
  
                  Response response;
                   using (var stream = tokenRequest.GetRequestStream())
                      {
                          stream.Write(bytes, 0, bytes.Length);
                          stream.Flush();
  
                          using (var webResponse = request.GetResponse())
                          {
                              Stream receiveStream = webResponse.GetResponseStream();
                              StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
                              MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(readStream.ReadToEnd()));
                              DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                              response = ser.ReadObject(ms) as Response;
                              ms.Close();
                              readStream.Close();
                          }
                      }
                  }
            return response.Id;
  
          }
  
    private string GetKeys(Credentials credentials)
          {
              return String.Format(@"client_id={0}&amp;client_secret={1}&amp;grant_type=client_credentials",
                                  credentials.Id, credentials.Secret);
          }
  </code></pre>
  
  <p>I dont know how to write unit test for web request methods.Can anyone suggest how to write unit test for the above method?</p>