コード例 #1
0
        public static void IfCollectionsAreNotEquivalent <T>(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)]
            IEnumerable <T> collection1,
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)]
            IEnumerable <T> collection2,
            Violation message
            )
        {
            Fail.IfArgumentNull(collection1, nameof(collection1));
            Fail.IfArgumentNull(collection2, nameof(collection2));

            IEnumerable <T> list1 = collection1 as IList <T> ?? collection1.ToList();
            IEnumerable <T> list2 = collection2 as IList <T> ?? collection2.ToList();

            int collection1Count = list1.Count();
            int collection2Count = list2.Count();

            if (collection1Count != collection2Count)
            {
                throw Fail.Because(message);
            }

            bool areEquivalent = list1.Intersect(list2)
                                 .Count() == collection1Count;

            Fail.IfFalse(areEquivalent, message);
        }