title: How to mock a method that returns an int with MOQ
body: <p>I have a class that does some retrieving of contents, and it has a method that requires some inputs (filters) before retrieving it. One of the "input" calls another method, which basically returning an int, how do I mock it using MOQ? Here's an example:</p>
  
  <pre><code>namespace MyNamespace
  {
      public class ConfigMetaDataColumns : MyModel
      {
          public int FieldID { get { return ValueInt("FieldID"); } }
          public int OrderId { get { return ValueInt("OrderId"); } }
          public string Label { get { return ValueString("Label"); } }
          public string FieldName { get { return ValueString("FieldName"); } }
          public int IsReadOnly { get { return ValueInt("IsReadOnly"); } }
      }
  
      public class GetDataClass
      {
          protected OpenSQLAccessLayer m_WITObject;
  
          // Input Properties
          public string GroupID;
          public string PageName;
  
          // Output Properties
  
          /// &lt;summary&gt;
          /// Get Config meta data
          /// &lt;/summary&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          public IEnumerable&lt;ConfigMetaDataColumns&gt; GetConfigMetaData()
          {
              var requester = new ListRequester&lt;OpenSQL, ConfigMetaDataColumns&gt;(m_WITObject, "Result[0].RowCount", "Result[0].Row[{0}].");
  
              return requester.Items;
          }
  
          public void InitRequest()
          {
              User user = (User)HttpContext.Current.User;
              m_WITObject = user.NewService&lt;OpenSQLAccessLayer&gt;();
  
              m_WITObject.SetInput("MultipleResultSets", 1);
              m_WITObject.SetInput("ClientID", Utils.GetClientID());
              m_WITObject.SetInput("GroupID", GroupID);
              m_WITObject.SetInput("PageName", PageName);
              m_WITObject.Retrieve();
          }
      }
  }
  </code></pre>
  
  <p>This is the "GetClientID()" method:</p>
  
  <pre><code>public static int GetClientID()
          {
              User oUser = (User)HttpContext.Current.User;
              int nClientID;
              string sClientID = string.Empty;
  
              if (String.IsNullOrEmpty(oUser.Session("clientid")))
              {
                  Client oClient = new Client();
              }
  
              oUser = (User)HttpContext.Current.User;
              sClientID = oUser.Session("clientid");
  
  
  
  
              //If we couldn't retrieve it, throw exception
              if ( string.IsNullOrEmpty(sClientID) || !int.TryParse(sClientID, out nClientID))
              {
                  throw new Exception("No clientid found in user session, client not authenticated, please login from main page");
              }
  
              return nClientID;
          }
  </code></pre>
  
  <p>I'm just looking for a way for me to pass in a hard-coded value for the ClientID, and use this to do some unit testing with the <strong>GetDataClass</strong> class.</p>
  
  <p>Thanks.</p>