Thanks for bringing up the issue. However, I wrote the test in a bit different way to better illustrate the problem:
var folder = new DirectoryInfo("C:\\Program Files");
bool called = false;
Mock.Arrange(() => folder.GetDirectories("Microsoft Visual Studio 8"))
.DoInstead(() => called = true)
var instance = new TypeBeingTested();
Assert.Fail("No exception was raised in TypeBeingTested constructor.");
In line Assert.IsTrue
, the test is failing as the instance created inside TypeBeingTested
is different from what is created in the test method. As, we can see that the setup is applied to the instance and to make things even more clear, Let's consider the following example:
var foo1 = Mock.Create<Foo>();
var foo2 = Mock.Create<Foo>();
Mock.Arrange(() => foo2.Echo(Arg.IsAny<
Mock.Arrange(() => foo1.Echo(Arg.IsAny<
arg) => arg);
Now, here we can see that different instances of the Foo
class is meant to be evaluated differently. Therefore, the setup made on instance 1 should not intercept with the setup on instance 2.
This also a basic to the object oriented design where two different instances should never interfere to each other. Moreover, making instances flat, breaks the integrity as well.
Currently, the solution is that you have an overload in TypeBeingTested
class that accepts a DirectoryInfo
However, we have opened an item in our JustMock backlog to provide an additional modifer named "IgnoreInstance" for Mock.Arrange(..)
Mock.Arrange(() => folder.GetDirectories(
"Microsoft Visual Studio 8"
.DoInstead(() => called =
This will evaluate the expected setup, no matter if the instance is newly created and has no relation with the one used inside Mock.Arrange
Hope this information is useful.
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking
system and vote to affect the priority of the items