Beispiel #1
0
        public static void IfCollectionContainsNull <T>(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] IEnumerable <T> collection,
            [NotNull] string collectionName) where T : class
        {
            Fail.RequiresCollectionName(collectionName);

            Fail.IfArgumentNull(collection, nameof(collection));
            Fail.IfTrue(collection.Contains(null), "Collection '{0}' contains null", collectionName);
        }
Beispiel #2
0
        public static void IfCollectionEmpty <T>(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] IEnumerable <T> collection,
            [NotNull] string collectionName)
        {
            Fail.RequiresCollectionName(collectionName);

            if (collection == null)
            {
                throw Fail.Because("Collection '{0}' should not be null but it is.", collectionName);
            }

            if (collection.Any() == false)
            {
                throw Fail.Because("Collection '{0}' should not be empty but it is.", collectionName);
            }
        }
Beispiel #3
0
        public static void IfCollectionContainsNull <T>(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)]
            IEnumerable <T> collection,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string collectionName
            )
            where T : class
        {
            Fail.RequiresCollectionName(collectionName);

            if (collection == null)
            {
                throw Fail.Because(Violation.WhenCollectionIsNull(collectionName));
            }

            if (collection.Contains(null))
            {
                throw Fail.Because(Violation.WhenCollectionContainsNull(collectionName));
            }
        }
Beispiel #4
0
        public static T OrFailIfCollectionEmpty <T>(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)]
            this T collection,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string collectionName
            )
            where T : IEnumerable
        {
            Fail.RequiresCollectionName(collectionName);

            if (collection == null)
            {
                throw Fail.Because(Violation.WhenCollectionIsNull(collectionName));
            }

            if (collection.IsEmpty())
            {
                throw Fail.Because(Violation.WhenCollectionIsEmpty(collectionName));
            }

            return(collection);
        }