public FrmValidationResult(IValidationResult result) { InitializeComponent(); this.Result = result; ShowResult(); }
public ValidationException( IValidationResult validationResult, object value ) : base( validationResult == null ? null : validationResult.ErrorMessage ) { Arg.NotNull( validationResult, nameof( validationResult ) ); this.validationResult = new Lazy<IValidationResult>( () => validationResult ); Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="ValidationContextChange"/> class. /// </summary> /// <param name="validationResult">The validation result.</param> /// <param name="changeType">Type of the change.</param> /// <exception cref="ArgumentNullException">The <paramref name="validationResult"/> is <c>null</c>.</exception> public ValidationContextChange(IValidationResult validationResult, ValidationContextChangeType changeType) { Argument.IsNotNull("validationResult", validationResult); ValidationResult = validationResult; ChangeType = changeType; }
public void ShowResult(IValidationResult Result) { if (Result == null) Result = new ValidationResult(); int c = 0; c = Result.Count(r => r.FromRule is IcDphValidator); SetCount(lblpIcDph, c); c = Result.Count(r => r.FromRule is KvKindValidator); SetCount(lblpDruh, c); c = Result.Count(r => r.FromRule is PeriodValidator || r.FromRule is YearValidator); SetCount(lblpObdobie, c); c = Result.Count(r => r.FromRule is NameValidator); SetCount(lblpNazov, c); c = Result.Count(r => r.FromRule is StateValidator); SetCount(lblpStat, c); c = Result.Count(r => r.FromRule is CityValidator); SetCount(lblpObec, c); c = Result.Count(r => r.FromRule is BlackListValidator); SetCount(lblpBlacklist, c); c = Result.Count(r => r.FromRule is TaxPayerValidator); SetCount(lblpTaxpayers, c); c = Result.Count(r => r.FromRule is CorrectionValidator); SetCount(lblpKodopravy, c); c = Result.Count(r => r.FromRule is GoodsValidator); SetCount(lblpTovary, c); c = Result.Count(r => r.FromRule is TaxRateValidator || r.FromRule is ItemTaxValidator); SetCount(lblpTaxes, c); c = Result.Count(r => r.ProblemObject is A1); SetCount(lblpA1, c); c = Result.Count(r => r.ProblemObject is A2); SetCount(lblpA2, c); c = Result.Count(r => r.ProblemObject is B1); SetCount(lblpB1, c); c = Result.Count(r => r.ProblemObject is B2); SetCount(lblpB2, c); c = Result.Count(r => r.ProblemObject is B3); SetCount(lblpB3, c); c = Result.Count(r => r.ProblemObject is C1); SetCount(lblpC1, c); c = Result.Count(r => r.ProblemObject is C2); SetCount(lblpC2, c); c = Result.Count(r => r.ProblemObject is D1); SetCount(lblpD1, c); c = Result.Count(r => r.ProblemObject is D2); SetCount(lblpD2, c); }
/// <summary> /// Returns an ErrorInfo for a class level validation result /// </summary> /// <param name="result"> /// The validation result. /// </param> /// <returns> /// The ErrorInfo /// </returns> private static ErrorInfo GetClassLevelErrorInfo(IValidationResult result) { var errorInfo = new ErrorInfo(string.Empty, result.Message); if (typeof(ICaptcha).IsAssignableFrom(result.ClassContext)) { errorInfo = new ErrorInfo("Captcha", result.Message); } else { // Get the validation attributes on the entity type var validatorProperties = result.ClassContext.GetCustomAttributes(false).Where( x => typeof(IValidateMultipleProperties).IsAssignableFrom(x.GetType())); // If the validation message matches one of the attributes messages, // then set the correct property path, based on the primary property name validatorProperties.ForEach( x => { if (result.Message == ((IValidateMultipleProperties)x).Message) { errorInfo = new ErrorInfo( ((ValidationResult)result).InvalidValue.PropertyPath + ((IValidateMultipleProperties)x).PrimaryPropertyName, result.Message); } }); } return errorInfo; }
public TextValidationSerializer( IValidationRuleset ruleset, IValidationResult[] validationResults) : this() { Ruleset = ruleset; ValidationResults = validationResults; }
public XmlValidationSerializer( IXmlDocumentProvider docProvider, IValidationRuleset ruleset, IValidationResult[] validationResults) : this(docProvider) { Ruleset = ruleset; ValidationResults = validationResults; }
public void ResultIndicatesValidWhenNoValidationErrorsFound() { var innerResult = new ValidationResult(); validationResult = new FluentValidationResult(innerResult); bool isModelValid = validationResult.IsModelValid(); Assert.True(isModelValid); }
public void ResultShowNoErrorsForValidProperty() { var innerResult = new ValidationResult(); validationResult = new FluentValidationResult(innerResult); var errorsForProperty = validationResult.GetErrorsForProperty("NewProperty"); Assert.That(errorsForProperty.Count() == 0); }
public void ResultShowsNoErrorsWhenNoneWereFound() { var innerResult = new ValidationResult(); validationResult = new FluentValidationResult(innerResult); int totalErrorCount = validationResult.GetErrorCount(); Assert.That(totalErrorCount == 0); }
public IPerson CreateTestPerson(IValidationResult result, IValidatorService validator, string firstName, string lastName, string emailId) { result = validator.Validate(firstName, lastName, emailId); if (result.IsSuccess == true) { return new Person(firstName, lastName, emailId); } else { throw new ValidationException() { Invalid = result.InvalidFields, }; } }
public void ResultShowErrorsForInvalidProperty() { var innerResult = new ValidationResult(); string propertyName = "AnyProperty"; string errorMessage = "Just some error message, doesnt matter"; innerResult.Errors.Add(new ValidationFailure(propertyName, errorMessage)); validationResult = new FluentValidationResult(innerResult); var errorsForProperty = validationResult.GetErrorsForProperty(propertyName); Assert.That(errorsForProperty.Count() == 1); Assert.That(errorsForProperty.First() == errorMessage); }
private void AddResultToView(IValidationResult result) { if (result == null) return; foreach (var issue in result.Issues) { string objectName = issue.Object == null ? "" : issue.Object.DisplayName; gridResultsView.Rows.Add(imageList1.Images[LevelToImageIndex(issue.ErrorLevel)], issue.Description, objectName); var rowIndex = gridResultsView.Rows.Count - 1; var row = gridResultsView.Rows[rowIndex]; row.Tag = issue; } }
public void WhenLocalFileDepthIsEqualToMaxDepthValidationResultIsSuccess() { // Prepare int maxDepth = 4; IConfiguration configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth); MaximumTreeDepthValidation validation = new MaximumTreeDepthValidation(configuration); string path = @"C:\first\second\third\fourth"; IFileInfo file = MockFactory.FileWithPath(path); // Exercise IValidationResult validationResult = validation.Validate(file); // Verify AssertExtension.ValidationResultIsSuccess(validationResult, "Local file with depth equal to max depth triggers an error."); }
public void WhenUNCFileIsDeeperThanMaxDepthValidationResultIsError() { // Prepare int maxDepth = 3; IConfiguration configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth); MaximumTreeDepthValidation validation = new MaximumTreeDepthValidation(configuration); string tooDeepFile = @"\\server\share$\first\second\third\fourth"; IFileInfo file = MockFactory.FileWithPath(tooDeepFile); // Exercise IValidationResult validationResult = validation.Validate(file); // Verify AssertExtension.ValidationResultIsError(validationResult, "Too deep local file does not trigger an error."); }
/// <summary> /// Verifica se <see cref="stringValue"/> possui tamanho entre <see cref="minimum"/> e <see cref="maximum"/> /// </summary> /// <param name="validationResult"></param> /// <param name="stringValue"></param> /// <param name="minimum"></param> /// <param name="maximum"></param> /// <param name="errorMessage"></param> /// <returns></returns> public static IValidationResult AssertArgumentLength(this IValidationResult validationResult, string stringValue, int minimum, int maximum, string errorMessage) { if (string.IsNullOrEmpty(stringValue)) { stringValue = string.Empty; } int length = stringValue.Trim().Length; if (length < minimum || length > maximum) { validationResult.Add(errorMessage); } return(validationResult); }
public static TException ToException <TException>(this IValidationResult result, Action <TException, ValidationResultCollection> appendAction = null) where TException : CosmosException, new() { switch (result) { case ValidationResultCollection fluentResult: return(ToException(fluentResult, appendAction)); case null: throw new ArgumentNullException(nameof(result)); default: throw new ArgumentException("ValidationResultCollection's type is invalid."); } }
public void SetUp() { mappingSet = new MappingSetImpl(); engine = new ValidationRulesEngine(mappingSet); rule1 = MockRepository.GenerateMock<IValidationRule>(); rule2 = MockRepository.GenerateMock<IValidationRule>(); result1 = new ValidationResult(rule1); result2 = new ValidationResult(rule2); rule1.Stub(r => r.Run(mappingSet)).Return(result1); rule2.Stub(r => r.Run(mappingSet)).Return(result2); engine.AddRule(rule1); engine.AddRule(rule2); }
public static void Should(this IValidationResult source, ValidationType type, Guid guid) { switch (type) { case ValidationType.Pass: ShouldPass(source, guid); break; case ValidationType.Fail: ShouldFail(source, guid); break; default: throw new ArgumentOutOfRangeException(); } }
public void SetUp() { mappingSet = new MappingSetImpl(); engine = new ValidationRulesEngine(mappingSet); rule1 = MockRepository.GenerateMock <IValidationRule>(); rule2 = MockRepository.GenerateMock <IValidationRule>(); result1 = new ValidationResult(rule1); result2 = new ValidationResult(rule2); rule1.Stub(r => r.Run(mappingSet)).Return(result1); rule2.Stub(r => r.Run(mappingSet)).Return(result2); engine.AddRule(rule1); engine.AddRule(rule2); }
/// <summary> /// Give the validation error message (used as system error message) /// </summary> /// <param name="validationResult">Result of the validation</param> /// <param name="input">Data that failed on validation specifications</param> public RuleValidationError(IValidationResult validationResult, object input = null) { // get the calling method CallingMethod = @"N/A"; if (input != null) { // get the json from the validated input ValidatedDataJson = input.SerializeToJSon(false); } else { ValidatedDataJson = @"N/A"; } // log only in case when we have a valid result if (validationResult.IsNull()) { return; } var _failedTypes = validationResult.GetTypesFailedRulesTypes(); if (_failedTypes.IsNullOrHasZeroElements()) { return; } // preserve the failed validations FalseReturnValidationRules = new ReadOnlyCollection <Type>(_failedTypes); // build the error info var _rulesBuilder = new StringBuilder(); _rulesBuilder.AppendFormat(@"{0}: ", GetType().Name); for (var _i = 0; _i < FalseReturnValidationRules.Count; _i++) { var _validationRule = FalseReturnValidationRules[_i]; if (_i + 1 == FalseReturnValidationRules.Count || FalseReturnValidationRules.Count == 1) { _rulesBuilder.Append(_validationRule.Name); } else { _rulesBuilder.AppendFormat(@"{0}, ", _validationRule.Name); } } FaultMessage = string.Concat(@"Failed rules: ", _rulesBuilder.ToString(), Environment.NewLine, GetCombinedExceptionMessage()); }
public CreateTicketResponse(IValidationResult result, IValidationResultInterpreter resultInterpreter, Ticket createdTicket = null) { if (resultInterpreter == null) { throw new ArgumentNullException(nameof(resultInterpreter)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } Ticket = createdTicket; this.validationResult = result; this.resultInterpreter = resultInterpreter; }
public SavingsAccount GenerateSavingAccount(string[] accountArgs) { string accountNumber = AccountNumberGenerator.GenerateAccountNumber(); decimal balance = decimal.Parse(accountArgs[0]); decimal interestRate = decimal.Parse(accountArgs[1]); SavingsAccount savingsAccount = new SavingsAccount(accountNumber, balance, interestRate); IValidationResult validationResult = SavingAccountValidator.IsValid(savingsAccount); if (!validationResult.IsValid) { throw new ArgumentException(string.Join($"{Environment.NewLine}", validationResult.ValidationErrors)); } return(savingsAccount); }
public CreateCommentResponse(IValidationResult result, IValidationResultInterpreter resultInterpreter, Comment comment = null) { if (resultInterpreter == null) { throw new ArgumentNullException(nameof(resultInterpreter)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } Comment = comment; this.validationResult = result; this.resultInterpreter = resultInterpreter; }
public CheckingAccount GenerateCheckingAccount(string[] accountArgs) { string accountNumber = AccountNumberGenerator.GenerateAccountNumber(); decimal balance = decimal.Parse(accountArgs[0]); decimal fee = decimal.Parse(accountArgs[1]); CheckingAccount checkingAccount = new CheckingAccount(accountNumber, balance, fee); IValidationResult validationResult = CheckingAccountValidator.IsValid(checkingAccount); if (!validationResult.IsValid) { throw new ArgumentException(string.Join($"{Environment.NewLine}", validationResult.ValidationErrors)); } return(checkingAccount); }
private void AddResultToView(IValidationResult result) { if (result == null) { return; } foreach (var issue in result.Issues) { string objectName = issue.Object == null ? "" : issue.Object.DisplayName; gridResultsView.Rows.Add(imageList1.Images[LevelToImageIndex(issue.ErrorLevel)], issue.Description, objectName); var rowIndex = gridResultsView.Rows.Count - 1; var row = gridResultsView.Rows[rowIndex]; row.Tag = issue; } }
public IValidationResult Validate(T entity) { try { this.ApplyRules(entity); IValidationResult result = this.factory.Resolve <IValidationResult>(); result.IsValid = true; return(result); } catch (Exception ex) { IValidationResult result = this.factory.Resolve <IValidationResult>(); result.IsValid = false; result.Exception = ex; return(result); } }
public ActionResult UpdateDoctrine(AccountDoctrinesViewModel viewModel) { // Convert the currently logged-in account id to an integer. int accountId = Conversion.StringToInt32(User.Identity.Name); if (ModelState.IsValid) { // Create an Auto Mapper map between the doctrine entity and the view model. Mapper.CreateMap <AccountDoctrinesViewModel, Doctrine>(); // Sanitise the form values. viewModel.AccountId = accountId; viewModel.Name = Conversion.StringToSafeString(viewModel.Name); viewModel.Description = viewModel.Description; viewModel.ImageUrl = Server.HtmlEncode(viewModel.ImageUrl) ?? string.Empty; // Populate a doctrine with automapper and pass it back to the service layer for update. Doctrine doctrine = Mapper.Map <AccountDoctrinesViewModel, Doctrine>(viewModel); IValidationResult validationResult = this.doctrineShipsServices.UpdateDoctrine(doctrine); // If the validationResult is not valid, something did not validate in the service layer. if (validationResult.IsValid) { TempData["Status"] = "The doctrine was successfully updated."; } else { TempData["Status"] = "Error: The doctrine was not updated, a validation error occured.<br /><b>Error Details: </b>"; foreach (var error in validationResult.Errors) { TempData["Status"] += error.Value + "<br />"; } } return(RedirectToAction("Doctrines")); } else { // Re-populate the view model and return with any validation errors. viewModel.Doctrines = this.doctrineShipsServices.GetDoctrineList(accountId); ViewBag.Status = "Error: The doctrine was not updated, a validation error occured."; return(View("~/Views/Account/Doctrines.cshtml", viewModel)); } }
public ActionResult UpdateShipFit(AccountShipFitsViewModel viewModel) { // Convert the currently logged-in account id to an integer. int accountId = Conversion.StringToInt32(User.Identity.Name); if (ModelState.IsValid) { // Create an Auto Mapper map between the ship fit entity and the view model. Mapper.CreateMap <AccountShipFitsViewModel, ShipFit>(); // Sanitise the form values. viewModel.AccountId = accountId; viewModel.Name = Conversion.StringToSafeString(viewModel.Name); viewModel.Role = Conversion.StringToSafeString(viewModel.Role); viewModel.Notes = viewModel.Notes; // Populate a ship fit with automapper and pass it back to the service layer for update. ShipFit shipFit = Mapper.Map <AccountShipFitsViewModel, ShipFit>(viewModel); IValidationResult validationResult = this.doctrineShipsServices.UpdateShipFit(shipFit); // If the validationResult is not valid, something did not validate in the service layer. if (validationResult.IsValid) { TempData["Status"] = "The ship fit was successfully updated."; } else { TempData["Status"] = "Error: The ship fit was not updated, a validation error occured.<br /><b>Error Details: </b>"; foreach (var error in validationResult.Errors) { TempData["Status"] += error.Value + "<br />"; } } return(RedirectToAction("ShipFits")); } else { // Re-populate the view model and return with any validation errors. viewModel.ShipFits = this.doctrineShipsServices.GetShipFitList(accountId); ViewBag.Status = "Error: The ship fit was not updated, a validation error occured."; return(View("~/Views/Account/ShipFits.cshtml", viewModel)); } }
public override string Execute() { if (this.CommandArgs.Length != 3) { throw new ArgumentException("Input is not valid!"); } if (AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException("You should log out before log in with another user!"); } string username = this.CommandArgs[0]; string password = this.CommandArgs[1]; string email = this.CommandArgs[2]; User user = new User() { Username = username, Password = password, Email = email }; IValidationResult validationResult = UserValidator.IsValid(user); if (!validationResult.IsValid) { throw new ArgumentException(string.Join($"{Environment.NewLine}", validationResult.ValidationErrors)); } if (this.Database.Users.Any(u => u.Username == username)) { throw new ArgumentException("Username already taken!"); } if (this.Database.Users.Any(u => u.Email == email)) { throw new ArgumentException("Email already taken!"); } this.Database.Users.Add(user); this.Database.SaveChanges(); return($"User {username} registered successfully!"); }
public IValidationResult Validate() { if (!IsOverriden) { //MS Validation Validator NotNullStringLengthValidator = new AndCompositeValidator(this.msNotNullValidator, this.msStringLengthValidator); ValidationResults valResults = NotNullStringLengthValidator.Validate(Customer.customerNumber); if (!valResults.IsValid) //if not valid { RuleValidationResult = new MyValidationResult(); RuleValidationResult.ValidationMessageList.Add(new NullValidationMessage()); } if (Customer.EmailList != null) { //Some other Random Test Validation. RegexValidator in this case Validator <string> emailAddresssValidator = new RegexValidator(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); valResults = emailAddresssValidator.Validate(Customer.EmailList.First()); } else { valResults = this.msNotNullValidator.Validate(Customer.EmailList); } //Holidays Own Validation //RuleValidationResult = valResults; if (valResults != null) { RuleValidationResult = new MyValidationResult(); foreach (var varRes in valResults) { IValidationMessage val = new MSWrapperMessage(MessageTypes.Error, varRes.Message); RuleValidationResult.ValidationMessageList.Add(val); } } } return(RuleValidationResult); }
public void PositionInputValidator_Validate_Should_Confirm_When_Input_UpperCase_Or_LoverCase() { IInputValidator validator = _factory.GetInputValidator <IPosition>(); string input = "7 5 s"; IValidationResult result = validator.Validate(input); Assert.IsTrue(result.IsValid); Assert.That(result.Message, Is.Null.Or.Empty); input = "7 5 S"; result = validator.Validate(input); Assert.IsTrue(result.IsValid); Assert.That(result.Message, Is.Null.Or.Empty); }
public void WhenFileFilenameIsInvalidValidationResultIsError() { // Prepare string invalidFilename = "invalid_filename"; List <string> invalidFilenames = new List <string> { invalidFilename }; IConfiguration configuration = MockFactory.ConfigurationWithInvalidFilenames(invalidFilenames); InvalidFilenameValidation validation = new InvalidFilenameValidation(configuration); IFileInfo file = MockFactory.FileWithName(invalidFilename); // Exercise IValidationResult validationResult = validation.Validate(file); // Verify Assert.StrictEqual <Result>(Result.Fail, validationResult.Result); }
public void AggregateARuleSetWithValidRulesResultsInAValidResult() { ValidationAggregator testee = new ValidationAggregator(this.validationFactory, false); IRuleSet <IValidationRule> ruleSet = new ValidationRuleSet { this.mockery.NewMock <IValidationRule>(), this.mockery.NewMock <IValidationRule>() }; Expect.On(ruleSet[0]).Method("Evaluate").Will(Return.Value(new ValidationResult(true))); Expect.On(ruleSet[1]).Method("Evaluate").Will(Return.Value(new ValidationResult(true))); string logInfo; IValidationResult result = testee.Aggregate(ruleSet, out logInfo); Assert.IsTrue(result.Valid, "aggregated result has to be valid if all rules are valid."); }
public void WhenDirectoryNameIsValidValidationResultIsSuccess() { // Prepare string invalidFilename = "invalid_filename"; List <string> invalidFilenames = new List <string> { invalidFilename }; IConfiguration configuration = MockFactory.ConfigurationWithInvalidFilenames(invalidFilenames); InvalidFilenameValidation validation = new InvalidFilenameValidation(configuration); IDirectoryInfo file = MockFactory.DirectoryWithName("valid_name"); // Exercise IValidationResult validationResult = validation.Validate(file); // Verify Assert.StrictEqual <Result>(Result.Success, validationResult.Result); }
public async Task <IValidationResult> ValidateAsync(T entity) { try { await this.ApplyRulesAsync(entity).ConfigureAwaitFalse(); IValidationResult result = this.factory.Resolve <IValidationResult>(); result.IsValid = true; return(result); } catch (Exception ex) { IValidationResult result = this.factory.Resolve <IValidationResult>(); result.IsValid = false; result.Exception = ex; return(result); } }
public async Task <IValidationResult> Validate(string employerName, string employerSurname) { IValidationResult result = ValidationResult.CreateEmpty(); if (string.IsNullOrEmpty(employerName)) { result.ResultParameters.Add(ExceptionMessage.EmployerNameIsNullOrEmpty); } if (string.IsNullOrEmpty(employerSurname)) { result.ResultParameters.Add(ExceptionMessage.EmployerSurnameIsNullOrEmpty); } result.IsValid = result.ResultParameters.Count == 0; return(result); }
protected virtual async Task ValidateAsync(T command) { IValidationResult result = null; if (validationHandler != null) { result = await validationHandler.HandleAsync(command); } else if (validationDispatcher != null) { result = await validationDispatcher.ValidateAsync(command); } if (result != null) { result.ThrowIfNotValid(); } }
private IValidationResult Validate(IValidationRequest request, IValidationResult result) { /// The package signature validator runs after the <see cref="PackageSignatureProcessor" />. /// All signature validation issues should be caught and handled by the processor. if (result.Status == ValidationStatus.Failed || result.NupkgUrl != null) { if (!_config.RepositorySigningEnabled) { _logger.LogInformation( "Ignoring invalid validation result in package signature validator as repository signing is disabled. " + "Status = {ValidationStatus}, Nupkg URL = {NupkgUrl}, validation issues = {Issues}", result.Status, result.NupkgUrl, result.Issues.Select(i => i.IssueCode)); return(ValidationResult.Succeeded); } _logger.LogCritical( "Unexpected validation result in package signature validator. This may be caused by an invalid repository " + "signature. Throwing an exception to force this validation to dead-letter. " + "Status = {ValidationStatus}, Nupkg URL = {NupkgUrl}, validation issues = {Issues}", result.Status, result.NupkgUrl, result.Issues.Select(i => i.IssueCode)); throw new InvalidOperationException("Package signature validator has an unexpected validation result"); } /// Suppress all validation issues. The <see cref="PackageSignatureProcessor"/> should /// have already reported any issues related to the author signature. Customers should /// not be notified of validation issues due to the repository signature. if (result.Issues.Count != 0) { _logger.LogWarning( "Ignoring {ValidationIssueCount} validation issues from result. Issues: {Issues}", result.Issues.Count, result.Issues.Select(i => i.IssueCode)); return(new ValidationResult(result.Status)); } return(result); }
/// <summary> /// Writes the specified validation result. /// </summary> /// <param name="validationResult">The validation result.</param> /// <exception cref="ArgumentException"></exception> public void Write(IValidationResult validationResult) { switch (validationResult.Kind) { case ValidationKind.SystemValidation: Validation.Results.Add(new PSValidationResult(validationResult)); break; case ValidationKind.NamespaceValidation: if (validationResult.Result == Result.Fail) { Validation.Results.Add(new PSValidationResult(validationResult)); } break; default: throw new ArgumentException(string.Format(StorageSyncResources.UnsupportedErrorFormat, validationResult.Kind.GetType().Name, validationResult.Kind)); } }
protected virtual int?ExtractTagLine(IValidationResult validationResult) { var tag = validationResult.Tag; if (ReferenceEquals(tag, null)) { return(null); } if (tag is string) { return(null); } var type = tag.GetType(); var lineProperty = type.GetPropertyEx("Line"); return(lineProperty?.GetValue(tag, new object[0]) as int?); }
public void Write(IValidationResult validationResult) { if (this.IsSystemValidation(validationResult)) { this._systemValidationResults.Add(validationResult); } else { if (IsError(validationResult)) { if (!this._validationErrorsHistogram.ContainsKey(validationResult.Type)) { this._validationErrorsHistogram[validationResult.Type] = 0; } this._validationErrorsHistogram[validationResult.Type] += 1; } } }
public void Write(IValidationResult validationResult) { switch (validationResult.Kind) { case ValidationKind.SystemValidation: this.Validation.Results.Add(new PSValidationResult(validationResult)); break; case ValidationKind.NamespaceValidation: if (validationResult.Result == Result.Fail) { this.Validation.Results.Add(new PSValidationResult(validationResult)); } break; default: throw new ArgumentException($"{validationResult.Kind.GetType().Name} value {validationResult.Kind} is unsupported"); } }
public async Task <IValidationResult> Validate(Employer employer, DateTime dayFrom, DateTime dayTo) { IValidationResult result = ValidationResult.CreateEmpty(); var availableCountOfVacationDays = employer.MaxVacationDays - GetVacationsFromCurrentYear(employer); if (dayFrom.Year == dayTo.Year && dayFrom.DayOfYear <= dayTo.DayOfYear) { var choosedVacationDaysCurrentYear = GetDatesInSameYear(dayFrom, dayTo); if (availableCountOfVacationDays < choosedVacationDaysCurrentYear.Count()) { result.ResultParameters.Add(ExceptionMessage.TooLongVacation); } } else if (dayFrom.Year < dayTo.Year) { var choosedVacationDaysPriviousYear = GetDatesInPriviousYear(dayFrom, dayTo); if (availableCountOfVacationDays < choosedVacationDaysPriviousYear.Count()) { result.ResultParameters.Add(ExceptionMessage.TooLongVacationInPriviousYear); } availableCountOfVacationDays = employer.MaxVacationDays - GetVacationsFromCurrentYear(employer); var choosedVacationDaysNextYear = GetDatesInNextYear(dayFrom, dayTo); if (availableCountOfVacationDays < choosedVacationDaysNextYear.Count()) { result.ResultParameters.Add(ExceptionMessage.TooLongVacationInNextYear); } } else { result.ResultParameters.Add(ExceptionMessage.IncorrectDatesOfVacation); } result.IsValid = result.ResultParameters.Count == 0; return(result); }
public void ShowResult(IValidationResult Result) { Clear(); if (Result == null) Result = new ValidationResult(); List<IValidationItemResult> found; found = Result.Where(r => r.FromRule is IcDphValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is KvKindValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is PeriodValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is YearValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is NameValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is StateValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is CityValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is BlackListValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is TaxPayerValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is CorrectionValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is GoodsValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is TaxRateValidator).ToList(); CheckFound(found); found = Result.Where(r => r.FromRule is ItemTaxValidator).ToList(); CheckFound(found); found = Result.Where(r => r.ProblemObject is A1).ToList(); if (found.Count > 0) AddProblem("A1", found.Count, "Problémové položky typu A1.", false); found = Result.Where(r => r.ProblemObject is A2).ToList(); if (found.Count > 0) AddProblem("A2", found.Count, "Problémové položky typu A2.", false); found = Result.Where(r => r.ProblemObject is B1).ToList(); if (found.Count > 0) AddProblem("B1", found.Count, "Problémové položky typu B1.", false); found = Result.Where(r => r.ProblemObject is B2).ToList(); if (found.Count > 0) AddProblem("B2", found.Count, "Problémové položky typu B2.", false); found = Result.Where(r => r.ProblemObject is B3).ToList(); if (found.Count > 0) AddProblem("B3", found.Count, "Problémové položky typu B3.", false); found = Result.Where(r => r.ProblemObject is C1).ToList(); if (found.Count > 0) AddProblem("C1", found.Count, "Problémové položky typu C1.", false); found = Result.Where(r => r.ProblemObject is C2).ToList(); if (found.Count > 0) AddProblem("C2", found.Count, "Problémové položky typu C2.", false); found = Result.Where(r => r.ProblemObject is D1).ToList(); if (found.Count > 0) AddProblem("D1", found.Count, "Problémové položky typu D1.", false); found = Result.Where(r => r.ProblemObject is D2).ToList(); if (found.Count > 0) AddProblem("D2", found.Count, "Problémové položky typu D2.", false); flowContent.SuspendLayout(); flowContent.Controls.Remove(notRunPanel); // pridame ok panel - vsetko je v poriadku if (flowContent.Controls.Count == 0) flowContent.Controls.Add(okPanel); flowContent.ResumeLayout(); }
/// <summary> /// Raises the right events based on the validation result. /// </summary> /// <param name="validationResult">The validation result.</param> /// <param name="notifyGlobal">If set to <c>true</c>, the global properties such as <see cref="INotifyDataErrorInfo.HasErrors" /> and <see cref="INotifyDataWarningInfo.HasWarnings" /> are also raised.</param> /// <exception cref="ArgumentNullException">The <paramref name="validationResult"/> is <c>null</c>.</exception> protected void NotifyValidationResult(IValidationResult validationResult, bool notifyGlobal) { Argument.IsNotNull("validationResult", validationResult); var propertyName = string.Empty; var fieldValidationResult = validationResult as IFieldValidationResult; if (fieldValidationResult != null) { propertyName = fieldValidationResult.PropertyName; } switch (validationResult.ValidationResultType) { case ValidationResultType.Warning: NotifyWarningsChanged(propertyName, notifyGlobal); break; case ValidationResultType.Error: NotifyErrorsChanged(propertyName, notifyGlobal); break; } }
public DomainValidationException(string message, IValidationResult validationResult) : base(message) { _validationResult = validationResult; }
/// <summary> /// Returns an ErrorInfo for a property level validation result /// </summary> /// <param name="result"> /// The validation result. /// </param> /// <returns> /// The ErrorInfo /// </returns> private static ErrorInfo GetPropertyLevelErrorInfo(IValidationResult result) { return new ErrorInfo(((ValidationResult) result).InvalidValue.PropertyPath, result.Message); }
public void Merge(IValidationResult validationResult) { this.errors = this.errors.Concat(validationResult.Errors).GroupBy(d => d.Key).ToDictionary(d => d.Key, d => d.First().Value); }
public void ShowResult(IValidationResult Result) { Clear(); if (Result == null) Result = new ValidationResult(); lblErrCount.Text = string.Format("{0} {1}", Common.theSign, Result.Count); List<IValidationItemResult> found; var row = 1; found = Result.Where(r => r.FromRule is IcDphValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is KvKindValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is PeriodValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is YearValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is NameValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is StateValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is CityValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is BlackListValidator).ToList(); CheckFound(found, ref row, 0); lblBlacklistCount.Text = string.Format("{0} {1}", Common.theSign, found.Count); found = Result.Where(r => r.FromRule is TaxPayerValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is CorrectionValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is GoodsValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is TaxRateValidator).ToList(); CheckFound(found, ref row, 0); found = Result.Where(r => r.FromRule is ItemTaxValidator).ToList(); CheckFound(found, ref row, 0); row = 1; found = Result.Where(r => r.ProblemObject is A1).ToList(); if (found.Count > 0) AddProblem("A.1.", found.Count, "Problémové položky typu A1.", false, row++, 1); found = Result.Where(r => r.ProblemObject is A2).ToList(); if (found.Count > 0) AddProblem("A.2.", found.Count, "Problémové položky typu A2.", false, row++, 1); found = Result.Where(r => r.ProblemObject is B1).ToList(); if (found.Count > 0) AddProblem("B.1.", found.Count, "Problémové položky typu B1.", false, row++, 1); found = Result.Where(r => r.ProblemObject is B2).ToList(); if (found.Count > 0) AddProblem("B.2.", found.Count, "Problémové položky typu B2.", false, row++, 1); found = Result.Where(r => r.ProblemObject is B3).ToList(); if (found.Count > 0) AddProblem("B.3.", found.Count, "Problémové položky typu B3.", false, row++, 1); found = Result.Where(r => r.ProblemObject is C1).ToList(); if (found.Count > 0) AddProblem("C.1.", found.Count, "Problémové položky typu C1.", false, row++, 1); found = Result.Where(r => r.ProblemObject is C2).ToList(); if (found.Count > 0) AddProblem("C.2.", found.Count, "Problémové položky typu C2.", false, row++, 1); found = Result.Where(r => r.ProblemObject is D1).ToList(); if (found.Count > 0) AddProblem("D.1.", found.Count, "Problémové položky typu D1.", false, row++, 1); found = Result.Where(r => r.ProblemObject is D2).ToList(); if (found.Count > 0) AddProblem("D.2.", found.Count, "Problémové položky typu D2.", false, row++, 1); FinalizeResults(); }
public void SetProblems(IValidationResult problems) { this.problems = problems; ShowProblems(); }