c# - Failure message for an NSubstitute .Received call -
in nsubstitute, possible specify message should thrown if received fails? following:
[test] public void should_execute_command() { var command = substitute.for<icommand>(); var = new somethingthatneedsacommand(command); something.dosomething(); command.received() .execute() .because("we should have executed command passed in"); }
for comparison, in moq, can this:
command.verify(c => c.execute, "we should have executed command passed in");
and message part of test failure message in test runner. can help create test failures easier read/diagnose. there similar in nsubstitute?
there no way alter message receive in receivedcallexception
; built straight hard-coded strings in nsubstitute.core.receivedcallsexceptionthrower
throw
method:
public void throw(icallspecification callspecification, ienumerable<icall> matchingcalls, ienumerable<icall> nonmatchingcalls, quantity requiredquantity) { stringbuilder stringbuilder = new stringbuilder(); stringbuilder.appendline(string.format("expected receive {0} matching:\n\t{1}", requiredquantity.describe("call", "calls"), callspecification)); this.appendmatchingcalls(callspecification, matchingcalls, stringbuilder); if (requiredquantity.requiresmorethan<icall>(matchingcalls)) { this.appendnonmatchingcalls(callspecification, nonmatchingcalls, stringbuilder); } throw new receivedcallsexception(stringbuilder.tostring()); }
unless you're ready dive in nsubstitute code, best bet grab receivedcallsexception
, throw own message.
c# nsubstitute
No comments:
Post a Comment