title: Mocking HTTP request in unit test
body: <p>I start learn Moq and I have this problem. I need mock class/interface which make HTTP GET and HTTP POST request and return HTML string as server response.</p>
  
  <p>I simplified my code. Here is:</p>
  
  <pre><code>public interface IHttpManager
  {
      /// &lt;summary&gt;
      /// Make HTTP GET request on server and return HTML string
      /// &lt;/summary&gt;
      string HttpGet(Uri url, CookieContainer cookies, HttpRequestSettings settings);
  
      /// &lt;summary&gt;
      /// Make HTTP POST request and return HTML string
      /// &lt;/summary&gt;
      string HttpPost(Uri url, string postData, CookieContainer cookies, HttpRequestSettings settings);
  }
  </code></pre>
  
  <p>I use <code>IHttpManager</code> in class <code>ConnectionManager</code> which make log in or log off on server.</p>
  
  <pre><code>public interface IConectionManager
  {
      /// &lt;summary&gt;
      /// Connect to server and parse HTML response
      /// &lt;/summary&gt;
      Result&lt;T&gt; LogIn(string nick, string password);
  
      /// &lt;summary&gt;
      /// Log off and parse HTML response
      /// &lt;/summary&gt;
      /// &lt;param name="account"&gt;&lt;/param&gt;
      void LogOff(Acccount account);
  }
  
  public class ConnectionManager : IConectionManager
  {
      private IHttpManager _httpManager;
      private HttpRequestSettings _httpRequestSettings;
  
      public ConnectionManager(IHttpManager httpManager, HttpRequestSettings httpRequestSettings)
      {
          _httpManager = httpManager;
          _httpRequestSettings = httpRequestSettings;
      }
  
      public Result&lt;Account&gt; LogIn(string nick, string password)
      {
          // I simplified this method
  
          // How correct mock IHttpManager, because it must return HTML string
          // so in Moq in Setup return hard coded HTML string which represent server response ?
          string htmlStringResponse = _httpManager.HttpGet(ServerUrl.LogOn, new CookieContainer(), _httpRequestSettings);
  
          // parse HTML string and return result
      }
  
      // ...
  }
  </code></pre>
  
  <p>I unit test for method <code>LogIn</code>. I would like to mock <code>IHttpManager</code>. But I don’t how to do in correct way.</p>
  
  <p>I try this:</p>
  
  <pre><code>// Arrange
  var mockHttpManager = new Mock&lt;IHttpManager&gt;();
  
  mockHttpManager.Setup(x=&gt;x.HttpGet()).Returns(()=&gt;"HTML SERVER RESPONSE");
  
  var sut = new ConnectionManager(mockHttpManager.Object, new HttpRequestSettings());
  
  // act
  sut.Login("nick", "123")
  
  // Assert
  </code></pre>