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();
}

相关文章:

  • 2021-09-09
  • 2021-12-19
  • 2021-09-11
  • 2021-09-05
  • 2022-12-23
  • 2022-02-08
猜你喜欢
  • 2021-11-10
  • 2021-12-16
  • 2022-12-23
  • 2022-01-13
  • 2021-09-13
  • 2021-06-11
  • 2022-02-20
相关资源
相似解决方案