Esempio n. 1
0
        private static Assertable <T> SingleImpl <T, TT>(Assertable <TT> a, IReadOnlyList <T> sample)
            where TT : IEnumerable <T>
        {
            if (sample.Count == 0)
            {
                throw a.Exception("Collection is empty, expected exactly one item");
            }

            if (sample.Count > 1)
            {
                var coll = string.Join(", ", a.Item.Select(x => x.ToString()));
                throw a.Exception($"Collection has more than one element, expected exactly one item. Collection: \n{coll}");
            }

            return(new Assertable <T>(sample[0], a.UseAssertionException));
        }
Esempio n. 2
0
 public static Assertable <T> Null <T>(this Assertable <T> a)
 {
     if (a.Item != null)
     {
         throw a.Exception("Object is not null, Expected=null");
     }
     return(a);
 }
Esempio n. 3
0
 public static Assertable <T> True <T>(this Assertable <T> a, Func <T, bool> shouldBeTrue, string errorMsg)
 {
     if (!shouldBeTrue(a.Item))
     {
         throw a.Exception($"Condition '{errorMsg}' is false, Expected=true");
     }
     return(a);
 }
Esempio n. 4
0
        public static Assertable <T> NotEqual <T>(this Assertable <T> a, T notExpected)
        {
            if (object.Equals(a.Item, notExpected))
            {
                throw a.Exception($"Objects are equal: Actual({a.Item?.ToString()}) == Expected({notExpected?.ToString()})");
            }

            return(a);
        }
Esempio n. 5
0
        public static Assertable <T> Equal <T>(this Assertable <T> a, T expected)
        {
            if (!object.Equals(a.Item, expected))
            {
                throw a.Exception($"Objects are not equal: Actual({a.Item?.ToString()}) <> Expected({expected?.ToString()})");
            }

            return(a);
        }