开发者

Stub not returning correct value with Rhino Mocks 3.6

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:

   开发者_如何学C [SetUp]
    public void SetUp()
    {
        repository = new MockRepository();
        webUserDal = repository.Stub<IWebUserDal>();
    }

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

        var user2 = webUserDal.Load("harry@test.com");

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

User1's email property is harry@test.com while user2's email property is null

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