Ejemplo n.º 1
0
        public void MergeErrors()
        {
            ValidationErrors otherErrors = new ValidationErrors();
            const string     anotherKey  = "anotherKey";

            otherErrors.AddError(anotherKey, ErrorMessageTwo);
            otherErrors.AddError(GoodErrorKey, ErrorMessageTwo);


            IValidationErrors errors = new ValidationErrors();

            errors.AddError(GoodErrorKey, ErrorMessageOne);
            errors.MergeErrors(otherErrors);

            Assert.IsFalse(errors.IsEmpty);
            IList <ErrorMessage> mergedErrors = errors.GetErrors(GoodErrorKey);

            Assert.IsNotNull(mergedErrors);
            Assert.AreEqual(2, mergedErrors.Count);
            Assert.AreEqual(ErrorMessageOne, mergedErrors[0]);
            Assert.AreEqual(ErrorMessageTwo, mergedErrors[1]);

            IList <ErrorMessage> otherErrorsForKey = errors.GetErrors(anotherKey);

            Assert.IsNotNull(otherErrorsForKey);
            Assert.AreEqual(1, otherErrorsForKey.Count);
            Assert.AreEqual(ErrorMessageTwo, otherErrorsForKey[0]);
        }
Ejemplo n.º 2
0
        public void MergeErrorsWithNull()
        {
            IValidationErrors errors = new ValidationErrors();

            errors.AddError(GoodErrorKey, ErrorMessageOne);
            errors.AddError(GoodErrorKey, ErrorMessageTwo);
            errors.MergeErrors(null);

            // must be unchanged with no Exception thrown...
            Assert.IsFalse(errors.IsEmpty);
            Assert.IsNotNull(errors.GetErrors(GoodErrorKey));
            Assert.AreEqual(2, errors.GetErrors(GoodErrorKey).Count);
        }