/// <summary>
        /// Creates a new instance of the <see href="AssertActualExpectedException"/> class.
        /// </summary>
        /// <param name="expected">The expected value</param>
        /// <param name="actual">The actual value</param>
        /// <param name="userMessage">The user message to be shown</param>
        /// <param name="skipPositionCheck">Set to true to skip the check for difference position</param>
        public AssertActualExpectedException(object expected,
                                             object actual,
                                             string userMessage,
                                             bool skipPositionCheck)
            : base(userMessage)
        {
            if (!skipPositionCheck)
            {
                IEnumerable enumerableActual   = actual as IEnumerable;
                IEnumerable enumerableExpected = expected as IEnumerable;

                if (enumerableActual != null && enumerableExpected != null)
                {
                    var comparer = new EnumerableEqualityComparer();
                    comparer.Equals(enumerableActual, enumerableExpected);

                    differencePosition = "Position: First difference is at position " + comparer.Position + Environment.NewLine;
                }
            }

            this.actual   = actual == null ? null : ConvertToString(actual);
            this.expected = expected == null ? null : ConvertToString(expected);

            if (actual != null &&
                expected != null &&
                actual.ToString() == expected.ToString() &&
                actual.GetType() != expected.GetType())
            {
                this.actual   += String.Format(" ({0})", actual.GetType().FullName);
                this.expected += String.Format(" ({0})", expected.GetType().FullName);
            }
        }
        /// <summary>
        /// Creates a new instance of the <see href="AssertActualExpectedException"/> class.
        /// </summary>
        /// <param name="expected">The expected value</param>
        /// <param name="actual">The actual value</param>
        /// <param name="userMessage">The user message to be shown</param>
        /// <param name="skipPositionCheck">Set to true to skip the check for difference position</param>
        public AssertActualExpectedException(object expected,
                                             object actual,
                                             string userMessage,
                                             bool skipPositionCheck)
            : base(userMessage)
        {
            if (!skipPositionCheck)
            {
                IEnumerable enumerableActual = actual as IEnumerable;
                IEnumerable enumerableExpected = expected as IEnumerable;

                if (enumerableActual != null && enumerableExpected != null)
                {
                    var comparer = new EnumerableEqualityComparer();
                    comparer.Equals(enumerableActual, enumerableExpected);

                    differencePosition = "Position: First difference is at position " + comparer.Position + Environment.NewLine;
                }
            }

            this.actual = actual == null ? null : ConvertToString(actual);
            this.expected = expected == null ? null : ConvertToString(expected);

            if (actual != null &&
                expected != null &&
                actual.ToString() == expected.ToString() &&
                actual.GetType() != expected.GetType())
            {
                this.actual += String.Format(" ({0})", actual.GetType().FullName);
                this.expected += String.Format(" ({0})", expected.GetType().FullName);
            }
        }
        public static void Equals___Should_return_true___When_enumerableEqualityComparerStrategy_is_SequenceEqual_and_item1_and_item2_are_null()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.SequenceEqual);

            // Act
            var actual = systemUnderTest.Equals(null, null);

            // Assert
            actual.Should().BeTrue();
        }
        public static void Equals___Should_return_true___When_enumerableEqualityComparerStrategy_is_SequenceEqual_and_item1_and_item2_are_the_same_reference()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.SequenceEqual);
            var item            = new[] { "abc", null, "def" };

            // Act
            var actual = systemUnderTest.Equals(item, item);

            // Assert
            actual.Should().BeTrue();
        }
        public static void Equals___Should_return_false___When_enumerableEqualityComparerStrategy_is_SequenceEqual_and_item1_is_not_null_and_item2_is_null()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.SequenceEqual);
            var item1           = Some.ReadOnlyDummies <string>();

            // Act
            var actual = systemUnderTest.Equals(item1, null);

            // Assert
            actual.Should().BeFalse();
        }
        public static void Equals___Should_return_true___When_enumerableEqualityComparerStrategy_is_UnorderedEqual_and_item1_and_item2_are_empty()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.UnorderedEqual);
            var item1           = new string[0];
            var item2           = new string[0];

            // Act
            var actual = systemUnderTest.Equals(item1, item2);

            // Assert
            actual.Should().BeTrue();
        }
        public static void Equals___Should_return_false___When_enumerableEqualityComparerStrategy_is_UnorderedEqual_and_item1_and_item2_are_not_null_and_not_equal()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.UnorderedEqual);

            var item1 = new[] { "abc", "def", "ghi" };
            var item2 = new[] { "abc", "def", "ghi", "abc" };

            // Act
            var actual = systemUnderTest.Equals(item1, item2);

            // Assert
            actual.Should().BeFalse();
        }
