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?
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With