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