RemoveBusinessRuleValidationResult() public méthode

Removes the business rule validation result.
The is null.
public RemoveBusinessRuleValidationResult ( IBusinessRuleValidationResult businessRuleValidationResult ) : void
businessRuleValidationResult IBusinessRuleValidationResult The business rule validation result.
Résultat void
        /// <summary>
        /// Synchronizes the current with the specified context. This means that the current contains will become the same as the
        /// specified context.
        /// </summary>
        /// <param name="validationContext">The validation context.</param>
        /// <param name="additionalValidationContext">The additional validation context.</param>
        /// <param name="onlyAddValidation">if set to <c>true</c>, validation is only added, not removed. This is great to build up summaries.</param>
        /// <returns>The list of changes.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        /// <exception cref="ArgumentNullException">The <paramref name="validationContext" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="validationContext" /> is <c>null</c>.</exception>
        public static List <ValidationContextChange> SynchronizeWithContext(this ValidationContext validationContext, IValidationContext additionalValidationContext, bool onlyAddValidation = false)
        {
            Argument.IsNotNull("validationContext", validationContext);
            Argument.IsNotNull("additionalValidationContext", additionalValidationContext);

            var changes = ValidationContextHelper.GetChanges(validationContext, additionalValidationContext);

            foreach (var change in changes)
            {
                var validationResultAsField        = change.ValidationResult as IFieldValidationResult;
                var validationResultAsBusinessRule = change.ValidationResult as IBusinessRuleValidationResult;

                switch (change.ChangeType)
                {
                case ValidationContextChangeType.Added:
                    if (validationResultAsField != null)
                    {
                        validationContext.AddFieldValidationResult(validationResultAsField);
                    }
                    else if (validationResultAsBusinessRule != null)
                    {
                        validationContext.AddBusinessRuleValidationResult(validationResultAsBusinessRule);
                    }
                    break;

                case ValidationContextChangeType.Removed:
                    if (!onlyAddValidation)
                    {
                        if (validationResultAsField != null)
                        {
                            validationContext.RemoveFieldValidationResult(validationResultAsField);
                        }
                        else if (validationResultAsBusinessRule != null)
                        {
                            validationContext.RemoveBusinessRuleValidationResult(validationResultAsBusinessRule);
                        }
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException("change.ChangeType");
                }
            }

            return(changes);
        }
            public void CorrectlyHandlesRemovalOfNonExistingValidationResult()
            {
                var validationContext = new ValidationContext();
                var businessRuleValidation = BusinessRuleValidationResult.CreateError("MyError");

                Assert.AreEqual(0, validationContext.GetBusinessRuleValidationCount());

                validationContext.RemoveBusinessRuleValidationResult(businessRuleValidation);

                Assert.AreEqual(0, validationContext.GetBusinessRuleValidationCount());
            }
            public void ThrowsArgumentNullExceptionForNullValidationResult()
            {
                var validationContext = new ValidationContext();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => validationContext.RemoveBusinessRuleValidationResult(null));
            }