/// <summary> /// Compares the number of elements in the two collections, if possible. /// </summary> /// <param name="x">The first collection.</param> /// <param name="y">The second collection.</param> /// <returns><see langword="true"/> when the collections have a mismatching /// number of elements; otherwise, <see langword="false"/>.</returns> private static bool HaveMismatchingCounts([NoEnumeration] IEnumerable <T> x, [NoEnumeration] IEnumerable <T> y) { #region Contract Debug.Assert(x != null); Debug.Assert(y != null); #endregion var xcount = Enumerables.TryGetCount(x); var ycount = Enumerables.TryGetCount(y); return(xcount != null && ycount != null && xcount != ycount); }
public void ShouldThrowArgumentNullException_WhenEnumerableIsNull() { // Arrange IReadOnlyCollection <String> enumerable = null; // Act var exception = Record.Exception(() => { Enumerables.TryGetCount(enumerable); }); // Assert Assert.IsType <ArgumentNullException>(exception); }
public void ShouldThrowException_WhenSecondSequenceIsLonger() { // Arrange var first = new[] { "a", "b", "c" }; var second = new[] { 1, 2, 3, 4, 5 }; // Act var exception = Record.Exception(() => { // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Enumerables.ZipEqual(first, second, (l, r) => l + r).ToArray(); }); // Assert Assert.IsAssignableFrom <InvalidOperationException>(exception); }