예제 #8
0
        public static bool CollectionEquals <T>(this ICollection <T> left, ICollection <T> right, IEqualityComparer <T> equalityComparer = null)
        {
            equalityComparer ??= EqualityComparer <T> .Default;

            if (left is null)
            {
                return(right is null);
            }
            else if (right is null)
            {
                return(false);
            }

            return(left.Count == right.Count && EnumerableEqualityComparer <T> .CreateInstance(equalityComparer).Equals(left, right));
        }
예제 #9
0
        public static bool ArrayEquals <T>(this T[] left, T[] right, IEqualityComparer <T> equalityComparer = null)
        {
            equalityComparer ??= EqualityComparer <T> .Default;

            if (left is null)
            {
                return(right is null);
            }
            else if (right is null)
            {
                return(false);
            }

            return(left.LongLength == right.LongLength && EnumerableEqualityComparer <T> .CreateInstance(equalityComparer).Equals(left, right));
        }
        public static void Equals___Should_return_false___When_enumerableEqualityComparerStrategy_is_SequenceEqual_and_item1_and_item2_are_not_null_and_not_equal()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.SequenceEqual);

            var item1a = Some.ReadOnlyDummies <string>(3);
            var item1b = Some.ReadOnlyDummies <string>(3);

            var item2a = new[] { "abc", null, "def" };
            var item2b = new[] { "def", null, "abc" };

            // Act
            var actual1 = systemUnderTest.Equals(item1a, item1b);
            var actual2 = systemUnderTest.Equals(item2a, item2b);

            // Assert
            actual1.Should().BeFalse();
            actual2.Should().BeFalse();
        }
        public static void Equals___Should_return_true___When_enumerableEqualityComparerStrategy_is_UnorderedEqual_and_item1_and_item2_are_not_null_and_equal()
        {
            // Arrange
            var systemUnderTest = new EnumerableEqualityComparer <string>(EnumerableEqualityComparerStrategy.UnorderedEqual);

            var item1a = new[] { "abc", null, "def" };
            var item1b = new[] { "def", "abc", null };

            var item2a = new[] { "abc", null, "def", "abc", "ghi", null };
            var item2b = new[] { null, "ghi", null, "abc", "def", "abc" };

            // Act
            var actual1 = systemUnderTest.Equals(item1a, item1b);
            var actual2 = systemUnderTest.Equals(item2a, item2b);

            // Assert
            actual1.Should().BeTrue();
            actual2.Should().BeTrue();
        }
예제 #12
0
 public static int EnumerableGetHashCode <T>(this IEnumerable <T> enumerable, IEqualityComparer <T> equalityComparer)
 => EnumerableEqualityComparer <T> .CreateInstance(equalityComparer).GetHashCode(enumerable);
예제 #13
0
 public static bool EnumerableEquals <T>(this IEnumerable <T> left, IEnumerable <T> right, IEqualityComparer <T> equalityComparer)
 => EnumerableEqualityComparer <T> .CreateInstance(equalityComparer).Equals(left, right);
예제 #14
0
        protected AssertActualExpectedException(object expected,
                                             object actual,
                                             string userMessage,
                                             bool skipPositionCheck = false)
            : base(userMessage)
        {
            if (!skipPositionCheck)
            {
                var enumerableActual = actual as IEnumerable;
                var enumerableExpected = expected as IEnumerable;

                if (enumerableActual != null && enumerableExpected != null)
                {
                    var comparer = new EnumerableEqualityComparer();
                    comparer.Equals(enumerableActual, enumerableExpected);

                    differencePosition = "Position: First difference is at position " + comparer.Position + Environment.NewLine;
                }
            }

            Actual = actual == null ? null : ConvertToString(actual);
            Expected = expected == null ? null : ConvertToString(expected);

            if (actual == null || expected == null || actual.ToString() != expected.ToString() ||
                actual.GetType() == expected.GetType()) return;
            Actual += $" ({actual.GetType().FullName})";
            Expected += $" ({expected.GetType().FullName})";
        }
 public void SetupListMultiplicator()
 {
     this.SetDependency <IListMultiplicator>(new ListMultiplicator());
     this.Comparer = new EnumerableEqualityComparer <int>();
 }