Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ConsumePlugin/GeneratedCapturingMock.fs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,13 @@ type internal TypeWithPropertiesMock =
lock this.Calls.Mem1 (fun _ -> this.Calls.Mem1.Add (arg_0_0))
this.Mem1 (arg_0_0)

member this.Prop1 = this.Prop1 ()
member this.Prop2 = this.Prop2 ()
member this.Prop1 =
lock this.Calls.Prop1 (fun _ -> this.Calls.Prop1.Add ())
this.Prop1 ()

member this.Prop2 =
lock this.Calls.Prop2 (fun _ -> this.Calls.Prop2.Add ())
this.Prop2 ()

interface System.IDisposable with
member this.Dispose () : unit = this.Dispose ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ module TestCapturingMockGenerator =
mock.Mem2 (3, "hi") 'a' |> shouldEqual "hiahiahi"
mock.Mem3 (3, "hi") 'a' |> shouldEqual "hiahiahi"

[<Test>]
let ``Property accesses are recorded in Calls`` () =
let mock =
{ TypeWithPropertiesMock.Empty () with
Prop1 = fun () -> 44
Prop2 = fun () -> async { return () }
}

let itf = mock :> TypeWithProperties

mock.Calls.Prop1.Count |> shouldEqual 0
mock.Calls.Prop2.Count |> shouldEqual 0

itf.Prop1 |> shouldEqual 44
mock.Calls.Prop1.Count |> shouldEqual 1
mock.Calls.Prop2.Count |> shouldEqual 0

itf.Prop1 |> shouldEqual 44
mock.Calls.Prop1.Count |> shouldEqual 2

// note: we don't attempt to track async scheduling or anything
itf.Prop2 |> ignore<_ Async>
mock.Calls.Prop2.Count |> shouldEqual 1

[<Test>]
let ``Example of use: properties`` () =
let mock : TypeWithProperties =
Expand Down
19 changes: 17 additions & 2 deletions WoofWare.Myriad.Plugins/CapturingInterfaceMockGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,23 @@ module internal CapturingInterfaceMockGenerator =
let properties =
interfaceType.Properties
|> List.map (fun pi ->
SynExpr.createLongIdent' [ Ident.create "this" ; pi.Identifier ]
|> SynExpr.applyTo (SynExpr.CreateConst ())
let addToCalls =
SynExpr.CreateConst ()
|> SynExpr.applyFunction (
SynExpr.createLongIdent [ "this" ; "Calls" ; pi.Identifier.idText ; "Add" ]
)
|> SynExpr.createLambda "_"
|> SynExpr.applyFunction (
SynExpr.createIdent "lock"
|> SynExpr.applyTo (SynExpr.createLongIdent [ "this" ; "Calls" ; pi.Identifier.idText ])
)

let body =
SynExpr.createLongIdent' [ Ident.create "this" ; pi.Identifier ]
|> SynExpr.applyTo (SynExpr.CreateConst ())

[ addToCalls ; body ]
|> SynExpr.sequential
|> SynBinding.basic [ Ident.create "this" ; pi.Identifier ] []
|> SynMemberDefn.memberImplementation
)
Expand Down
Loading