Menu

#25 Method Call Requires an Expectation

open
Choy Rim
5
2005-05-10
2005-05-06
No

We were previously using v.7.2 that allowed for the
calling of a dynamic mocked interface method without
an expectation attached to it. By looking over the
source, it looks like since v .7.5 this is no longer
possible. In the current version, v.7.6, the Call method
receives an IMethodCallExpectation from the
nextExpectation method. This method will return null if
there are no expectations and you are not strict. The
Call method is not handling null being returned and
therefore you get the NullReferenceException. In the
v.7.2 implementation, the code would have been:

IMethodCallExpectation e = nextExpectation
(methodCall);
if (e == null)
return null;

return e.CheckCallAndSendResponse(methodCall);

Here is a test that fails in the current version:

public interface ITest
{
void MethodTest();
}

[TestFixture]
public class TestDynamicMock
{
[Test]
public void
TestDynamicMockMethodWithoutExpectations()
{
DynamicMock dynamicMock =
new DynamicMock(typeof(ITest));

    ITest test = \(ITest\)

dynamicMock.Object;
test.MethodTest();
}
}

Discussion

  • Choy Rim

    Choy Rim - 2005-05-10

    Logged In: YES
    user_id=1023300

    Here I thought I was correcting a bug. All the unit tests
    passed.

    Personally I feel that this old *feature* was a bug. But
    that's my narrow viewpoint. We should open this up to argue
    the good and the bad.

    Maybe Griffin or some of the other users can shed some light
    as to why this is not a bug.

    If the test didn't have to specify the expectation, then it
    wouldn't clearly document the interaction between two
    objects. would this be useful for method calls that are
    irrelevant to the test?

     
  • Choy Rim

    Choy Rim - 2005-05-10
    • labels: --> Dynamic Mocks
    • assigned_to: nobody --> choyrim
     
  • Choy Rim

    Choy Rim - 2005-07-01

    Logged In: YES
    user_id=1023300

    Well, it doesnt look like anyone is interested in discussing
    this. And when in doubt, support backward compatibility.
    I'll go back and change this when I get a chance.

    It'll be a while though. My computer crashed and I've been
    having trouble restoring it.

     
  • Arild Fines

    Arild Fines - 2006-03-10

    Logged In: YES
    user_id=676362

    > Here I thought I was correcting a bug.

    How can it be considered "correcting a bug" when you
    introduce a NullReferenceException that comes out of nowhere
    with no relevant information as to what went wrong?

    > If the test didn't have to specify the expectation, then
    it
    >wouldn't clearly document the interaction between two
    objects.

    That's what the .Strict property is for. This bug (and yes,
    it's most definitely a bug) is in violation of the
    documentation for the Strict property.

    Fortunately I can fix this for myself, or I'd have no choice
    but to abandon the use of DotNetMock altogether. This
    behavior is quite clearly unacceptable.

     
  • Choy Rim

    Choy Rim - 2006-03-12

    Logged In: YES
    user_id=1023300

    Yeah it should do what it used to do. I'll fix it. Looks
    like you've already included a solution.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.