title: How to mock RestSharp portable library in Unit Test
body: <p>I would like to mockup the RestClient class for test purposes</p>
  
  <pre><code>public class DataServices : IDataServices
  {
      private readonly IRestClient _restClient;
  
  
      public DataServices(IRestClient restClient)
      {
          _restClient = restClient;
      }
  
      public async Task&lt;User&gt; GetUserByUserName(string userName)
      {
          User user = null;
  
          // create a new request
          var restRequest = new RestRequest("User", Method.GET);
          // create REST parameters
          restRequest.AddParameter("userName", userName, ParameterType.QueryString);
          // execute the REST request
          var restResponse = await _restClient.Execute&lt;User&gt;(restRequest);
          if (restResponse.StatusCode.Equals(HttpStatusCode.OK))
          {
              user = restResponse.Data;
          }
          return user;
      }
  
  }
  </code></pre>
  
  <p>My test class :</p>
  
  <pre><code>[TestClass]
  public class DataServicesTest
  {
      public static IRestClient MockRestClient&lt;T&gt;(HttpStatusCode httpStatusCode, string json)
      {
          var mockIRestClient = new Mock&lt;IRestClient&gt;();
          mockIRestClient.Setup(x =&gt; x.Execute&lt;T&gt;(It.IsAny&lt;IRestRequest&gt;()))
            .Returns(new RestResponse&lt;T&gt;
            {
                Data = JsonConvert.DeserializeObject&lt;T&gt;(json),
                StatusCode = httpStatusCode
            });
          return mockIRestClient.Object;
      }
  
      [TestMethod]
      public async void GetUserByUserName()
      {
          var dataServices = new DataServices(MockRestClient&lt;User&gt;(HttpStatusCode.OK, "my json code"));
          var user = await dataServices.GetUserByUserName("User1");
          Assert.AreEqual("User1", user.Username);
      }
  }
  </code></pre>
  
  <p>But I can't instantiate the <code>RestResponse</code> object, I've the following error:</p>
  
  <pre><code>.Returns(new RestResponse&lt;T&gt;
  {
      Data = JsonConvert.DeserializeObject&lt;T&gt;(json),
      StatusCode = httpStatusCode
  });
  </code></pre>
  
  <blockquote>
    <p>Cannot access protected internal constructor 'RestResponse' here.</p>
  </blockquote>
  
  <p>How can I workaround this ? I'm using the FubarCoder.RestSharp nuget package on a Xamarin portable Library.</p>