public void QueryHandler_Exception_Test() { #region preparation ApplicationContext _Context = new ApplicationContext(); string errorType = GetBooksQueryError.Set_InternalServerError("").ErrorType; string errorDetail_part = "Value cannot be null"; #endregion #region test error Result <GetBooksQueryResult, GetBooksQueryError> result = new GetBooksQueryHandler(_Context).Handle(null); Assert.AreEqual(errorType, result.Error.ErrorType); Assert.IsTrue(result.Error.ErrorDetail.Contains(errorDetail_part)); #endregion }
public Result <GetBooksQueryResult, GetBooksQueryError> GetBooks(GetBooksQuery query) { Result <GetBooksQueryResult, GetBooksQueryError> _queryResult; try // try dispatch of the command { _queryResult = _QueryDispatcher.Dispatch <GetBooksQueryResult, GetBooksQueryError>(_Context, query); //handle the request } catch (Exception _exception) // catch every exception { string errorMsg = $"Error in {this.GetType()} queryHandler. Message: {_exception.Message} \n Stacktrace: {_exception.StackTrace}"; _Log.ErrorFormat(errorMsg); return(Result.Fail <GetBooksQueryResult, GetBooksQueryError>(GetBooksQueryError.Set_InternalServerError(errorMsg))); // return internal server error } finally { // do nothing } //GetBooksQueryHandler handler = new GetBooksQueryHandler(); //return handler.Handle(_Context, query); return(_queryResult); }