Can't figure out a strategy to test the pattern following:
The problem is to avoid AnotherCall from being called from within VoidCall to isolate VoidCall's implemenation. You can't use IFoo because neither implementation can be called, but the DoNothing doesn't seem to have any effect on avoiding AnotherCall even if you do a foo.AnotherCall(). Also the CallOriginal seems valueless, since without it the method gets called anyway. I don't see the value of it without parameters to VoidCall (but I couldn't even get that to work). As a matter of fact nothing seems any different than not mocking Foo at all. What am I missing in the definition of these Arrange functions.
The problem is to avoid AnotherCall from being called from within VoidCall to isolate VoidCall's implemenation. You can't use IFoo because neither implementation can be called, but the DoNothing doesn't seem to have any effect on avoiding AnotherCall even if you do a foo.AnotherCall(). Also the CallOriginal seems valueless, since without it the method gets called anyway. I don't see the value of it without parameters to VoidCall (but I couldn't even get that to work). As a matter of fact nothing seems any different than not mocking Foo at all. What am I missing in the definition of these Arrange functions.
[TestClass]
public class FooTest
{
[TestMethod]
public void SimpleExampleWithDoNothing()
{
// Arrange
var foo = Mock.Create<
Foo
>();
Mock.Arrange(() => foo.VoidCall()).CallOriginal();
Mock.Arrange(() => foo.AnotherCall()).DoNothing();
// Act
foo.VoidCall();
// Assert
Mock.Assert(foo);
}
}
public interface IFoo
{
void VoidCall();
void AnotherCall();
}
public class Foo : IFoo
{
public void VoidCall()
{
AnotherCall();
}
public void AnotherCall()
{
throw new InvalidOperationException();
}
}