Compare commits

..

5 Commits

Author SHA1 Message Date
Smaug123
8f0e8d6369 Failing test 2025-09-17 08:51:36 +01:00
Smaug123
e7780dc412 Docs 2025-09-17 08:49:23 +01:00
Smaug123
c3311bd350 README 2025-09-17 08:43:33 +01:00
Smaug123
07e9eaff38 Implement 2025-09-17 08:37:41 +01:00
Smaug123
2c539c13a3 Capturing mock 2025-09-16 23:33:35 +01:00
11 changed files with 292 additions and 850 deletions

View File

@@ -9,285 +9,180 @@ namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal PublicTypeMockCalls =
/// All the calls made to a PublicTypeMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
Mem3 : ResizeArray<int * System.Threading.CancellationToken option>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
Mem3 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal PublicTypeMock = type internal PublicTypeMock =
{ {
Calls : PublicTypeMockCalls.Calls
Mem1 : string * int -> string list Mem1 : string * int -> string list
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
Mem3 : int * System.Threading.CancellationToken option -> string /// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
Mem3 : int * option<System.Threading.CancellationToken> -> string
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem3_Calls : ResizeArray<int * System.Threading.CancellationToken>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PublicTypeMock = static member Empty : PublicTypeMock =
{ {
Calls = PublicTypeMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3")) Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
Mem3_Calls = ResizeArray ()
} }
interface IPublicType with interface IPublicType with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1) member this.Mem3 (arg_0_0, arg_0_1) = this.Mem3 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
member this.Mem3 (arg_0_0, arg_0_1) =
lock this.Calls.Mem3 (fun _ -> this.Calls.Mem3.Add (arg_0_0, arg_0_1))
this.Mem3 (arg_0_0, arg_0_1)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module public PublicTypeInternalFalseMockCalls =
/// All the calls made to a PublicTypeInternalFalseMock mock
type public Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
Mem3 : ResizeArray<int * System.Threading.CancellationToken option>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
Mem3 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type public PublicTypeInternalFalseMock = type public PublicTypeInternalFalseMock =
{ {
Calls : PublicTypeInternalFalseMockCalls.Calls
Mem1 : string * int -> string list Mem1 : string * int -> string list
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
Mem3 : int * System.Threading.CancellationToken option -> string /// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
Mem3 : int * option<System.Threading.CancellationToken> -> string
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem3_Calls : ResizeArray<int * System.Threading.CancellationToken>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PublicTypeInternalFalseMock = static member Empty : PublicTypeInternalFalseMock =
{ {
Calls = PublicTypeInternalFalseMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3")) Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
Mem3_Calls = ResizeArray ()
} }
interface IPublicTypeInternalFalse with interface IPublicTypeInternalFalse with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1) member this.Mem3 (arg_0_0, arg_0_1) = this.Mem3 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
member this.Mem3 (arg_0_0, arg_0_1) =
lock this.Calls.Mem3 (fun _ -> this.Calls.Mem3.Add (arg_0_0, arg_0_1))
this.Mem3 (arg_0_0, arg_0_1)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal InternalTypeMockCalls =
/// All the calls made to a InternalTypeMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal InternalTypeMock = type internal InternalTypeMock =
{ {
Calls : InternalTypeMockCalls.Calls
Mem1 : string * int -> unit Mem1 : string * int -> unit
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : InternalTypeMock = static member Empty : InternalTypeMock =
{ {
Calls = InternalTypeMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface InternalType with interface InternalType with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal PrivateTypeMockCalls =
/// All the calls made to a PrivateTypeMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type private PrivateTypeMock = type private PrivateTypeMock =
{ {
Calls : PrivateTypeMockCalls.Calls
Mem1 : string * int -> unit Mem1 : string * int -> unit
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PrivateTypeMock = static member Empty : PrivateTypeMock =
{ {
Calls = PrivateTypeMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface PrivateType with interface PrivateType with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal PrivateTypeInternalFalseMockCalls =
/// All the calls made to a PrivateTypeInternalFalseMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type private PrivateTypeInternalFalseMock = type private PrivateTypeInternalFalseMock =
{ {
Calls : PrivateTypeInternalFalseMockCalls.Calls
Mem1 : string * int -> unit Mem1 : string * int -> unit
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PrivateTypeInternalFalseMock = static member Empty : PrivateTypeInternalFalseMock =
{ {
Calls = PrivateTypeInternalFalseMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface PrivateTypeInternalFalse with interface PrivateTypeInternalFalse with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal VeryPublicTypeMockCalls =
/// All the calls made to a VeryPublicTypeMock mock
type internal Calls<'a, 'b> =
{
Mem1 : ResizeArray<'a>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls<'a, 'b> =
{
Mem1 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal VeryPublicTypeMock<'a, 'b> = type internal VeryPublicTypeMock<'a, 'b> =
{ {
Calls : VeryPublicTypeMockCalls.Calls<'a, 'b>
Mem1 : 'a -> 'b Mem1 : 'a -> 'b
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<'a>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : VeryPublicTypeMock<'a, 'b> = static member Empty () : VeryPublicTypeMock<'a, 'b> =
{ {
Calls = VeryPublicTypeMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem1_Calls = ResizeArray ()
} }
interface VeryPublicType<'a, 'b> with interface VeryPublicType<'a, 'b> with
member this.Mem1 arg_0_0 = member this.Mem1 arg_0_0 = this.Mem1 (arg_0_0)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0))
this.Mem1 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal CurriedMockCalls = module internal CurriedMockCalls =
/// A single call to the Mem1 method /// A single call to the Mem1 method
type internal Mem1Call<'a> = type internal Mem1Call<'a> =
@@ -331,178 +226,84 @@ module internal CurriedMockCalls =
Arg1 : 'a * int Arg1 : 'a * int
} }
/// All the calls made to a CurriedMock mock
type internal Calls<'a> =
{
Mem1 : ResizeArray<Mem1Call<'a>>
Mem2 : ResizeArray<Mem2Call<'a>>
Mem3 : ResizeArray<Mem3Call<'a>>
Mem4 : ResizeArray<Mem4Call<'a>>
Mem5 : ResizeArray<Mem5Call<'a>>
Mem6 : ResizeArray<Mem6Call<'a>>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls<'a> =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
Mem3 = ResizeArray ()
Mem4 = ResizeArray ()
Mem5 = ResizeArray ()
Mem6 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal CurriedMock<'a> = type internal CurriedMock<'a> =
{ {
Calls : CurriedMockCalls.Calls<'a>
Mem1 : int -> 'a -> string Mem1 : int -> 'a -> string
Mem1_Calls : ResizeArray<CurriedMockCalls.Mem1Call<'a>>
Mem2 : int * string -> 'a -> string Mem2 : int * string -> 'a -> string
Mem2_Calls : ResizeArray<CurriedMockCalls.Mem2Call<'a>>
Mem3 : (int * string) -> 'a -> string Mem3 : (int * string) -> 'a -> string
Mem3_Calls : ResizeArray<CurriedMockCalls.Mem3Call<'a>>
Mem4 : (int * string) -> ('a * int) -> string Mem4 : (int * string) -> ('a * int) -> string
Mem4_Calls : ResizeArray<CurriedMockCalls.Mem4Call<'a>>
Mem5 : int * string -> ('a * int) -> string Mem5 : int * string -> ('a * int) -> string
Mem5_Calls : ResizeArray<CurriedMockCalls.Mem5Call<'a>>
Mem6 : int * string -> 'a * int -> string Mem6 : int * string -> 'a * int -> string
Mem6_Calls : ResizeArray<CurriedMockCalls.Mem6Call<'a>>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : CurriedMock<'a> = static member Empty () : CurriedMock<'a> =
{ {
Calls = CurriedMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3")) Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3"))
Mem4 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem4")) Mem4 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem4"))
Mem5 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem5")) Mem5 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem5"))
Mem6 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem6")) Mem6 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem6"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
Mem3_Calls = ResizeArray ()
Mem4_Calls = ResizeArray ()
Mem5_Calls = ResizeArray ()
Mem6_Calls = ResizeArray ()
} }
interface Curried<'a> with interface Curried<'a> with
member this.Mem1 arg_0_0 arg_1_0 = member this.Mem1 arg_0_0 arg_1_0 = this.Mem1 (arg_0_0) (arg_1_0)
lock member this.Mem2 (arg_0_0, arg_0_1) arg_1_0 = this.Mem2 (arg_0_0, arg_0_1) (arg_1_0)
this.Calls.Mem1 member this.Mem3 arg_0_0 arg_1_0 = this.Mem3 (arg_0_0) (arg_1_0)
(fun _ ->
this.Calls.Mem1.Add
{
bar = arg_0_0
Arg1 = arg_1_0
}
)
this.Mem1 (arg_0_0) (arg_1_0)
member this.Mem2 (arg_0_0, arg_0_1) arg_1_0 =
lock
this.Calls.Mem2
(fun _ ->
this.Calls.Mem2.Add
{
Arg0 = arg_0_0, arg_0_1
baz = arg_1_0
}
)
this.Mem2 (arg_0_0, arg_0_1) (arg_1_0)
member this.Mem3 arg_0_0 arg_1_0 =
lock
this.Calls.Mem3
(fun _ ->
this.Calls.Mem3.Add
{
quux = arg_0_0
flurb = arg_1_0
}
)
this.Mem3 (arg_0_0) (arg_1_0)
member this.Mem4 ((arg_0_0, arg_0_1)) ((arg_1_0, arg_1_1)) = member this.Mem4 ((arg_0_0, arg_0_1)) ((arg_1_0, arg_1_1)) =
lock
this.Calls.Mem4
(fun _ ->
this.Calls.Mem4.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0, arg_1_1
}
)
this.Mem4 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) this.Mem4 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1)
member this.Mem5 (arg_0_0, arg_0_1) ((arg_1_0, arg_1_1)) = member this.Mem5 (arg_0_0, arg_0_1) ((arg_1_0, arg_1_1)) =
lock
this.Calls.Mem5
(fun _ ->
this.Calls.Mem5.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0, arg_1_1
}
)
this.Mem5 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) this.Mem5 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1)
member this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) = member this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) =
lock
this.Calls.Mem6
(fun _ ->
this.Calls.Mem6.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0, arg_1_1
}
)
this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal TypeWithInterfaceMockCalls =
/// All the calls made to a TypeWithInterfaceMock mock
type internal Calls =
{
Mem1 : ResizeArray<string option>
Mem2 : ResizeArray<unit>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal TypeWithInterfaceMock = type internal TypeWithInterfaceMock =
{ {
Calls : TypeWithInterfaceMockCalls.Calls
/// Implementation of IDisposable.Dispose /// Implementation of IDisposable.Dispose
Dispose : unit -> unit Dispose : unit -> unit
Mem1 : string option -> string[] Async Mem1 : string option -> string[] Async
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string option>
Mem2 : unit -> string[] Async Mem2 : unit -> string[] Async
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<unit>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : TypeWithInterfaceMock = static member Empty : TypeWithInterfaceMock =
{ {
Calls = TypeWithInterfaceMockCalls.Calls.Empty ()
Dispose = (fun () -> ()) Dispose = (fun () -> ())
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface TypeWithInterface with interface TypeWithInterface with
member this.Mem1 arg_0_0 = member this.Mem1 arg_0_0 = this.Mem1 (arg_0_0)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0)) member this.Mem2 () = this.Mem2 (())
this.Mem1 (arg_0_0)
member this.Mem2 () =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (()))
this.Mem2 (())
interface System.IDisposable with interface System.IDisposable with
member this.Dispose () : unit = this.Dispose () member this.Dispose () : unit = this.Dispose ()
@@ -511,50 +312,36 @@ namespace SomeNamespace.CapturingMock
open System open System
open WoofWare.Myriad.Plugins open WoofWare.Myriad.Plugins
[<RequireQualifiedAccess>]
module internal TypeWithPropertiesMockCalls =
/// All the calls made to a TypeWithPropertiesMock mock
type internal Calls =
{
Mem1 : ResizeArray<string option>
Prop1 : ResizeArray<unit>
Prop2 : ResizeArray<unit>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Prop1 = ResizeArray ()
Prop2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal TypeWithPropertiesMock = type internal TypeWithPropertiesMock =
{ {
Calls : TypeWithPropertiesMockCalls.Calls
/// Implementation of IDisposable.Dispose /// Implementation of IDisposable.Dispose
Dispose : unit -> unit Dispose : unit -> unit
Mem1 : string option -> string[] Async
Prop1 : unit -> int Prop1 : unit -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Prop1_Calls : ResizeArray<unit>
Prop2 : unit -> unit Async Prop2 : unit -> unit Async
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Prop2_Calls : ResizeArray<unit>
Mem1 : string option -> string[] Async
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string option>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : TypeWithPropertiesMock = static member Empty : TypeWithPropertiesMock =
{ {
Calls = TypeWithPropertiesMockCalls.Calls.Empty ()
Dispose = (fun () -> ()) Dispose = (fun () -> ())
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Prop1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Prop1")) Prop1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Prop1"))
Prop2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Prop2")) Prop2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Prop2"))
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Prop1_Calls = ResizeArray ()
Prop2_Calls = ResizeArray ()
Mem1_Calls = ResizeArray ()
} }
interface TypeWithProperties with interface TypeWithProperties with
member this.Mem1 arg_0_0 = member this.Mem1 arg_0_0 = this.Mem1 (arg_0_0)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0))
this.Mem1 (arg_0_0)
member this.Prop1 = this.Prop1 () member this.Prop1 = this.Prop1 ()
member this.Prop2 = this.Prop2 () member this.Prop2 = this.Prop2 ()

View File

@@ -8,279 +8,174 @@ namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal PublicTypeNoAttrMockCalls =
/// All the calls made to a PublicTypeNoAttrMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
Mem3 : ResizeArray<int * System.Threading.CancellationToken option>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
Mem3 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal PublicTypeNoAttrMock = type internal PublicTypeNoAttrMock =
{ {
Calls : PublicTypeNoAttrMockCalls.Calls
Mem1 : string * int -> string list Mem1 : string * int -> string list
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
Mem3 : int * System.Threading.CancellationToken option -> string /// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
Mem3 : int * option<System.Threading.CancellationToken> -> string
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem3_Calls : ResizeArray<int * System.Threading.CancellationToken>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PublicTypeNoAttrMock = static member Empty : PublicTypeNoAttrMock =
{ {
Calls = PublicTypeNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3")) Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
Mem3_Calls = ResizeArray ()
} }
interface IPublicTypeNoAttr with interface IPublicTypeNoAttr with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1) member this.Mem3 (arg_0_0, arg_0_1) = this.Mem3 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
member this.Mem3 (arg_0_0, arg_0_1) =
lock this.Calls.Mem3 (fun _ -> this.Calls.Mem3.Add (arg_0_0, arg_0_1))
this.Mem3 (arg_0_0, arg_0_1)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module public PublicTypeInternalFalseNoAttrMockCalls =
/// All the calls made to a PublicTypeInternalFalseNoAttrMock mock
type public Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
Mem3 : ResizeArray<int * System.Threading.CancellationToken option>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
Mem3 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type public PublicTypeInternalFalseNoAttrMock = type public PublicTypeInternalFalseNoAttrMock =
{ {
Calls : PublicTypeInternalFalseNoAttrMockCalls.Calls
Mem1 : string * int -> string list Mem1 : string * int -> string list
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
Mem3 : int * System.Threading.CancellationToken option -> string /// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
Mem3 : int * option<System.Threading.CancellationToken> -> string
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem3_Calls : ResizeArray<int * System.Threading.CancellationToken>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PublicTypeInternalFalseNoAttrMock = static member Empty : PublicTypeInternalFalseNoAttrMock =
{ {
Calls = PublicTypeInternalFalseNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3")) Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
Mem3_Calls = ResizeArray ()
} }
interface IPublicTypeInternalFalseNoAttr with interface IPublicTypeInternalFalseNoAttr with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1) member this.Mem3 (arg_0_0, arg_0_1) = this.Mem3 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
member this.Mem3 (arg_0_0, arg_0_1) =
lock this.Calls.Mem3 (fun _ -> this.Calls.Mem3.Add (arg_0_0, arg_0_1))
this.Mem3 (arg_0_0, arg_0_1)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal InternalTypeNoAttrMockCalls =
/// All the calls made to a InternalTypeNoAttrMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal InternalTypeNoAttrMock = type internal InternalTypeNoAttrMock =
{ {
Calls : InternalTypeNoAttrMockCalls.Calls
Mem1 : string * int -> unit Mem1 : string * int -> unit
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : InternalTypeNoAttrMock = static member Empty : InternalTypeNoAttrMock =
{ {
Calls = InternalTypeNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface InternalTypeNoAttr with interface InternalTypeNoAttr with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal PrivateTypeNoAttrMockCalls =
/// All the calls made to a PrivateTypeNoAttrMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type private PrivateTypeNoAttrMock = type private PrivateTypeNoAttrMock =
{ {
Calls : PrivateTypeNoAttrMockCalls.Calls
Mem1 : string * int -> unit Mem1 : string * int -> unit
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PrivateTypeNoAttrMock = static member Empty : PrivateTypeNoAttrMock =
{ {
Calls = PrivateTypeNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface PrivateTypeNoAttr with interface PrivateTypeNoAttr with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal PrivateTypeInternalFalseNoAttrMockCalls =
/// All the calls made to a PrivateTypeInternalFalseNoAttrMock mock
type internal Calls =
{
Mem1 : ResizeArray<string * int>
Mem2 : ResizeArray<string>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type private PrivateTypeInternalFalseNoAttrMock = type private PrivateTypeInternalFalseNoAttrMock =
{ {
Calls : PrivateTypeInternalFalseNoAttrMockCalls.Calls
Mem1 : string * int -> unit Mem1 : string * int -> unit
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string * int>
Mem2 : string -> int Mem2 : string -> int
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<string>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : PrivateTypeInternalFalseNoAttrMock = static member Empty : PrivateTypeInternalFalseNoAttrMock =
{ {
Calls = PrivateTypeInternalFalseNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface PrivateTypeInternalFalseNoAttr with interface PrivateTypeInternalFalseNoAttr with
member this.Mem1 (arg_0_0, arg_0_1) = member this.Mem1 (arg_0_0, arg_0_1) = this.Mem1 (arg_0_0, arg_0_1)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0, arg_0_1)) member this.Mem2 arg_0_0 = this.Mem2 (arg_0_0)
this.Mem1 (arg_0_0, arg_0_1)
member this.Mem2 arg_0_0 =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (arg_0_0))
this.Mem2 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal VeryPublicTypeNoAttrMockCalls =
/// All the calls made to a VeryPublicTypeNoAttrMock mock
type internal Calls<'a, 'b> =
{
Mem1 : ResizeArray<'a>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls<'a, 'b> =
{
Mem1 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal VeryPublicTypeNoAttrMock<'a, 'b> = type internal VeryPublicTypeNoAttrMock<'a, 'b> =
{ {
Calls : VeryPublicTypeNoAttrMockCalls.Calls<'a, 'b>
Mem1 : 'a -> 'b Mem1 : 'a -> 'b
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<'a>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : VeryPublicTypeNoAttrMock<'a, 'b> = static member Empty () : VeryPublicTypeNoAttrMock<'a, 'b> =
{ {
Calls = VeryPublicTypeNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem1_Calls = ResizeArray ()
} }
interface VeryPublicTypeNoAttr<'a, 'b> with interface VeryPublicTypeNoAttr<'a, 'b> with
member this.Mem1 arg_0_0 = member this.Mem1 arg_0_0 = this.Mem1 (arg_0_0)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0))
this.Mem1 (arg_0_0)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal CurriedNoAttrMockCalls = module internal CurriedNoAttrMockCalls =
/// A single call to the Mem1 method /// A single call to the Mem1 method
type internal Mem1Call<'a> = type internal Mem1Call<'a> =
@@ -324,177 +219,83 @@ module internal CurriedNoAttrMockCalls =
Arg1 : 'a * int Arg1 : 'a * int
} }
/// All the calls made to a CurriedNoAttrMock mock
type internal Calls<'a> =
{
Mem1 : ResizeArray<Mem1Call<'a>>
Mem2 : ResizeArray<Mem2Call<'a>>
Mem3 : ResizeArray<Mem3Call<'a>>
Mem4 : ResizeArray<Mem4Call<'a>>
Mem5 : ResizeArray<Mem5Call<'a>>
Mem6 : ResizeArray<Mem6Call<'a>>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls<'a> =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
Mem3 = ResizeArray ()
Mem4 = ResizeArray ()
Mem5 = ResizeArray ()
Mem6 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal CurriedNoAttrMock<'a> = type internal CurriedNoAttrMock<'a> =
{ {
Calls : CurriedNoAttrMockCalls.Calls<'a>
Mem1 : int -> 'a -> string Mem1 : int -> 'a -> string
Mem1_Calls : ResizeArray<CurriedNoAttrMockCalls.Mem1Call<'a>>
Mem2 : int * string -> 'a -> string Mem2 : int * string -> 'a -> string
Mem2_Calls : ResizeArray<CurriedNoAttrMockCalls.Mem2Call<'a>>
Mem3 : (int * string) -> 'a -> string Mem3 : (int * string) -> 'a -> string
Mem3_Calls : ResizeArray<CurriedNoAttrMockCalls.Mem3Call<'a>>
Mem4 : (int * string) -> ('a * int) -> string Mem4 : (int * string) -> ('a * int) -> string
Mem4_Calls : ResizeArray<CurriedNoAttrMockCalls.Mem4Call<'a>>
Mem5 : int * string -> ('a * int) -> string Mem5 : int * string -> ('a * int) -> string
Mem5_Calls : ResizeArray<CurriedNoAttrMockCalls.Mem5Call<'a>>
Mem6 : int * string -> 'a * int -> string Mem6 : int * string -> 'a * int -> string
Mem6_Calls : ResizeArray<CurriedNoAttrMockCalls.Mem6Call<'a>>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : CurriedNoAttrMock<'a> = static member Empty () : CurriedNoAttrMock<'a> =
{ {
Calls = CurriedNoAttrMockCalls.Calls.Empty ()
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3")) Mem3 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem3"))
Mem4 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem4")) Mem4 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem4"))
Mem5 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem5")) Mem5 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem5"))
Mem6 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem6")) Mem6 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem6"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
Mem3_Calls = ResizeArray ()
Mem4_Calls = ResizeArray ()
Mem5_Calls = ResizeArray ()
Mem6_Calls = ResizeArray ()
} }
interface CurriedNoAttr<'a> with interface CurriedNoAttr<'a> with
member this.Mem1 arg_0_0 arg_1_0 = member this.Mem1 arg_0_0 arg_1_0 = this.Mem1 (arg_0_0) (arg_1_0)
lock member this.Mem2 (arg_0_0, arg_0_1) arg_1_0 = this.Mem2 (arg_0_0, arg_0_1) (arg_1_0)
this.Calls.Mem1 member this.Mem3 ((arg_0_0, arg_0_1)) arg_1_0 = this.Mem3 (arg_0_0, arg_0_1) (arg_1_0)
(fun _ ->
this.Calls.Mem1.Add
{
Arg0 = arg_0_0
Arg1 = arg_1_0
}
)
this.Mem1 (arg_0_0) (arg_1_0)
member this.Mem2 (arg_0_0, arg_0_1) arg_1_0 =
lock
this.Calls.Mem2
(fun _ ->
this.Calls.Mem2.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0
}
)
this.Mem2 (arg_0_0, arg_0_1) (arg_1_0)
member this.Mem3 ((arg_0_0, arg_0_1)) arg_1_0 =
lock
this.Calls.Mem3
(fun _ ->
this.Calls.Mem3.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0
}
)
this.Mem3 (arg_0_0, arg_0_1) (arg_1_0)
member this.Mem4 ((arg_0_0, arg_0_1)) ((arg_1_0, arg_1_1)) = member this.Mem4 ((arg_0_0, arg_0_1)) ((arg_1_0, arg_1_1)) =
lock
this.Calls.Mem4
(fun _ ->
this.Calls.Mem4.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0, arg_1_1
}
)
this.Mem4 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) this.Mem4 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1)
member this.Mem5 (arg_0_0, arg_0_1) ((arg_1_0, arg_1_1)) = member this.Mem5 (arg_0_0, arg_0_1) ((arg_1_0, arg_1_1)) =
lock
this.Calls.Mem5
(fun _ ->
this.Calls.Mem5.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0, arg_1_1
}
)
this.Mem5 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) this.Mem5 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1)
member this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) = member this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) =
lock
this.Calls.Mem6
(fun _ ->
this.Calls.Mem6.Add
{
Arg0 = arg_0_0, arg_0_1
Arg1 = arg_1_0, arg_1_1
}
)
this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1) this.Mem6 (arg_0_0, arg_0_1) (arg_1_0, arg_1_1)
namespace SomeNamespace.CapturingMock namespace SomeNamespace.CapturingMock
open System open System
[<RequireQualifiedAccess>]
module internal TypeWithInterfaceNoAttrMockCalls =
/// All the calls made to a TypeWithInterfaceNoAttrMock mock
type internal Calls =
{
Mem1 : ResizeArray<string option>
Mem2 : ResizeArray<unit>
}
/// A fresh calls object which has not yet had any calls made.
static member Empty () : Calls =
{
Mem1 = ResizeArray ()
Mem2 = ResizeArray ()
}
/// Mock record type for an interface /// Mock record type for an interface
type internal TypeWithInterfaceNoAttrMock = type internal TypeWithInterfaceNoAttrMock =
{ {
Calls : TypeWithInterfaceNoAttrMockCalls.Calls
/// Implementation of IDisposable.Dispose /// Implementation of IDisposable.Dispose
Dispose : unit -> unit Dispose : unit -> unit
Mem1 : string option -> string[] Async Mem1 : string option -> string[] Async
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem1_Calls : ResizeArray<string option>
Mem2 : unit -> string[] Async Mem2 : unit -> string[] Async
/// Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it.
Mem2_Calls : ResizeArray<unit>
} }
/// An implementation where every non-unit method throws. /// An implementation where every non-unit method throws.
static member Empty () : TypeWithInterfaceNoAttrMock = static member Empty : TypeWithInterfaceNoAttrMock =
{ {
Calls = TypeWithInterfaceNoAttrMockCalls.Calls.Empty ()
Dispose = (fun () -> ()) Dispose = (fun () -> ())
Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1")) Mem1 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem1"))
Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2")) Mem2 = (fun _ -> raise (System.NotImplementedException "Unimplemented mock function: Mem2"))
Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface TypeWithInterfaceNoAttr with interface TypeWithInterfaceNoAttr with
member this.Mem1 arg_0_0 = member this.Mem1 arg_0_0 = this.Mem1 (arg_0_0)
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0)) member this.Mem2 () = this.Mem2 (())
this.Mem1 (arg_0_0)
member this.Mem2 () =
lock this.Calls.Mem2 (fun _ -> this.Calls.Mem2.Add (()))
this.Mem2 (())
interface System.IDisposable with interface System.IDisposable with
member this.Dispose () : unit = this.Dispose () member this.Dispose () : unit = this.Dispose ()

