/// <summary> /// Verifies that all elements in the specified collection are instances of the specified type. The assertion /// fails if there exists one element in the collection for which the specified type is not found in its /// inheritance hierarchy. /// </summary> public static void AllItemsAreInstancesOfType(ICollection collection, Type expectedType, string message = null, params object[] parameters) { if (collection == null) { throw new NullTestArgumentException("collection"); } if (expectedType == null) { throw new NullTestArgumentException("expectedType"); } int index = 0; foreach (object item in collection) { if (item == null) { throw new AssertFailedException("Element at index {0} is (null). Expected type: <{1}>.".Format(index, expectedType.FullName), message, parameters); } if (!Assert.CheckIsInstanceOfType(item, expectedType)) { throw new AssertFailedException( "Element at index {0} is not of expecteds type. Expected type: {1}. Actual type: {2}.".FormatValues(index, expectedType.FullName, item.GetType().FullName), message, parameters); } index++; } }