public static void ShouldContainOnly <T>(this IEnumerable <T> list, IEnumerable <T> items)
        {
            var source    = new List <T>(list);
            var noContain = new List <T>();
            var comparer  = new AssertComparer <T>();

            foreach (var item in items)
            {
                if (!source.Contains(item, comparer))
                {
                    noContain.Add(item);
                }
                else
                {
                    source.Remove(item);
                }
            }

            if (noContain.Any() || source.Any())
            {
                string message = string.Format(@"Should contain only: {0} 
entire list: {1}", items.EachToUsefulString(), list.EachToUsefulString());
                if (noContain.Any())
                {
                    message += "\ndoes not contain: " + noContain.EachToUsefulString();
                }
                if (source.Any())
                {
                    message += "\ndoes contain but shouldn't: " + source.EachToUsefulString();
                }

                throw new SpecificationException(message);
            }
        }
        public static void ShouldNotContain <T>(this IEnumerable <T> list, IEnumerable <T> items)
        {
            var contains = new List <T>();
            var comparer = new AssertComparer <T>();

            foreach (var item in items)
            {
                if (list.Contains(item, comparer))
                {
                    contains.Add(item);
                }
            }

            if (contains.Any())
            {
                throw new SpecificationException(string.Format(@"Should not contain: {0} 
entire list: {1}
does contain: {2}", items.EachToUsefulString(), list.EachToUsefulString(), contains.EachToUsefulString()));
            }
        }
Esempio n. 3
0
        public static void ShouldNotContain <T>(this IEnumerable <T> list, IEnumerable <T> items)
        {
            var comparer = new AssertComparer <T>();

            var listArray  = list.ToArray();
            var itemsArray = items.ToArray();

            var contains = itemsArray
                           .Where(x => listArray.Contains(x, comparer))
                           .ToList();

            if (contains.Any())
            {
                throw new SpecificationException(string.Format(
                                                     @"Should not contain: {0}" + Environment.NewLine +
                                                     "entire list: {1}" + Environment.NewLine +
                                                     "does contain: {2}",
                                                     itemsArray.EachToUsefulString(),
                                                     listArray.EachToUsefulString(),
                                                     contains.EachToUsefulString()));
            }
        }
Esempio n. 4
0
        public static void ShouldContain <T>(this IEnumerable <T> list, IEnumerable <T> items)
        {
            var noContain = new List <T>();
            var comparer  = new AssertComparer <T>();

            foreach (var item in items)
            {
                if (!list.Contains <T>(item, comparer))
                {
                    noContain.Add(item);
                }
            }

            if (noContain.Any())
            {
                throw new SpecificationException(string.Format(
                                                     @"Should contain: {0}" + Environment.NewLine +
                                                     "entire list: {1}" + Environment.NewLine +
                                                     "does not contain: {2}",
                                                     items.EachToUsefulString(),
                                                     list.EachToUsefulString(),
                                                     noContain.EachToUsefulString()));
            }
        }
Esempio n. 5
0
        static bool SafeEquals <T>(this T left, T right)
        {
            var comparer = new AssertComparer <T>();

            return(comparer.Compare(left, right) == 0);
        }