public Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { ValidationResult validationResult; ModeloInvalidoException validationError; if (_type == _typeOperationResult) { validationResult = _validator.Validate(request); if (validationResult.IsValid) { return(next?.Invoke()); } validationError = new ModeloInvalidoException(validationResult.Errors.GroupBy(v => v.PropertyName, v => v.ErrorMessage).ToDictionary(v => v.Key, v => v.Select(y => y))); return(Task.FromResult((TResponse)Convert.ChangeType(OperationResult.Error(validationError), _type))); } if (!_type.IsGenericType || _type.GetGenericTypeDefinition() != _typeOperationResultGeneric) { return(next?.Invoke()); } validationResult = _validator.Validate(request); if (validationResult.IsValid) { return(next?.Invoke()); } validationError = new ModeloInvalidoException(validationResult.Errors.GroupBy(v => v.PropertyName, v => v.ErrorMessage).ToDictionary(v => v.Key, v => v.Select(y => y))); return(Task.FromResult((TResponse)Convert.ChangeType(_operationResultError.Invoke(null, new object[] { validationError }), _type))); }
public static void ComMensagem(this ModeloInvalidoException exception, string mensagemEsperada) { Assert.Contains(mensagemEsperada, exception.Mensagens); }