tags:

views:

71

answers:

1

Hi

I'm trying to write a test using Rhino Mocks 3.6 with AAA. The problem I'm running into is that the Stub i've set up doesn't seem to be returning the correct object.

The following test fails:

    [SetUp]
    public void SetUp()
    {
        repository = new MockRepository();
        webUserDal = repository.Stub<IWebUserDal>();
    }

    [Test]
    public void Test()
    {
        var user1 = new WebUser{Status = Status.Active, Email = "[email protected]"};
        webUserDal.Stub(x => x.Load(Arg<string>.Is.Anything)).Return(user1);

        var user2 = webUserDal.Load("[email protected]");

        Assert.AreEqual(user1.Email, user2.Email);
    }

User1's email property is [email protected] while user2's email property is null

Could anyone shed some light on what I'm doing wrong?

+1  A: 

You mixed up the old and new syntax, and it doesn't seem to work nicely together. If you want to use the new syntax (preferred), you have to change your set up method to:

[SetUp]
public void SetUp()
{
    webUserDal = MockRepository.GenerateStub<IWebUserDal>();
}

If you create the MockRepository object then you need to run repository.ReplayAll() before you use the mocks, but this is the old syntax. So its better to just use static methods.

Grzenio