/// <summary> /// Verifies that the expected collection events are raised from the <see cref="ValidationResultCollection"/> /// when <see cref="ValidationResultCollection.ReplaceErrors"/> is called for a property. /// </summary> /// <param name="member">The property that errors are being replaced for</param> /// <param name="replacementResults">The results to use as the replacement errors for the property for the replacement.</param> /// <param name="errorsChangedMembers">The array of member names to expect errors changed events for.</param> private static void VerifyPropertyReplacementEvents(string member, IEnumerable <ValidationResult> replacementResults, string[] errorsChangedMembers) { int collectionChangedCount = 0; int hasErrorsChangedCount = 0; List <string> propertyErrorsChangedList = new List <string>(); Action collectionChanged = () => ++ collectionChangedCount; Action hasErrorsChanged = () => ++ hasErrorsChangedCount; Action <string> propertyErrorsChanged = propertyName => propertyErrorsChangedList.Add(propertyName); ValidationResultCollection collection = new TestValidationResultCollection(collectionChanged, hasErrorsChanged, propertyErrorsChanged); collection.ReplaceErrors(member, replacementResults); Assert.AreEqual <int>(1, collectionChangedCount, "CollectionChanged count for first replacement"); Assert.AreEqual <int>(1, hasErrorsChangedCount, "HasErrorsChanged count for first replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMembers.OrderBy(s => s)), "propertyErrorsChangedList for first replacement"); collection.Add(new ValidationResult("Error", new string[] { member })); collectionChangedCount = 0; hasErrorsChangedCount = 0; propertyErrorsChangedList.Clear(); collection.ReplaceErrors(member, replacementResults); Assert.AreEqual <int>(1, collectionChangedCount, "CollectionChanged count for second replacement"); Assert.AreEqual <int>(0, hasErrorsChangedCount, "HasErrorsChanged count for second replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMembers.OrderBy(s => s)), "propertyErrorsChangedList for second replacement"); }
public void ReplaceAllResultsWithNothing() { // This test differs from the other replacement tests enough that it doesn't use the same helper method string member = "Member"; string[] memberNames = new string[] { member }; string[] replacementNames = new string[] { member }; IEnumerable <ValidationResult> initialResults = new ValidationResult[] { new ValidationResult("Error", memberNames) }; IEnumerable <ValidationResult> replacementResults = Enumerable.Empty <ValidationResult>(); int collectionChangedCount = 0; int hasErrorsChangedCount = 0; List <string> propertyErrorsChangedList = new List <string>(); Action collectionChanged = () => ++ collectionChangedCount; Action hasErrorsChanged = () => ++ hasErrorsChangedCount; Action <string> propertyErrorsChanged = propertyName => propertyErrorsChangedList.Add(propertyName); ValidationResultCollection collection = new TestValidationResultCollection(collectionChanged, hasErrorsChanged, propertyErrorsChanged); collection.ReplaceErrors(initialResults); Assert.AreEqual <int>(1, collectionChangedCount, "CollectionChanged count for first replacement"); Assert.AreEqual <int>(1, hasErrorsChangedCount, "HasErrorsChanged count for first replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(replacementNames.OrderBy(s => s)), "propertyErrorsChangedList for first replacement"); collection.Add(new ValidationResult("Error", new string[] { member })); collectionChangedCount = 0; hasErrorsChangedCount = 0; propertyErrorsChangedList.Clear(); collection.ReplaceErrors(replacementResults); // Notice that HasErrors changes again because we no longer have any errors Assert.AreEqual <int>(1, collectionChangedCount, "CollectionChanged count for second replacement"); Assert.AreEqual <int>(1, hasErrorsChangedCount, "HasErrorsChanged count for second replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(replacementNames.OrderBy(s => s)), "propertyErrorsChangedList for second replacement"); }
/// <summary> /// Verifies that the expected collection events are raised from the <see cref="ValidationResultCollection"/> /// when <see cref="ValidationResultCollection.ReplaceErrors"/> is called for a property. /// </summary> /// <param name="member">The property that errors are being replaced for</param> /// <param name="replacementResults">The results to use as the replacement errors for the property for the replacement.</param> /// <param name="errorsChangedMembers">The array of member names to expect errors changed events for.</param> private static void VerifyPropertyReplacementEvents(string member, IEnumerable<ValidationResult> replacementResults, string[] errorsChangedMembers) { int collectionChangedCount = 0; int hasErrorsChangedCount = 0; List<string> propertyErrorsChangedList = new List<string>(); Action collectionChanged = () => ++collectionChangedCount; Action hasErrorsChanged = () => ++hasErrorsChangedCount; Action<string> propertyErrorsChanged = propertyName => propertyErrorsChangedList.Add(propertyName); ValidationResultCollection collection = new TestValidationResultCollection(collectionChanged, hasErrorsChanged, propertyErrorsChanged); collection.ReplaceErrors(member, replacementResults); Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for first replacement"); Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for first replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMembers.OrderBy(s => s)), "propertyErrorsChangedList for first replacement"); collection.Add(new ValidationResult("Error", new string[] { member })); collectionChangedCount = 0; hasErrorsChangedCount = 0; propertyErrorsChangedList.Clear(); collection.ReplaceErrors(member, replacementResults); Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for second replacement"); Assert.AreEqual<int>(0, hasErrorsChangedCount, "HasErrorsChanged count for second replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMembers.OrderBy(s => s)), "propertyErrorsChangedList for second replacement"); }
public void ReplaceAllResultsWithNothing() { // This test differs from the other replacement tests enough that it doesn't use the same helper method string member = "Member"; string[] memberNames = new string[] { member }; string[] replacementNames = new string[] { member }; IEnumerable<ValidationResult> initialResults = new ValidationResult[] { new ValidationResult("Error", memberNames) }; IEnumerable<ValidationResult> replacementResults = Enumerable.Empty<ValidationResult>(); int collectionChangedCount = 0; int hasErrorsChangedCount = 0; List<string> propertyErrorsChangedList = new List<string>(); Action collectionChanged = () => ++collectionChangedCount; Action hasErrorsChanged = () => ++hasErrorsChangedCount; Action<string> propertyErrorsChanged = propertyName => propertyErrorsChangedList.Add(propertyName); ValidationResultCollection collection = new TestValidationResultCollection(collectionChanged, hasErrorsChanged, propertyErrorsChanged); collection.ReplaceErrors(initialResults); Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for first replacement"); Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for first replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(replacementNames.OrderBy(s => s)), "propertyErrorsChangedList for first replacement"); collection.Add(new ValidationResult("Error", new string[] { member })); collectionChangedCount = 0; hasErrorsChangedCount = 0; propertyErrorsChangedList.Clear(); collection.ReplaceErrors(replacementResults); // Notice that HasErrors changes again because we no longer have any errors Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for second replacement"); Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for second replacement"); Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(replacementNames.OrderBy(s => s)), "propertyErrorsChangedList for second replacement"); }