Rhino Mocks: AssertNotCalled (except when I'm loading)

189 views Asked by At

I have a dependency that gets called when the object I'm testing is created. However, it should never be called after that. How would I write such a test?

I'd like just this line as my test (since I'm trying to follow the AAA style of test writing). However, this assertion will fail since the Publish method was called during setup.

Notifier.AssertWasNotCalled(Sub(n) n.Publish(Arg(Of Message).Is.Anything))

Is there a way to "reset" the calls on the dependency I've mocked?

Note: I can set it up so that I check the property on the Message argument for a value I expect after initialization, but that makes my test more fragile/brittle and I'd like to avoid it if possible.

_notifier.AssertWasNotCalled(
  Sub(n) n.Publish(Arg(Of Message).Matches(Function(m) m.property = "yo!")))
1

There are 1 answers

1
Pondidum On BEST ANSWER

Here is how I would do it:

_notifier.AssertWasCalled(function(n) p.Publish, function(c) c.Repeat.Once().IgnoreArguments());

As this would make sure it is called once only, which would be triggered by your setup code as you have indicated.