JustMock supports recursive mocking inside Mock.Arrange statements. In other words, the following
Mock.Arrange(() => fakeSite.AllWebs.Add(Arg.AnyString, Arg.AnyString, Arg.AnyString, (
)Arg.AnyInt, Arg.AnyString, Arg.AnyBool, Arg.AnyBool).ID).Returns(SomeGuid);
i.e, it will arrange fakeSite.AllWebs to return an auto-created mock and that whenever the Add method is invoked on the fakeSite.AllWebs, then the return value will be auto-arranged to return a mock and its ID will be SomeGuid. However, there's no direct equivalent to TypeMock's
API. In JustMock you need to use the IgnoreInstance() API, just like you do in your example.
Here's a shortened version of your example:
var allWebs = Mock.Create<SPWebCollection>();
Mock.Arrange(() => allWebs.Names).ReturnsCollection<
Mock.Arrange(() => allWebs.Add(Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.IsAny<
>(), Arg.AnyString, Arg.AnyBool, Arg.AnyBool).ID).Returns(webGuid);
I explicitly create and arrange a mock of
, and then arrange that the AllWebs property of any SPSite (ignoring instance) will return my mock. The syntax
is equivalent to arranging the AllWebs property on a specific instance of SPSite and then adding .IgnoreInstance() to that arrangement.
I hope this helps you with your current situation. If you have any other questions, please, don't hesitate to write us back.
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums
, or our JustTrace