View File

@@ -10,7 +10,7 @@
<WarnOn>FS3388,FS3559</WarnOn> <WarnOn>FS3388,FS3559</WarnOn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.8.118" PrivateAssets="all" /> <PackageReference Include="Nerdbank.GitVersioning" Version="3.8.38-alpha" PrivateAssets="all" />
<SourceLinkGitHubHost Include="github.com" ContentUrl="https://raw.githubusercontent.com" /> <SourceLinkGitHubHost Include="github.com" ContentUrl="https://raw.githubusercontent.com" />
</ItemGroup> </ItemGroup>
<PropertyGroup Condition="'$(GITHUB_ACTION)' != ''"> <PropertyGroup Condition="'$(GITHUB_ACTION)' != ''">

View File

@@ -478,51 +478,40 @@ It takes a type like this:
```fsharp ```fsharp
[<GenerateCapturingMock>] [<GenerateCapturingMock>]
type IPublicType = type IPublicType =
abstract Mem1 : string * int -> thing : bool -> string list abstract Mem1 : string * int -> string list
abstract Mem2 : baz : string -> unit -> int abstract Mem2 : baz : string -> unit -> int
``` ```
and stamps out types like this: and stamps out types like this:
```fsharp ```fsharp
[<RequireQualifiedAccess>]
module internal PublicTypeCalls = module internal PublicTypeCalls =
type internal Mem1Call = type internal Mem2Call =
{ {
Arg0 : string * int baz : string
thing : bool Arg1 : unit
} }
type internal Calls =
{
Mem1 : ResizeArray<Mem1Call>
Mem2 : ResizeArray<string>
}
static member Empty () = { Mem1 = ResizeArray () ; Mem2 = ResizeArray () }
/// Mock record type for an interface /// Mock record type for an interface
type internal PublicTypeMock = type internal PublicTypeMock =
{ {
Mem1 : string * int -> bool -> string list Mem1 : string * int -> string list
Mem2 : string -> int Mem2 : string -> int
Calls : PublicTypeCalls.Calls Mem2_Calls : ResizeArray<string * int>
Mem2_Calls : ResizeArray<PublicTypeCalls.Mem2Call>
} }
static member Empty : PublicTypeMock = static member Empty : PublicTypeMock =
{ {
Mem1 = (fun x -> raise (System.NotImplementedException "Unimplemented mock function")) Mem1 = (fun x -> raise (System.NotImplementedException "Unimplemented mock function"))
Mem2 = (fun x -> raise (System.NotImplementedException "Unimplemented mock function")) Mem2 = (fun x -> raise (System.NotImplementedException "Unimplemented mock function"))
Calls = PublicTypeMockCalls.Calls.Empty () Mem1_Calls = ResizeArray ()
Mem2_Calls = ResizeArray ()
} }
interface IPublicType with interface IPublicType with
member this.Mem1 (arg0, arg1) = member this.Mem1 (arg0, arg1) = this.Mem1 (arg0, arg1)
lock this.Calls.Mem1 (fun () -> this.Calls.Mem1.Add { Arg0 = arg0 ; thing = arg1 }) member this.Mem2 (arg0) = this.Mem2 (arg0)
this.Mem1 (arg0, arg1)
member this.Mem2 (arg0) =
lock this.Calls.Mem2 (fun () -> this.Calls.Mem2.Add arg0)
this.Mem2 (arg0)
``` ```
### What's the point? ### What's the point?
@@ -536,36 +525,6 @@ thereby allowing the programmer to use F#'s record-update syntax.
* You may supply an `isInternal : bool` argument to the attribute. 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 with `[<GenerateMock false>]`. * You may supply an `isInternal : bool` argument to the attribute. 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 with `[<GenerateMock false>]`.
### Gotchas (GenerateCapturingMock)
We use the same name for the record field as the implementing interface member:
```fsharp
type FooMock =
{
Field : string -> unit
}
interface IFoo with
member _.Field x = ...
```
If you have an object of type `FooMock` in scope, you'll get the *record field*, not the *interface member*.
You need to cast it to `IFoo` before using it (or pass it into a function which takes an `IFoo`):
```fsharp
let thing = FooMock.Empty () // of type FooMock
thing.Field "hello" // the wrong one! bypasses the IFoo implementation which captures calls
// correct:
let thing' = FooMock.Empty ()
let thing = thing' :> IFoo
thing.Field "hello" // the right one: this call does get recorded in the mock, because this is the interface member
// also correct, but beware because it leaves the chance of the above footgun lying around for later:
let thing = FooMock.Empty () // of type FooMock
doTheThing thing // where doTheThing : IFoo -> unit
```
## `CreateCatamorphism` ## `CreateCatamorphism`
Takes a collection of mutually recursive discriminated unions: Takes a collection of mutually recursive discriminated unions:

