Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I export internals to a test project in F#?

Tags:

c#

.net

f#

In C# you can create use the InternalsVisibleTo attribute in AssemblyInfo.c to give a test project access to a project's internals, so you can unit test parts of your project that you don't want to make public.

[assembly: InternalsVisibleTo("MyTestProject")]

I cannot discover an equivalent solution in F#, or even discover how to add an attribute to an assembly at all. Is there a solution (or an equivalent workaround) and if so what is it?

like image 393
Adam Kennedy Avatar asked Jan 24 '15 00:01

Adam Kennedy


2 Answers

Put this into your fsproj file:

 <ItemGroup>
   <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
     <_Parameter1>$(AssemblyName).Tests</_Parameter1>
   </AssemblyAttribute>
   <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
     <_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
   </AssemblyAttribute>
 </ItemGroup>

Note that the entry for DynamicProxyGenAssembly2 is only needed if Moq is used.

like image 88
Tom Schardt Avatar answered Oct 04 '22 06:10

Tom Schardt


Jeff Mercado's solution to getting an assembly attribute (which I'd never seen before) lead to the following solution for my problem. Thanks Jeff!

module AssemblyInfo

open System.Runtime.CompilerServices

[<assembly: InternalsVisibleTo("MyTestProject")>]
do()
like image 29
Adam Kennedy Avatar answered Oct 04 '22 06:10

Adam Kennedy