NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Improve output for expected argument for custom argument matchers on non-match or make it customizable

Open rbeurskens opened this issue 9 months ago • 8 comments

When implementing a custom argument matcher, it would be nice that the output of what is expected would be the same of the default matchers (or is customizable): Example: sut.Received().MyMethod(Arg.Is<MyType>(p => p.Property == 42)); output:

NSubstitute.Exceptions.ReceivedCallsException Expected to receive a call matching: MyMethod(p => (p.Property == 42)) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): MyMethod(*MyType*)

at NSubstitute.Core.ReceivedCallsExceptionThrower.Throw(ICallSpecification callSpecification, IEnumerable`1 matchingCalls, IEnumerable`1 nonMatchingCalls, Quantity requiredQuantity) at NSubstitute.Routing.Handlers.CheckReceivedCallsHandler.Handle(ICall call) at NSubstitute.Routing.Route.Handle(ICall call) at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.ObjectProxy.MyMethod(MyType p)

With a custom argument matcher: (note the name of an internal proxy is used to describe the expected match)

NSubstitute.Exceptions.ReceivedCallsException Expected to receive a call matching: MyMethod(NSubstitute.Core.Arguments.ArgumentMatcher+GenericToNonGenericMatcherProxy`1[MyType]) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): MyMethod(*MyType*) (...)

.. or (of it implements IDescribeNonMatches):

NSubstitute.Exceptions.ReceivedCallsException Expected to receive a call matching: MyMethod(NSubstitute.Core.Arguments.ArgumentMatcher+GenericToNonGenericMatcherProxyWithDescribe`1[MyType]) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): MyMethod(*MyType*) (...)

Even if my custom matcher overrides .ToString() (which Arg.Is(Expression<Predicate<T>>)) seems to use to get the string of what is expected, the output does not change.

rbeurskens avatar Apr 26 '24 16:04 rbeurskens