1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.Collections;
\r
6 using System.Collections.Generic;
\r
7 using Microsoft.VisualStudio.TestTools.UnitTesting;
\r
9 namespace Microsoft.Internal.Collections
\r
11 public static class EnumerableExtensions
\r
13 public static int Count(this IEnumerable source)
\r
17 foreach (object o in source)
\r
25 public static IEnumerable<T> ToEnumerable<T>(this IEnumerable source)
\r
27 foreach (object value in source)
\r
29 yield return (T)value;
\r
33 public static List<object> ToList(this IEnumerable source)
\r
35 var enumerable = source.ToEnumerable<object>();
\r
37 return System.Linq.Enumerable.ToList(enumerable);
\r
40 public static T AssertSingle<T>(this IEnumerable<T> source)
\r
42 return AssertSingle(source, t => true);
\r
45 public static T AssertSingle<T>(this IEnumerable<T> source, string message)
\r
47 return AssertSingle(source, t => true, message);
\r
50 public static T AssertSingle<T>(this IEnumerable<T> source, Func<T, bool> predicate)
\r
52 return AssertSingle(source, predicate, "Expecting a single item matching the predicate in the collection.");
\r
55 public static T AssertSingle<T>(this IEnumerable<T> source, Func<T, bool> predicate, string message)
\r
59 foreach (T t in source)
\r
68 Assert.AreEqual(1, count, message);
\r