View File

@@ -32,11 +32,7 @@ type GenerateMockAttribute (isInternal : bool) =
/// record update syntax to easily specify partially-implemented mock objects. /// record update syntax to easily specify partially-implemented mock objects.
/// You may optionally specify `isInternal = false` to get a mock with the public visibility modifier. /// You may optionally specify `isInternal = false` to get a mock with the public visibility modifier.
/// ///
/// The default implementation of each field throws. /// The default implementation of each field captures all calls made to it, which can then be accessed later.
///
/// The generated interface methods capture all calls made to them, before passing through to the relevant
/// field of the mock record; the calls can be accessed later through the `Calls` field of the generated
/// mock record.
type GenerateCapturingMockAttribute (isInternal : bool) = type GenerateCapturingMockAttribute (isInternal : bool) =
inherit Attribute () inherit Attribute ()
/// The default value of `isInternal`, the optional argument to the GenerateCapturingMockAttribute constructor. /// The default value of `isInternal`, the optional argument to the GenerateCapturingMockAttribute constructor.

View File

@@ -11,7 +11,7 @@ module TestCapturingMockGenerator =
[<Test>] [<Test>]
let ``Example of use: IPublicType`` () = let ``Example of use: IPublicType`` () =
let mock : IPublicType = let mock : IPublicType =
{ PublicTypeMock.Empty () with { PublicTypeMock.Empty with
Mem1 = fun (s, count) -> List.replicate count s Mem1 = fun (s, count) -> List.replicate count s
} }
:> _ :> _
@@ -38,7 +38,7 @@ module TestCapturingMockGenerator =
[<Test>] [<Test>]
let ``Example of use: properties`` () = let ``Example of use: properties`` () =
let mock : TypeWithProperties = let mock : TypeWithProperties =
{ TypeWithPropertiesMock.Empty () with { TypeWithPropertiesMock.Empty with
Mem1 = fun i -> async { return Option.toArray i } Mem1 = fun i -> async { return Option.toArray i }
Prop1 = fun () -> 44 Prop1 = fun () -> 44
} }
@@ -50,7 +50,7 @@ module TestCapturingMockGenerator =
[<Test>] [<Test>]
let ``Example of curried use`` () = let ``Example of curried use`` () =
let mock' = let mock =
{ CurriedMock<string>.Empty () with { CurriedMock<string>.Empty () with
Mem1 = Mem1 =
fun x y -> fun x y ->
@@ -59,11 +59,9 @@ module TestCapturingMockGenerator =
"it's me" "it's me"
} }
let mock = mock' :> Curried<_>
mock.Mem1 3 "hello" |> shouldEqual "it's me" mock.Mem1 3 "hello" |> shouldEqual "it's me"
lock mock'.Calls.Mem1 (fun () -> Seq.toList mock'.Calls.Mem1) lock mock.Mem1_Calls (fun () -> Seq.toList mock.Mem1_Calls)
|> List.exactlyOne |> List.exactlyOne
|> shouldEqual |> shouldEqual
{ {

View File

@@ -11,7 +11,7 @@ module TestCapturingMockGeneratorNoAttr =
[<Test>] [<Test>]
let ``Example of use: IPublicType`` () = let ``Example of use: IPublicType`` () =
let mock : IPublicTypeNoAttr = let mock : IPublicTypeNoAttr =
{ PublicTypeNoAttrMock.Empty () with { PublicTypeNoAttrMock.Empty with
Mem1 = fun (s, count) -> List.replicate count s Mem1 = fun (s, count) -> List.replicate count s
} }
:> _ :> _

View File

@@ -50,12 +50,7 @@ module internal CapturingInterfaceMockGenerator =
Attrs = [] Attrs = []
Type = Type =
tupledArg.Args tupledArg.Args
|> List.map (fun pi -> |> List.map (fun pi -> pi.Type)
if pi.IsOptional then
pi.Type |> SynType.appPostfix "option"
else
pi.Type
)
|> SynType.tupleNoParen |> SynType.tupleNoParen
|> Option.get |> Option.get
} }
@@ -80,7 +75,7 @@ module internal CapturingInterfaceMockGenerator =
let private buildType (x : ParameterInfo) : SynType = let private buildType (x : ParameterInfo) : SynType =
if x.IsOptional then if x.IsOptional then
SynType.appPostfix "option" x.Type SynType.app "option" [ x.Type ]
else else
x.Type x.Type
@@ -144,12 +139,7 @@ module internal CapturingInterfaceMockGenerator =
| [] -> failwith "expected args in member" | [] -> failwith "expected args in member"
| [ ty ] -> | [ ty ] ->
ty.Args ty.Args
|> List.map (fun pi -> |> List.map _.Type
if pi.IsOptional then
SynType.appPostfix "option" pi.Type
else
pi.Type
)
|> SynType.tupleNoParen |> SynType.tupleNoParen
|> Option.get |> Option.get
|> CallField.Original |> CallField.Original
@@ -224,9 +214,8 @@ module internal CapturingInterfaceMockGenerator =
| None -> failwith $"unexpectedly got a field with no identifier: %O{f}" | None -> failwith $"unexpectedly got a field with no identifier: %O{f}"
| Some idOpt -> idOpt.idText | Some idOpt -> idOpt.idText
fieldName, (f, extraType) f, extraType, fieldName
) )
|> Map.ofList
let failwithNotImplemented (fieldName : string) = let failwithNotImplemented (fieldName : string) =
let failString = SynExpr.CreateConst $"Unimplemented mock function: %s{fieldName}" let failString = SynExpr.CreateConst $"Unimplemented mock function: %s{fieldName}"
@@ -259,21 +248,28 @@ module internal CapturingInterfaceMockGenerator =
let originalMembers = let originalMembers =
fields fields
|> Map.toList |> List.map (fun (_, _, fieldName) -> SynLongIdent.createS fieldName, failwithNotImplemented fieldName)
|> List.map (fun (fieldName, _) -> SynLongIdent.createS fieldName, failwithNotImplemented fieldName)
let callsObject = let callsArrays =
SynLongIdent.createS "Calls", fields
SynExpr.applyFunction |> List.map (fun (_field, _, fieldName) ->
(SynExpr.createLongIdent [ $"%s{name}Calls" ; "Calls" ; "Empty" ]) let name = SynLongIdent.createS $"%s{fieldName}_Calls"
(SynExpr.CreateConst ())
callsObject :: interfaceExtras @ originalMembers let init =
SynExpr.createIdent "ResizeArray" |> SynExpr.applyTo (SynExpr.CreateConst ())
name, init
)
interfaceExtras @ originalMembers @ callsArrays
let staticMemberEmpty = let staticMemberEmpty =
SynBinding.basic SynBinding.basic
[ Ident.create "Empty" ] [ Ident.create "Empty" ]
[ SynPat.unit ] (if interfaceType.Generics.IsNone then
[]
else
[ SynPat.unit ])
(SynExpr.createRecord None emptyRecordFieldInstantiations) (SynExpr.createRecord None emptyRecordFieldInstantiations)
|> SynBinding.withXmlDoc (PreXmlDoc.create "An implementation where every non-unit method throws.") |> SynBinding.withXmlDoc (PreXmlDoc.create "An implementation where every non-unit method throws.")
|> SynBinding.withReturnAnnotation constructorReturnType |> SynBinding.withReturnAnnotation constructorReturnType
@@ -294,109 +290,43 @@ module internal CapturingInterfaceMockGenerator =
[] []
let nonExtras = let nonExtras =
fields |> Map.toSeq |> Seq.map (fun (_, (field, _)) -> field) |> Seq.toList
let calls =
let ty =
match interfaceType.Generics with
| None -> SynType.createLongIdent' [ $"%s{name}Calls" ; "Calls" ]
| Some generics ->
generics.TyparDecls
|> List.map (fun (SynTyparDecl (_, typar)) -> SynType.var typar)
|> SynType.app' (SynType.createLongIdent' [ $"%s{name}Calls" ; "Calls" ])
{
Attrs = []
Ident = Ident.create "Calls" |> Some
Type = ty
}
|> SynField.make
calls :: extras @ nonExtras
let access =
match interfaceType.Accessibility, spec.IsInternal with
| Some (SynAccess.Public _), true
| None, true -> SynAccess.Internal range0
| Some (SynAccess.Public _), false -> SynAccess.Public range0
| None, false -> SynAccess.Public range0
| Some (SynAccess.Internal _), _ -> SynAccess.Internal range0
| Some (SynAccess.Private _), _ -> SynAccess.Private range0
let accessAtLeastInternal =
match access with
| SynAccess.Private _ -> SynAccess.Internal range0
| access -> access
let callsObject =
let fields' =
fields fields
|> Map.toSeq |> List.collect (fun (field, callType, fieldName) ->
|> Seq.map (fun (fieldName, (_, callType)) -> let callField =
match callType with match callType with
| CallField.Original ty -> | CallField.Original ty ->
{ {
Attrs = [] Attrs = []
Ident = Some (fieldName |> Ident.create) Ident = Some (fieldName + "_Calls" |> Ident.create)
Type = SynType.app "ResizeArray" [ ty ] Type = SynType.app "ResizeArray" [ ty ]
} }
|> SynField.make |> SynField.make
|> SynField.withDocString (
PreXmlDoc.create
"Additions to this ResizeArray are locked on itself. For maximum safety, lock on this field before reading it."
)
| CallField.ArgsObject (argsObjectName, _, generics) -> | CallField.ArgsObject (argsObjectName, _, generics) ->
{ {
Attrs = [] Attrs = []
Ident = Some (fieldName |> Ident.create) Ident = Some (fieldName + "_Calls" |> Ident.create)
Type = Type =
match generics with match generics with
| None -> SynType.named argsObjectName.idText | None -> SynType.named argsObjectName.idText
| Some generics -> | Some generics ->
generics.TyparDecls generics.TyparDecls
|> List.map (fun (SynTyparDecl.SynTyparDecl (_, typar)) -> SynType.var typar) |> List.map (fun (SynTyparDecl.SynTyparDecl (_, typar)) -> SynType.var typar)
|> SynType.app' (SynType.createLongIdent' [ argsObjectName.idText ]) |> SynType.app' (
SynType.createLongIdent' [ $"%s{name}Calls" ; argsObjectName.idText ]
)
|> List.singleton |> List.singleton
|> SynType.app "ResizeArray" |> SynType.app "ResizeArray"
} }
|> SynField.make |> SynField.make
[ field ; callField ]
) )
|> Seq.toList
let emptyMember = extras @ nonExtras
let returnType =
match interfaceType.Generics with
| None -> SynType.named "Calls"
| Some generics ->
let generics =
match generics with
| SynTyparDecls.PostfixList (decls = decls)
| SynTyparDecls.PrefixList (decls = decls) -> decls
| SynTyparDecls.SinglePrefix (decl = decl) -> [ decl ]
|> List.map (fun (SynTyparDecl.SynTyparDecl (_, typar)) -> SynType.var typar)
SynType.app "Calls" generics
fields
|> Map.toSeq
|> Seq.map (fun (name, _) ->
SynLongIdent.createS name,
SynExpr.applyFunction (SynExpr.createIdent "ResizeArray") (SynExpr.CreateConst ())
)
|> Seq.toList
|> SynExpr.createRecord None
|> SynBinding.basic [ Ident.create "Empty" ] [ SynPat.unit ]
|> SynBinding.withXmlDoc (PreXmlDoc.create "A fresh calls object which has not yet had any calls made.")
|> SynBinding.withReturnAnnotation returnType
|> SynMemberDefn.staticMember
{
RecordType.Name = Ident.create "Calls"
Fields = fields'
Members = Some [ emptyMember ]
XmlDoc = PreXmlDoc.create $"All the calls made to a %s{name} mock" |> Some
Generics = interfaceType.Generics
TypeAccessibility = Some accessAtLeastInternal
ImplAccessibility = None
Attributes = [ SynAttribute.requireQualifiedAccess ]
}
|> AstHelper.defineRecordType
let interfaceMembers = let interfaceMembers =
let members = let members =
@@ -420,66 +350,29 @@ module internal CapturingInterfaceMockGenerator =
|> fun i -> if tupledArgs.HasParen then SynPat.paren i else i |> fun i -> if tupledArgs.HasParen then SynPat.paren i else i
) )
let body, addToCalls = let body =
let tupleContents = let tuples =
memberInfo.Args memberInfo.Args
|> List.mapi (fun i args -> |> List.mapi (fun i args ->
args.Args args.Args
|> List.mapi (fun j arg -> |> List.mapi (fun j arg ->
match arg.Type with match arg.Type with
| UnitType -> SynExpr.CreateConst (), arg.Id | UnitType -> SynExpr.CreateConst ()
| _ -> SynExpr.createIdent $"arg_%i{i}_%i{j}", arg.Id | _ -> SynExpr.createIdent $"arg_%i{i}_%i{j}"
) )
|> SynExpr.tuple
) )
let tuples = tupleContents |> List.map (List.map fst >> SynExpr.tuple)
match tuples |> List.rev with match tuples |> List.rev with
| [] -> failwith "expected args but got none" | [] -> failwith "expected args but got none"
| last :: rest -> | last :: rest ->
let tuples = (last, rest) ||> List.fold SynExpr.applyTo (last, rest)
||> List.fold SynExpr.applyTo
let body =
tuples
|> SynExpr.applyFunction ( |> SynExpr.applyFunction (
SynExpr.createLongIdent' [ Ident.create "this" ; memberInfo.Identifier ] SynExpr.createLongIdent' [ Ident.create "this" ; memberInfo.Identifier ]
) )
let addToCalls =
match Map.tryFind memberInfo.Identifier.idText fields with
| None ->
failwith
$"unexpectedly looking up a nonexistent field %s{memberInfo.Identifier.idText}"
| Some (_, result) ->
match result with
| CallField.Original _ -> tuples
| CallField.ArgsObject _ ->
tupleContents
|> List.mapi (fun i fields ->
match fields with
| [ contents, Some ident ] -> SynLongIdent.create [ ident ], contents
| [ contents, None ] -> SynLongIdent.createS $"Arg%i{i}", contents
| _ ->
SynLongIdent.createS $"Arg%i{i}",
SynExpr.tupleNoParen (fields |> List.map fst)
)
|> SynExpr.createRecord None
|> SynExpr.applyFunction (
SynExpr.createLongIdent [ "this" ; "Calls" ; memberInfo.Identifier.idText ; "Add" ]
)
|> SynExpr.createLambda "_"
|> SynExpr.applyFunction (
SynExpr.createIdent "lock"
|> SynExpr.applyTo (
SynExpr.createLongIdent [ "this" ; "Calls" ; memberInfo.Identifier.idText ]
)
)
body, addToCalls
let body = [ addToCalls ; body ] |> SynExpr.sequential
SynBinding.basic [ Ident.create "this" ; memberInfo.Identifier ] headArgs body SynBinding.basic [ Ident.create "this" ; memberInfo.Identifier ] headArgs body
|> SynMemberDefn.memberImplementation |> SynMemberDefn.memberImplementation
) )
@@ -510,6 +403,15 @@ module internal CapturingInterfaceMockGenerator =
SynMemberDefn.Interface (interfaceName, Some range0, Some (members @ properties), range0) SynMemberDefn.Interface (interfaceName, Some range0, Some (members @ properties), range0)
let access =
match interfaceType.Accessibility, spec.IsInternal with
| Some (SynAccess.Public _), true
| None, true -> SynAccess.Internal range0
| Some (SynAccess.Public _), false -> SynAccess.Public range0
| None, false -> SynAccess.Public range0
| Some (SynAccess.Internal _), _ -> SynAccess.Internal range0
| Some (SynAccess.Private _), _ -> SynAccess.Private range0
let extraInterfaces = let extraInterfaces =
inherits inherits
|> Seq.map (fun inheritance -> |> Seq.map (fun inheritance ->
@@ -546,21 +448,20 @@ module internal CapturingInterfaceMockGenerator =
let typeDecl = AstHelper.defineRecordType record let typeDecl = AstHelper.defineRecordType record
let callsModule = let callsModule =
let types =
fields fields
|> Map.toSeq |> List.choose (fun (_, field, _) ->
|> Seq.choose (fun (_, (_, field)) ->
match field with match field with
| CallField.Original _ -> None | CallField.Original _ -> None
| CallField.ArgsObject (_, callType, _) -> Some (SynModuleDecl.Types ([ callType ], range0)) | CallField.ArgsObject (_, callType, _) -> Some callType
) )
|> Seq.toList |> function
| [] -> None
types @ [ SynModuleDecl.Types ([ callsObject ], range0) ] | l ->
SynModuleDecl.Types (l, range0)
|> List.singleton
|> SynModuleDecl.nestedModule ( |> SynModuleDecl.nestedModule (
SynComponentInfo.create (Ident.create $"%s{name}Calls") SynComponentInfo.create (Ident.create $"%s{name}Calls")
|> SynComponentInfo.withAccessibility accessAtLeastInternal |> SynComponentInfo.withAccessibility access
|> SynComponentInfo.addAttributes [ SynAttribute.requireQualifiedAccess ]
) )
|> Some |> Some

View File

@@ -1,5 +1,5 @@
{ {
"version": "9.0", "version": "8.1",
"publicReleaseRefSpec": [ "publicReleaseRefSpec": [
"^refs/heads/main$" "^refs/heads/main$"
], ],

6
flake.lock generated
View File

@@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1758976413, "lastModified": 1757746433,
"narHash": "sha256-hEIDTaIqvW1NMfaNgz6pjhZPZKTmACJmXxGr/H6isIg=", "narHash": "sha256-fEvTiU4s9lWgW7mYEU/1QUPirgkn+odUBTaindgiziY=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e3a3b32cc234f1683258d36c6232f150d57df015", "rev": "6d7ec06d6868ac6d94c371458fc2391ded9ff13d",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -216,8 +216,8 @@
}, },
{ {
"pname": "Nerdbank.GitVersioning", "pname": "Nerdbank.GitVersioning",
"version": "3.8.118", "version": "3.8.38-alpha",
"hash": "sha256-Hmyy0ZKOmwN4zIhI4+MqoN8geZNc1sd033aZJ6APrO8=" "hash": "sha256-gPMrVbjOZxXoofczF/pn6eVkLhjVSJIyQrLO2oljrDc="
}, },
{ {
"pname": "NETStandard.Library", "pname": "NETStandard.Library",