質問

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!")))
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top