I'd let to mock an IBus with Foq.
One of the methods on the IBus
is OpenPublishChannel
, which returns an IPublishChannel. IPublishChannel in turn has a Bus
property that returns the parent IBus
.
My current code is below, but obviously it doesn't compile as mockBus is not defined by the point I need it. Is there a way of setting up recursive mocking like this without creating two mocks of either interface?
open System
open EasyNetQ
open Foq
let mockChannel =
Mock<IPublishChannel>()
.Setup(fun x -> <@ x.Bus @>).Returns(mockBus)
.Create()
let mockBus =
Mock<IBus>()
.Setup(fun x -> <@ x.OpenPublishChannel() @>).Returns(mockChannel)
.Create()