Thanks Tim. That's exactly what I mean. It is the non-virtual method.
I don't know if you get a chance to look at my real world code. My
class is inheriting from Spring.Net's AdoTemplate, which has over 100
of overloaded methods that I need to adapter. And further I need to
write over 100 test cases for those adapting methods.
I often rewrite my code when I found it becomes difficult to test and
the result was mostly a better design. But not this time. I was able
to write a Stub my self to complete the test, you can see the solution
using my own Stub instead of Rhino Mocks.
The solution for the fiction code using my own Stub is provided in my
blog post, let me include it here and I believe Rhino Mocks should (if
not now, theoretically can in future :)) be able to do the same. See
the MyClassStub and the test below.
[Test] public void UsingMyStub() {
const int workResult = 293848;
MyClassStub stub = new MyClassStub();
IDoNotOwn o = stub.ExpectCallDirtyWork(4).WillReturn
(workResult);
Assert.That(o.Outer(2), Is.EqualTo(workResult));
stub.VerifyAll();
}
private class MyClassStub : MyClass, IDoNotOwn {
private int _expectedI, _returnValue;
private bool _isCalled;
internal MyClassStub ExpectCallDirtyWork(int i) {
_expectedI = i; return this;
}
internal MyClassStub WillReturn(int value) {
_returnValue = value; return this;
}
internal void VerifyAll() {
Assert.IsTrue(_isCalled, "Call to DirtyWork was not
made.");
}
public new int DirtyWork(int i) {
Assert.That(i, Is.EqualTo(_expectedI));
Assert.IsFalse(_isCalled, "Duplicated call to
DirtyWork.");
_isCalled = true;
return _returnValue;
}
}
Kenneth
On Apr 18, 6:35 pm, Tim Barcz <
timba...@gmail.com> wrote:
> I believe if it's not virtual you're in trouble.
>
> Can you try adapting your code with the adapter pattern (see what I did
> there? :-)) and then you can mock...
>
> Tim
>
> >
http://kennethxu.blogspot.com/2009/04/rhino-mocks-strikes-to-mock-non...
>
> > And I have a real word test case that now I wrote my own stub class:
> > The test case:
>
> >
http://code.google.com/p/kennethxublogsource/source/browse/trunk/Spri...
>
> > And the code to be tested:
>
> >
http://code.google.com/p/kennethxublogsource/source/browse/trunk/Spri...
>
> > Thanks,
> > Kenneth