locked
Calling the Original Method from the Stub Method Problem RRS feed

  • Question

  • On page 24 of the Moles reference manual a process is explained where one can call the original method from within a stub.

    I have done this and I am still seeing a "method not Moled" exception.

    My code looks like this:

    MMasterTestGenerator moledGenerator = new MMasterTestGenerator(theGenerator);
    moledGenerator.GetControlsIEnumerableOfITreeItem = (e) => {
    	moledGenerator.GetControlsIEnumerableOfITreeItem = null;
    	return theGenerator.GetControls(e);
    };
    

    HostType("Moles") is at the top of the test method.
    If I put a breakpoint in the anonymous method it is hit when I later call the method, but when it calls the second line to hit the original method the exception is thrown.

    I don't see what I'm missing or doing wrong. Any help would be appreciated.

    Wednesday, December 22, 2010 10:11 PM

Answers

  • It seems that the 'NotImplemented' fallback behavior is preventing you to do that (documentation is incomplete). Add the following line:

      var moledGenerator = new MMasterTestGenerator(theGenerator) { InstanceFallthrough = MoleBehaviors.Fallthrough };

    This will tell Moles to allow calls that go to the original method.


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    • Marked as answer by JMRobertson Tuesday, February 8, 2011 4:15 PM
    Wednesday, January 5, 2011 4:31 AM