NSubstitute not implementing publish method of IMediator

Viewed 238

I have this method that creates an instance of a Pipeline Behavior to validate a command

        internal PipelineBehavior<TCommand, bool> CreatePipelineBehaviorValidator(IValidator<TCommand> validator)
        {
            var cache = Substitute.For<IMemoryCache>();
            var bus = Substitute.For<IMediator>();

            IEnumerable<IValidator<TCommand>> validators = new List<IValidator<TCommand>> {validator};

            return Substitute.ForPartsOf<PipelineBehavior<TCommand, bool>>(cache, validators, bus);
        }

and inside PipelineBehavior i uses the mocked bus version that i pass to the PipelineBehavior class constructor to publish an ExceptionNotification

 _bus.Publish(new ExceptionNotification(error.ErrorCode, error.ErrorMessage, error.PropertyName));

but when i run the test, and tries to execute the Publish method of the _bus object it throws me an

System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task MediatR.IMediator.Publish(!!0, System.Threading.CancellationToken)'.

NSubstitute doenst create the publish method?

I tried to use ForPartsOf<IMediator>() but it accepts only class, not interfaces

0 Answers
Related