title: Configuring C# out parameters with Foq in F#
body: <p>I am using F# and Foq to write unit tests for a C# project.</p>
  
  <p>I am trying to set up a mock of an interface whose method has an <code>out</code> parameter, and I have no idea how to even start. It probably has to do with code quotations, but that's where my understanding ends.</p>
  
  <p>The interface is this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public interface IGetTypeNameString
  {
      bool For(Type type, out string typeName);
  }
  </code></pre>
  
  <p>In C# Foq usage for the interface looks like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[Fact]
  public void Foq_Out()
  {
      // Arrange
      var name = "result";
      var instance = new Mock&lt;IGetTypeNameString&gt;()
          .Setup(x =&gt; x.For(It.IsAny&lt;Type&gt;(), out name))
          .Returns(true)
          .Create();
  
      // Act
      string resultName;
      var result = instance.For(typeof(string), out resultName);
  
      // Assert
      Assert.True(result);
      Assert.Equal("result", resultName);
  }
  </code></pre>
  
  <p>As for how to achieve that with F#, I am completely lost. I tried something along the lines of</p>
  
  <pre class="lang-ml prettyprint-override"><code>let name = "result"
  let instance = Mock&lt;IGetTypeNameString&gt;().Setup(&lt;@ x.For(It.IsAny&lt;Type&gt;(), name) @&gt;).Returns(true).Create();
  </code></pre>
  
  <p>which results in the quotation expression being underlined with an error message of</p>
  
  <pre><code>This expression was expected to have type IGetTypeNameString -&gt; Quotations.Expr&lt;'a&gt; but here has type Quotations.Expr&lt;'b&gt;
  </code></pre>
  
  <p>Without any indication what types a and b are supposed to be, I have no clue how to correct this.</p>
  
  <p>:?></p>
  
  <p>(It gets even wilder when I use <code>open Foq.Linq</code>; then the Error List window starts telling me about possible overloads with stuff like <code>Action&lt;'TAbstract&gt; -&gt; ActionBuilder&lt;'TAbstract&gt;</code>, and I get even loster....)</p>
  
  <p>Any assistance or explanation greatly appreciated!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>So, as stated <a href="https://stackoverflow.com/questions/15939777/why-f-quotation-cannot-contains-struct">here</a>, byref/out parameters can not be used in code quotations. Can this be set up at all then in F#?</p>