WoofWare.Whippet.Plugin.InterfaceMock 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package WoofWare.Whippet.Plugin.InterfaceMock --version 0.1.2                
NuGet\Install-Package WoofWare.Whippet.Plugin.InterfaceMock -Version 0.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WoofWare.Whippet.Plugin.InterfaceMock" Version="0.1.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WoofWare.Whippet.Plugin.InterfaceMock --version 0.1.2                
#r "nuget: WoofWare.Whippet.Plugin.InterfaceMock, 0.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WoofWare.Whippet.Plugin.InterfaceMock as a Cake Addin
#addin nuget:?package=WoofWare.Whippet.Plugin.InterfaceMock&version=0.1.2

// Install WoofWare.Whippet.Plugin.InterfaceMock as a Cake Tool
#tool nuget:?package=WoofWare.Whippet.Plugin.InterfaceMock&version=0.1.2                

WoofWare.Whippet.Plugin.InterfaceMock

This is a Whippet plugin for defining mocks for interfaces.

It is a copy of the corresponding Myriad HttpClient plugin in WoofWare.Myriad, taken from commit d59ebdfccb87a06579fb99008a15f58ea8be394e.

Usage

Define a file like Client.fs:

type IPublicType =
    abstract Mem1 : string * int -> string list
    abstract Mem2 : string -> int

In your fsproj:

<Project>
    <ItemGroup>
        <Compile Include="Client.fs" />
        <Compile Include="GeneratedClient.fs">
            <WhippetFile>Client.fs</WhippetFile>
            <WhippetParamIPublicType>InterfaceMock</WhippetParamIPublicType>
        </Compile>
    </ItemGroup>

    <ItemGroup>
        
        <PackageReference Include="WoofWare.Whippet.Plugin.InterfaceMock" WhippetPlugin="true" Version="" />
        <PackageReference Include="WoofWare.Whippet" Version="" PrivateAssets="all" />
    </ItemGroup>
</Project>

(This plugin follows a standard convention taken by WoofWare.Whippet.Plugin plugins, where you use Whippet parameters with the same name as each input type, whose contents are a !-delimited list of the generators which you wish to apply to that input type.)

The generator produces a type like this:

/// Mock record type for an interface
type internal PublicTypeMock =
    {
        Mem1 : string * int -> string list
        Mem2 : string -> int
    }

    static member Empty : PublicTypeMock =
        {
            Mem1 = (fun x -> raise (System.NotImplementedException "Unimplemented mock function"))
            Mem2 = (fun x -> raise (System.NotImplementedException "Unimplemented mock function"))
        }

    interface IPublicType with
        member this.Mem1 (arg0, arg1) = this.Mem1 (arg0, arg1)
        member this.Mem2 (arg0) = this.Mem2 (arg0)

What's the point?

Reflective mocking libraries like Foq in my experience are a rich source of flaky tests. The Grug-brained developer would prefer to do this without reflection, and this reduces the rate of strange one-in-ten-thousand "failed to generate IL" errors. But since F# does not let you partially update an interface definition, we instead stamp out a record, thereby allowing the programmer to use F#'s record-update syntax.

Features

You may supply an isInternal : bool argument:

<Compile Include="GeneratedClient.fs">
    <WhippetFile>Client.fs</WhippetFile>
    <WhippetParamIPublicType>InterfaceMock(false)</WhippetParamIPublicType>
</Compile>

By default, we make the resulting record type at most internal (never public), since this is intended only to be used in tests; but you can instead make it public by setting the false boolean.

Instead of configuring the client with <WhippetParamMyType>InterfaceMock</WhippetParamMyType>, you may choose to add an attribute called InterfaceMock (with an optional "isInternal" argument) to any type you wish to use as an input. You may use WoofWare.Whippet.Plugin.InterfaceMock.Attributes to provide this attribute, or you may define it yourself.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.5 104 10/8/2024
0.1.4 84 10/8/2024
0.1.3 81 10/8/2024
0.1.2 90 10/8/2024
0.1.1 93 10/7/2024