/// <summary> /// Adds <see cref="ValidationDetail" /> to <see cref="IValidationContext" /> with specified /// <see cref="ValidationSeverity" /> /// </summary> /// <exception cref="ValidationConditionException"> /// Throws when ValidationDetail.ValidationSeverity greater ValidationContext.ValidationSeverity. /// Example: Add fatal detail, when validation context severity is error /// </exception> public static ValidationDetail?AddValidationDetail( this IValidationCondition condition, string validationMessage, ValidationSeverity validationSeverity = ValidationSeverity.Error) { var validationContext = condition.ValidationContext; var validationDetail = new ValidationDetail( validationContext, condition.ValidationKey, validationMessage, validationSeverity, condition.IsValid ?? false); // Not null or false // Null by default, so validationContext.When(...).AddValidationDetail(...) works without additional conditions if (validationDetail.IsValid) { return(validationDetail); } validationContext.ValidationDetails.Add(validationDetail); if (validationDetail.ValidationSeverity > validationContext.ValidationSeverity) { throw new ValidationConditionException(validationDetail); } return(validationDetail); }
public static void Deconstruct( this ValidationDetail validationDetail, out string validationKey, out string validationMessage) { validationKey = validationDetail.ValidationKey; validationMessage = validationDetail.ValidationMessage; }
public static void Deconstruct( this ValidationDetail validationDetail, out string validationKey, out string validationMessage, out bool isValid) { validationKey = validationDetail.ValidationKey; validationMessage = validationDetail.ValidationMessage; isValid = validationDetail.IsValid; }
static ValidationResults ConvertToValidationResults(ValidationDetail[] results, object target) { // Convert the validation details in the exception to individual // ValidationResult instances and add them to the collection. ValidationResults adaptedResults = new ValidationResults(); foreach (ValidationDetail result in results) { adaptedResults.AddResult(new ValidationResult(result.Message, target, result.Key, result.Tag, null)); } return adaptedResults; }
public void AdwService_GetUserDetails_ThrowsExceptionFault() { string userId = "AB1234_D"; ValidationDetail details = new ValidationDetail("Error Occurred", "Key", "tag"); mockAdwActiveDirectory.Setup(m => m.GetUserIdNameDetails(It.IsAny <GetUserIdNameDetailsRequest>())) .Throws(new FaultException <ValidationFault>(new ValidationFault() { Details = new List <ValidationDetail>() { details } })); var userDetails = SystemUnderTest().GetUserDetails(userId); }
public static ValidationDetail ValidateLoanInformation(BorrowerAndLoanInformation input) { ValidationDetail result = new ValidationDetail(); result.ErrorMessages = new List <string>(); if (string.IsNullOrEmpty(input.Date)) { result.IsValid = false; result.ErrorMessages.Add("Date is empty"); } if (string.IsNullOrWhiteSpace(input.ApplicantName)) { result.IsValid = false; result.ErrorMessages.Add("Applicant Name was not entered."); } if (string.IsNullOrWhiteSpace(input.ApplicantStreetAddress)) { result.IsValid = false; result.ErrorMessages.Add("Applicant Street Address was not entered."); } if (string.IsNullOrWhiteSpace(input.ApplicantCityStateZip)) { result.IsValid = false; result.ErrorMessages.Add("Applicant City, State, Zip was not entered"); } if (string.IsNullOrWhiteSpace(input.PbmStreetAddress)) { result.IsValid = false; result.ErrorMessages.Add("Property Being Mortgaged - Street Address was not entered."); } if (string.IsNullOrWhiteSpace(input.SalePrice)) { result.IsValid = false; result.ErrorMessages.Add("Sale Price was not entered."); } return(result); }
private void Submit_Click(object sender, RoutedEventArgs e) { Output.IsSelected = true; try { BorrowerAndLoanInformation borrowData = MapInput_BorrowerInformation(); ClosingCostInformation closingData = MapInput_ClosingInformation(); ValidationDetail validation = ValidationService.ValidateLoanInformation(borrowData); MapOutput_BorrowerInformation(borrowData); MapOutput_loanSchedule(borrowData); MapOutput_LoanCosts(closingData); MapOutput_ProjectedPayments(borrowData); } catch (Exception ex) { var message = ex.Message; MessageBox.Show(message, "Error"); } }
T exceptionHandling <T>(Token token, Func <T> method) { testSleep(); ExceptionHandler.Default.EmailFeaturesEnabled = false; try { localizeThread(token); return(method()); } catch (ProfileRankException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ProfileRankException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (MaintenanceException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.MaintenanceException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (FileNotFoundException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.FileNotFoundException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ConsistencyException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ConsistencyException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ProfileDeletedException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ProfileDeletedException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (UserDeletedException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.UserDeletedException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ProfileIsNotActivatedException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ProfileIsNotActivatedException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (SecurityException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.SecurityException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (TrainingIntegrationException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.TrainingIntegrityException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (DeleteConstraintException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.DeleteConstraintException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ObjectIsFavoriteException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ObjectIsFavoriteException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (AlreadyOccupiedException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.AlreadyOccupied, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (LicenceException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.LicenceException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ProductAlreadyPaidException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ProductAlreadyPaid, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ObjectIsNotFavoriteException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ObjectIsNotFavoriteException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ProfileAlreadyFriendException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ProfileAlreadyFriendException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (CannotAcceptRejectInvitationDoesntExistException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.CannotAcceptRejectInvitationDoesntExistException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (DatabaseException adoEx) { BAServiceException baEx = new BAServiceException(ErrorCode.DatabaseException, adoEx.Message); baEx.ErrorId = ExceptionHandler.Default.Process(adoEx); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (GenericADOException adoEx) { BAServiceException baEx = new BAServiceException(ErrorCode.DatabaseException, adoEx.Message); baEx.ErrorId = ExceptionHandler.Default.Process(adoEx); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (DatabaseVersionException adoEx) { BAServiceException baEx = new BAServiceException(ErrorCode.DatabaseVersionException, adoEx.Message); baEx.ErrorId = ExceptionHandler.Default.Process(adoEx); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ObjectNotFoundException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ObjectNotFound, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (FaultException <BAServiceException> ) { throw; } catch (Portable.Exceptions.AuthenticationException ex) { BAAuthenticationException baEx = new BAAuthenticationException(ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAAuthenticationException>(baEx, baEx.Message); } catch (InvalidOperationException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.InvalidOperationException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ArgumentNullException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ArgumentNullException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); baEx.AdditionalData = ex.ParamName; throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (EMailSendException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.EMailSendException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (NullReferenceException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.NullReferenceException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ArgumentOutOfRangeException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ArgumentOutOfRange, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (UniqueException uniqEx) { BAServiceException baEx = new BAServiceException(ErrorCode.UniqueException, uniqEx.Message); baEx.ErrorId = ExceptionHandler.Default.Process(uniqEx); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (CrossProfileOperationException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.CrossProfileOperation, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (UnauthorizedAccessException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.UnauthorizedAccessException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (ValidationException ex) { ValidationFault fault = new ValidationFault(); foreach (var result in ex.Results) { ValidationDetail detail = new ValidationDetail(result.Message, result.Key, result.Tag); fault.Add(detail); } throw new FaultException <ValidationFault>(fault, ex.Message); } catch (ArgumentException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.ArgumentException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (StaleObjectStateException ex) { BAServiceException baEx = new BAServiceException(ErrorCode.OldDataException, "You are trying to change old data. In the database there is a newer version so please take the latest version and try again"); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } catch (Exception ex) { BAServiceException baEx = new BAServiceException(ErrorCode.UnexpectedException, ex.Message); baEx.ErrorId = ExceptionHandler.Default.Process(ex); throw new FaultException <BAServiceException>(baEx, baEx.Message); } }