/// <summary>
        /// Tests whether two collections contain the same elements and throws an exception if either collection contains an element not in the other collection.
        /// </summary>
        /// <param name="expected">
        /// The first collection to compare. This contains the elements the test expects.
        /// </param>
        /// <param name="actual">
        /// The second collection to compare. This is the collection produced by the code under test.
        /// </param>
        /// <exception cref="T:Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException">
        /// Thrown if an element was found in one of the collections but not the other.
        /// </exception>
        public static void AreEnumerablesEquivalent <TItem>(IEnumerable <TItem> expected, IEnumerable <TItem> actual)
        {
            if ((expected == null) != (actual == null))
            {
                Assert.Fail(
                    $"{nameof(CollectionAsserter.AreEnumerablesEquivalent)} failed. Cannot compare enumerables for equivalency as {nameof(expected)} or {nameof(actual)} provided is null.");
            }

            if (CollectionAsserter.Equals(expected, actual))
            {
                return;
            }

            var expectedList = expected.ToList();
            var actualList   = actual.ToList();

            if (expectedList.Count != actualList.Count)
            {
                Assert.Fail(
                    $"{nameof(CollectionAsserter.AreEnumerablesEquivalent)} failed. The number of elements are different.");
            }

            if (expectedList.Count == 0 || !FindMismatchedElement(
                    expectedList,
                    actualList,
                    out _,
                    out _,
                    out object mismatchedElement))
            {
                return;
            }

            Assert.Fail(
                $"{nameof(CollectionAsserter.AreEnumerablesEquivalent)} failed. The collections contain mismatched elements. {mismatchedElement ?? "Element was null."}");
        }
        private static bool CompareEnumerables <TType>(
            IEnumerable <TType> expected,
            IEnumerable <TType> actual,
            IComparer comparer,
            ref string reason)
        {
            if (comparer == null)
            {
                Assert.Fail($"Cannot compare enumerables as the {nameof(comparer)} provided is null.");
            }

            if (CollectionAsserter.Equals(expected, actual))
            {
                reason = "Both enumerables are the same reference.";
                return(true);
            }

            if (expected == null || actual == null)
            {
                return(false);
            }

            var expectedList = expected.ToList();
            var actualList   = actual.ToList();

            if (expectedList.Count != actualList.Count)
            {
                reason = "The number of elements are different.";
                return(false);
            }

            IEnumerator enumerator1 = expectedList.GetEnumerator();
            IEnumerator enumerator2 = actualList.GetEnumerator();
            int         num         = 0;

            while (enumerator1.MoveNext() && enumerator2.MoveNext())
            {
                if (comparer.Compare(enumerator1.Current, enumerator2.Current) != 0)
                {
                    return(false);
                }

                ++num;
            }

            reason = "Both enumerables contain the same elements.";
            return(true);
        }