Search code examples
.netunit-testingrhino-mocksstub

How to create stub, that throws exception on all calls in Rhino mocks?


Is it possible with Rhino Mocks to create a stub, that throws exception for all calls?

public interface IMyIF
{
    // Some methods
}

[TestClass]
public class MyTestClass
{
    [TestMethod()]
    public void MyTest()
    {
        MockRepository mocks = new MockRepository();
        IMyIF stb = mocks.Stub<IMyIF>();

        // Somehow set stb to throw some exception on every method call
        // without knowing all the methods and overloads in IMyIF interface

        // use stb to test something
    }
}

Solution

  • var stb = MockRepository.GenerateStrictMock<IMyIF>();