`
experience
  • 浏览: 192739 次
社区版块
存档分类
最新评论
阅读更多
http://developernotes.com/archive/2006/06/06/Rhino...

NMock不支持mocking classes. Rhino Mocks allows you to create a PartialMock of a class with parameterized constructor arguments.

Sample code pieces:

public abstract class DomainObject
{
    public virtual Guid GetUser()
    {
        Guid g = GetId();
        if (g == Guid.Empty)
        {
            g = Guid.NewGuid();
        }
    return g;
    }   
    public abstract Guid GetId();
}


    [Test()]
public void PatialMock()
    {
        MockRepository mocks = new MockRepository();
DomainObject anObject =
            (DomainObject)mocks.PartialMock(typeof(DomainObject));
Guid g = Guid.NewGuid();
Expect.Call(anObject.GetId()).Return(g);
mocks.ReplayAll();
Assert.AreEqual(g, anObject.GetUser());
mocks.VerifyAll();
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics