private static void IsTrue(bool condition, string propertyName) { if (!condition) { var exception = new DataAssertionException(); exception.Add(propertyName); throw exception; } }
private static void UnorderedCollectionsAreEqual <T>(ICollection <T> expected, ICollection <T> actual, Action <T, T> test, string propertyName) { IsTrue(expected.Count == actual.Count, string.Format("{0}(count)", propertyName)); int successCount = 0; var matched = new bool[expected.Count]; for (int i = 0; i < expected.Count; i++) { successCount = 0; for (int j = 0; j < expected.Count; j++) { try { test(expected.ElementAt(i), actual.ElementAt(j)); successCount++; } catch (DataAssertionException) { } } if (successCount > 0) { matched[i] = true; } else { var e = new DataAssertionException(); e.Add(String.Format("{0}[{1}]", propertyName, i)); throw e; } } for (int i = 0; i < expected.Count; i++) { if (!matched[i]) { var e = new DataAssertionException(); e.Add(String.Format("{0}[{1}]", propertyName, i)); throw e; } } }