How to mock and autofill interfaces using Rhino Mocks?

Jan 31, 2013 at 7:30 AM
There are full samples with Moq + AutoFixture, but missing with Rhino Mocks. So lets say we have simple interface:
public interface ISimpleComponent
{
    string TextValue { get; set; }
}
And here NUnit tests:
[TestFixture]
public class FillInterfaceTests
{
    [Test]
    public void Autofill_Test_1()
    {
        var fixture = new Fixture().Customize(new AutoRhinoMockCustomization());

        var mockInterface = fixture.CreateAnonymous<ISimpleComponent>();
            
        Assert.That(mockInterface.TextValue, Is.Not.Empty);
    }

    [Test]
    public void Autofill_Test_2()
    {
        var stub = MockRepository.GenerateStub<ISimpleComponent>();
        var fixture = new Fixture().Customize(new MultipleCustomization());
        fixture.Register(() => stub);

        var mockInterface = fixture.CreateAnonymous(stub);

        Assert.That(mockInterface.TextValue, Is.Not.Empty);
    }
}
Both tests fails (TextValue property is not filled). So what should be the correct usage RhinoMock and Autofixture?
Coordinator
Feb 1, 2013 at 3:59 PM
This behaviour is by design, because when you decide to use a dynamic mock library like Rhino Mocks, you are implicitly indicating that the dynamic mock library is responsible for the data and behaviour related to the instances it creates. For that reason, AutoFixture leaves it alone.

You may want to refer to this issue, or perhaps this discussion is helpful.