using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using Developpez.Dotnet.Collections; using System.Diagnostics; namespace Developpez.Dotnet.Tests.Collections { [TestFixture] public class EnumerableExtensionsTests { byte[] bytes = new byte[] { 1, 10, 15, 20, 32, 255 }; int[] ints = new int[] { 1, 10, 15, 20, 32, 255 }; [Test] public void FormatAll_With_Format_And_Separator() { string expected = "1-A-F-14-20-FF"; string actual = bytes.FormatAll("{0:X}", "-"); Assert.AreEqual(expected, actual); } [Test] public void FormatAll_With_Format_Without_Separator() { string expected = "010a0f1420ff"; string actual = bytes.FormatAll("x2", null); Assert.AreEqual(expected, actual); } [Test] public void FormatAll_Without_Format_Without_Separator() { string expected = "110152032255"; string actual = bytes.FormatAll(null, null); Assert.AreEqual(expected, actual); } [Test] public void FormatAll_Without_Format_With_Separator() { string expected = "1-10-15-20-32-255"; string actual = bytes.FormatAll(null, "-"); Assert.AreEqual(expected, actual); } [Test] public void FormatAll_Delegate() { string expected = "1-A-F-14-20-FF"; string actual = bytes.FormatAll(b => Convert.ToString(b, 16).ToUpper(), "-"); Assert.AreEqual(expected, actual); } [Test(Description = "Vérifie le bon fonctionnement de la méthode IsNullOrEmpty(ICollection)")] public void Check_IsNullOrEmpty_ICollection() { List nullList = null; List emptyList = new List(); List notNullOrEmptyList = new List { 42 }; Assert.IsTrue(nullList.IsNullOrEmpty()); Assert.IsTrue(emptyList.IsNullOrEmpty()); Assert.IsFalse(notNullOrEmptyList.IsNullOrEmpty()); Array nullArray = null; Array emptyArray = Array.CreateInstance(typeof(int), 0); Array notNullOrEmptyArray = Array.CreateInstance(typeof(int), 1); Assert.IsTrue(nullArray.IsNullOrEmpty()); Assert.IsTrue(emptyArray.IsNullOrEmpty()); Assert.IsFalse(notNullOrEmptyArray.IsNullOrEmpty()); int[] nullArrayOfInt = null; int[] emptyArrayOfInt = new int[0]; int[] notNullOrEmptyArrayOfInt = new[] { 42 }; Assert.IsTrue(nullArrayOfInt.IsNullOrEmpty()); Assert.IsTrue(emptyArrayOfInt.IsNullOrEmpty()); Assert.IsFalse(notNullOrEmptyArrayOfInt.IsNullOrEmpty()); } [Test(Description = "Vérifie le fonctionnement de la méthode Shuffle. Note: ce test a une probabilité d'échec à cause de la nature aléatoire de la fonctionnalité testée")] public void Check_Shuffle() { List lst = new List(); for (int i = 0; i < 1500; i++) { lst.Add(i.ToString()); } List lst2 = new List(lst); lst2.Shuffle(); Assert.IsFalse(lst.SequenceEqual(lst2)); } [Test(Description = "Vérifie le fonctionnement de la méthode Swap")] public void Check_Swap() { List lst = new List { "hello", "world", "the", "sun", "is", "shining", "today" }; lst.Swap(0, 1); Assert.AreEqual(lst[0], "world"); Assert.AreEqual(lst[1], "hello"); } [Test(Description = "Vérifie le fonctionnement de la méthode ToCsvString")] public void Check_ToCsvString() { List lst1 = new List(); lst1.Add("Hello"); lst1.Add("World"); lst1.Add("!"); string csv1 = lst1.ToCsvString(","); Assert.AreEqual(csv1, "Hello,World,!"); List lst2 = new List(); lst2.Add(42); lst2.Add(7); lst2.Add(13); string csv2 = lst2.ToCsvString("|"); Assert.AreEqual(csv2, "42|7|13"); } [Test(Description = "Vérifie le fonctionnement de la méthode ListFromCsv")] public void Check_ListFromCsv_No_Null_Values() { string csv1 = "Hello,World,!"; var expected1 = new string[] { "Hello", "World", "!" }; var actual1 = csv1.ListFromCsv(","); Assert2.AreSequenceEqual(expected1, actual1); string csv2 = "42|7|13"; var expected2 = new int[] { 42, 7, 13 }; var actual2 = csv2.ListFromCsv("|"); Assert2.AreSequenceEqual(expected2, actual2); } [Test(Description = "Vérifie le fonctionnement de la méthode ListFromCsv")] public void Check_ListFromCsv_With_Null_Values() { string csv1 = "Hello,,!"; var expected1 = new string[] { "Hello", null, "!" }; var actual1 = csv1.ListFromCsv(","); Assert2.AreSequenceEqual(expected1, actual1); string csv2 = "42||13"; var expected2 = new int[] { 42, 0, 13 }; var actual2 = csv2.ListFromCsv("|"); Assert2.AreSequenceEqual(expected2, actual2); } [Test(Description = "Vérifie le fonctionnement de la méthode IsOrdered")] public void Check_IsOrdered() { List list = new List(); Assert.IsTrue(list.IsOrdered()); list.Add(5); Assert.IsTrue(list.IsOrdered()); list.Add(6); Assert.IsTrue(list.IsOrdered()); list.Add(3); Assert.IsFalse(list.IsOrdered()); list.Sort(); Assert.IsTrue(list.IsOrdered()); } [Test(Description = "Vérifie le fonctionnement de la méthode IsOrderedDescending")] public void Check_IsOrderedDescending_ForBaseClass() { List list = new List(); Assert.IsTrue(list.IsOrderedDescending()); list.Add(5); Assert.IsTrue(list.IsOrderedDescending()); list.Add(3); Assert.IsTrue(list.IsOrderedDescending()); list.Add(6); Assert.IsFalse(list.IsOrderedDescending()); list.Sort(Comparer.Default.Reverse()); Assert.IsTrue(list.IsOrderedDescending()); } [Test(Description = "Vérifie le fonctionnement de la méthode IsOrderedDescending avec Comparateur")] public void Check_IsOrderedDescending_ForCustomClass_WithComparer() { List list = new List(); Assert.IsTrue(list.IsOrderedDescending(new FooComparer())); list.Add(new Foo { Bar = "world" }); Assert.IsTrue(list.IsOrderedDescending(new FooComparer())); list.Add(new Foo { Bar = "prout" }); Assert.IsTrue(list.IsOrderedDescending(new FooComparer())); list.Add(new Foo { Bar = "hello" }); Assert.IsTrue(list.IsOrderedDescending(new FooComparer())); list.Sort(new FooComparer().Reverse()); Assert.IsTrue(list.IsOrderedDescending(new FooComparer())); } [Test(Description = "Vérifie le fonctionnement de la méthode IsOrderedDescending avec une classe implémentant IComparable")] public void Check_IsOrderedDescending_ForCustom_Icomparable_Class() { List list = new List(); Assert.IsTrue(list.IsOrderedDescending()); list.Add(new FooFoo { Bar = "world" }); Assert.IsTrue(list.IsOrderedDescending()); list.Add(new FooFoo { Bar = "prout" }); Assert.IsTrue(list.IsOrderedDescending()); list.Add(new FooFoo { Bar = "hello" }); Assert.IsTrue(list.IsOrderedDescending()); list.Sort(Comparer.Default.Reverse()); Assert.IsTrue(list.IsOrderedDescending()); } internal class Foo { internal string Bar { get; set; } } internal class FooFoo : IComparable { internal string Bar { get; set; } public int CompareTo(FooFoo other) { return this.Bar.CompareTo(other.Bar); } } internal class FooComparer : IComparer { public int Compare(Foo x, Foo y) { return x.Bar.CompareTo(y.Bar); } } [Test(Description = "Vérifie le fonctionnement de la méthode IsOrderedBy")] public void Check_IsOrderedBy() { List list = new List(); Assert.IsTrue(list.IsOrderedBy(f => f.Bar)); list.Add(new Foo { Bar = "hello" }); Assert.IsTrue(list.IsOrderedBy(f => f.Bar)); list.Add(new Foo { Bar = "world" }); Assert.IsTrue(list.IsOrderedBy(f => f.Bar)); list.Add(new Foo { Bar = "prout" }); Assert.IsFalse(list.IsOrderedBy(f => f.Bar)); list.Sort((x, y) => string.Compare(x.Bar, y.Bar)); Assert.IsTrue(list.IsOrderedBy(f => f.Bar)); } [Test(Description = "Vérifie le fonctionnement de la méthode IsOrderedByDescending")] public void Check_IsOrderedByDescending() { List list = new List(); Assert.IsTrue(list.IsOrderedByDescending(f => f.Bar)); list.Add(new Foo { Bar = "world" }); Assert.IsTrue(list.IsOrderedByDescending(f => f.Bar)); list.Add(new Foo { Bar = "hello" }); Assert.IsTrue(list.IsOrderedByDescending(f => f.Bar)); list.Add(new Foo { Bar = "prout" }); Assert.IsFalse(list.IsOrderedByDescending(f => f.Bar)); list.Sort((x, y) => string.Compare(y.Bar, x.Bar)); Assert.IsTrue(list.IsOrderedByDescending(f => f.Bar)); } #if !DOTNET4 [Test(Description = "Vérifie le fonctionnement de la méthode Zip")] public void Test_Zip() { var expected = new[] { new { Name = "Jack", Value = 4 }, new { Name = "Kate", Value = 8 }, new { Name = "Sayid", Value = 15 }, new { Name = "Sun", Value = 16 }, new { Name = "Sawyer", Value = 23 }, new { Name = "John", Value = 42 } }; // Cas 1 : même longueur var names = expected.Select(x => x.Name); var values = expected.Select(x => x.Value); var actual = names.Zip(values, (n, v) => new { Name = n, Value = v }); Assert2.AreSequenceEqual(expected, actual); // Cas 2 : names plus long que values names = expected.Select(x => x.Name); values = expected.Select(x => x.Value).Take(4); actual = names.Zip(values, (n, v) => new { Name = n, Value = v }); Assert2.AreSequenceEqual(expected.Take(4), actual); // Cas 3 : values plus long que names names = expected.Select(x => x.Name).Take(4); values = expected.Select(x => x.Value); actual = names.Zip(values, (n, v) => new { Name = n, Value = v }); Assert2.AreSequenceEqual(expected.Take(4), actual); } #endif [Test(Description = "Vérifie le comportement de la méthode FirstOrDefault, sans prédicat")] public void Test_FirstOrDefault_NoPredicate() { var lst = Enumerable.Empty(); string expected = "toto"; string actual = lst.FirstOrDefault("toto"); Assert.AreEqual(expected, actual); lst = new string[] { "hello", "world" }; expected = "hello"; actual = lst.FirstOrDefault("toto"); Assert.AreEqual(expected, actual); } [Test(Description = "Vérifie le comportement de la méthode FirstOrDefault, avec un prédicat")] public void Test_FirstOrDefault_WithPredicate() { var lst = new string[] { "hello", "world", "foo", "bar", "titi" }; string expected = "toto"; string actual = lst.FirstOrDefault(s => s[0] > 'x' ,"toto"); Assert.AreEqual(expected, actual); expected = "world"; actual = lst.FirstOrDefault(s => s[0] > 'n', "toto"); Assert.AreEqual(expected, actual); } [Test(Description = "Vérifie le comportement de la méthode LastOrDefault, sans prédicat")] public void Test_LastOrDefault_NoPredicate() { var lst = Enumerable.Empty(); string expected = "toto"; string actual = lst.LastOrDefault("toto"); Assert.AreEqual(expected, actual); lst = new string[] { "hello", "world" }; expected = "world"; actual = lst.LastOrDefault("toto"); Assert.AreEqual(expected, actual); } [Test(Description = "Vérifie le comportement de la méthode LastOrDefault, avec un prédicat")] public void Test_LastOrDefault_WithPredicate() { var lst = new string[] { "hello", "world", "foo", "bar", "titi" }; string expected = "toto"; string actual = lst.LastOrDefault(s => s[0] > 'x', "toto"); Assert.AreEqual(expected, actual); expected = "titi"; actual = lst.LastOrDefault(s => s[0] > 'n', "toto"); Assert.AreEqual(expected, actual); } [Test(Description = "Vérifie le comportement de la méthode ElementAtOrDefault")] public void Test_ElementAtOrDefault() { var lst = new string[] { "hello", "world" }; string expected = "toto"; string actual = lst.ElementAtOrDefault(2, "toto"); Assert.AreEqual(expected, actual); expected = "world"; actual = lst.ElementAtOrDefault(1, "toto"); Assert.AreEqual(expected, actual); } [Test(Description = "Vérifie le comportement de la méthode SingleOrDefault, sans prédicat")] public void Test_SingleOrDefault_NoPredicate() { var lst = Enumerable.Empty(); string expected = "toto"; string actual = lst.SingleOrDefault("toto"); Assert.AreEqual(expected, actual); lst = new string[] { "hello" }; expected = "hello"; actual = lst.LastOrDefault("toto"); Assert.AreEqual(expected, actual); lst = new string[] { "hello", "world" }; Assert2.Throws( () => lst.SingleOrDefault("toto")); } [Test(Description = "Vérifie le comportement de la méthode SingleOrDefault, avec un prédicat")] public void Test_SingleOrDefault_WithPredicate() { var lst = new string[] { "hello", "world", "foo", "bar", "titi" }; string expected = "toto"; string actual = lst.SingleOrDefault(s => s[0] > 'x', "toto"); Assert.AreEqual(expected, actual); expected = "titi"; actual = lst.SingleOrDefault(s => s.Length == 4, "toto"); Assert.AreEqual(expected, actual); Assert2.Throws( () => lst.SingleOrDefault(s => s[0] > 'n', "toto")); } [Test] public void Test_BinarySearch() { IList list = GetFoos(); foreach (var item in list) { var foundItem = list.BinarySearch(f => f.Bar, item.Bar); Assert.AreEqual(item, foundItem); } Assert2.Throws( () => list.BinarySearch(f => f.Bar, "joe")); } [Test] public void Test_BinarySearchOrDefault() { IList list = GetFoos(); var defaultFoo = new Foo { Bar = "joe" }; foreach (var item in list) { var foundItem = list.BinarySearchOrDefault(f => f.Bar, item.Bar); Assert.AreEqual(item, foundItem); foundItem = list.BinarySearchOrDefault(f => f.Bar, item.Bar, defaultFoo); Assert.AreEqual(item, foundItem); } Foo expected = null; var actual = list.BinarySearchOrDefault(f => f.Bar, defaultFoo.Bar); Assert.AreEqual(expected, actual); expected = defaultFoo; actual = list.BinarySearchOrDefault(f => f.Bar, defaultFoo.Bar, defaultFoo); Assert.AreEqual(expected, actual); } [Test] public void Test_TryBinarySearch() { IList list = GetFoos(); var defaultFoo = new Foo { Bar = "joe" }; foreach (var item in list) { Foo foundItem; var found = list.TryBinarySearch(f => f.Bar, item.Bar, out foundItem); Assert.IsTrue(found); Assert.AreEqual(item, foundItem); } bool expected = false; Foo expectedItem = null; Foo actualItem = null; bool actual = list.TryBinarySearch(f => f.Bar, defaultFoo.Bar, out actualItem); Assert.AreEqual(expected, actual); Assert.AreEqual(expectedItem, actualItem); } [Test] public void Test_WithMax() { var foos = GetFoos(); foos.Shuffle(); var fooWithMaxBar = foos.WithMax(f => f.Bar); var expected = "xyz"; var actual = fooWithMaxBar.Bar; Assert.AreEqual(expected, actual); } [Test] public void Test_WithMin() { var foos = GetFoos(); foos.Shuffle(); var fooWithMinBar = foos.WithMin(f => f.Bar); var expected = "abcd"; var actual = fooWithMinBar.Bar; Assert.AreEqual(expected, actual); } [Test] public void Test_QuickSort_Default() { Random rnd = new Random(); byte[] values = new byte[100]; rnd.NextBytes(values); values.QuickSort(); bool ordered = values.IsOrdered(); Assert.IsTrue(ordered); } [Test] public void Test_QuickSort_Comparison() { Random rnd = new Random(); byte[] values = new byte[100]; rnd.NextBytes(values); // Les nombres pairs en premier, puis triés par ordre décroissant Comparison comparison = (a, b) => { if (a % 2 == 0 && b % 2 == 1) return -1; else if (a % 2 == 1 && b % 2 == 0) return 1; else return -a.CompareTo(b); }; values.QuickSort(comparison); bool ordered = values.IsOrdered(comparison); Assert.IsTrue(ordered); } [Test] public void Test_QuickSortBy() { Random rnd = new Random(); byte[] values = new byte[100]; rnd.NextBytes(values); var foos = values.Select(x => new Foo { Bar = x.ToString() }).ToList(); foos.QuickSortBy(f => f.Bar); bool ordered = foos.IsOrderedBy(f => f.Bar); Assert.IsTrue(ordered); } [Test] public void Test_Append() { var foos = GetFoos(); var item = new Foo { Bar = "zzz" }; var expected = foos.ToList(); expected.Add(item); var actual = foos.Append(item); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_Prepend() { var foos = GetFoos(); var item = new Foo { Bar = "zzz" }; var expected = foos.ToList(); expected.Insert(0, item); var actual = foos.Prepend(item); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_AsIndexed_Unindex() { var foos = GetFoos(); var indexed = foos.AsIndexed().ToList(); for (int i = 0; i < indexed.Count; i++) { Assert.AreEqual(i, indexed[i].Index); } var unindexed = indexed.Unindex(); Assert2.AreSequenceEqual(foos, unindexed); } [Test] public void Test_GroupEvery() { var foos = GetFoos(); var grouped = foos.GroupEvery(3).ToList(); Assert.AreEqual(3, grouped.Count); Assert.AreEqual(3, grouped[0].Count()); Assert.AreEqual(3, grouped[1].Count()); Assert.AreEqual(1, grouped[2].Count()); } [Test] public void Test_TakeEvery() { var numbers = Enumerable.Range(0, 10); var expected = new[] { 2, 5, 8 }; var actual = numbers.TakeEvery(3, 2); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_SkipEvery() { var numbers = Enumerable.Range(0, 10); var expected = new[] { 0, 1, 3, 4, 6, 7, 9 }; var actual = numbers.SkipEvery(3, 2); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_SkipFirst() { var input = new[] { "foo", "bar", "baz", "bar" }; var expected = new[] { "foo", "baz", "bar" }; var actual = input.SkipFirst(s => s == "bar"); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_SkipLast() { var input = new[] { "foo", "bar", "baz", "bar", "zoo" }; var expected = new[] { "foo", "bar", "baz", "zoo" }; var actual = input.SkipLast(s => s == "bar"); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_SkipAt() { var input = new[] { "foo", "bar", "baz", "bar" }; var expected = new[] { "foo", "baz", "bar" }; var actual = input.SkipAt(1); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_ReplaceAt() { var input = new[] { "foo", "bar", "baz", "bar" }; var expected = new[] { "foo", "zoo", "baz", "bar" }; var actual = input.ReplaceAt(1, "zoo"); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_InsertAt() { var input = new[] { "foo", "baz", "bar" }; var expected = new[] { "foo", "zoo", "baz", "bar" }; var actual = input.InsertAt(1, "zoo"); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_None() { var empty = new int[0]; var notEmpty = new int[] { 42 }; Assert.IsTrue(empty.None()); Assert.IsFalse(notEmpty.None()); } [Test] public void Test_None_With_Predicate() { var allOdds = new int[] { 5, 15, 23 }; var oddsAndEvens = new int[] { 5, 8, 15, 16, 23, 42 }; Func isEven = n => n % 2 == 0; Assert.IsTrue(allOdds.None(isEven)); Assert.IsFalse(oddsAndEvens.None(isEven)); } [Test] public void Test_GetSegment() { var array = new int[] { 5, 8, 15, 16, 23, 42 }; var segment = array.GetSegment(); Assert.AreEqual(array, segment.Array); Assert.AreEqual(0, segment.Offset); Assert.AreEqual(array.Length, segment.Count); segment = array.GetSegment(2); Assert.AreEqual(array, segment.Array); Assert.AreEqual(2, segment.Offset); Assert.AreEqual(array.Length - 2, segment.Count); segment = array.GetSegment(2, 3); Assert.AreEqual(array, segment.Array); Assert.AreEqual(2, segment.Offset); Assert.AreEqual(3, segment.Count); } [Test] public void Test_Segment_AsEnumerable() { var array = new int[] { 5, 8, 15, 16, 23, 42 }; var segment = array.GetSegment(2, 3); var expected = array.Skip(2).Take(3); var actual = segment.AsEnumerable(); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_Segment_ToArray() { var array = new int[] { 5, 8, 15, 16, 23, 42 }; var segment = array.GetSegment(2, 3); var expected = array.Skip(2).Take(3).ToArray(); var actual = segment.ToArray(); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_ShiftLeft() { int[] array = new[] { 0, 4, 8, 15, 16, 23 }; int[] expected = new[] { 4, 8, 15, 16, 23, 42 }; int[] actual = array.ShiftLeft(42); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_ShiftRight() { int[] array = new[] { 8, 15, 16, 23, 42, 0 }; int[] expected = new[] { 4, 8, 15, 16, 23, 42 }; int[] actual = array.ShiftRight(4); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_RotateLeft() { int[] array = new[] { 42, 4, 8, 15, 16, 23 }; int[] expected = new[] { 4, 8, 15, 16, 23, 42 }; int[] actual = array.RotateLeft(); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_RotateRight() { int[] array = new[] { 8, 15, 16, 23, 42, 4 }; int[] expected = new[] { 4, 8, 15, 16, 23, 42 }; int[] actual = array.RotateRight(); Assert2.AreSequenceEqual(expected, actual); } [Test] public void Test_IndexOf_Item() { var source = Enumerable.Range(0, 10); int expected = 3; int actual = source.IndexOf(3); Assert.AreEqual(expected, actual); expected = -1; actual = source.IndexOf(42); Assert.AreEqual(expected, actual); } [Test] public void Test_IndexOf_Predicate() { var source = Enumerable.Range(0, 10); int expected = 3; int actual = source.IndexOf(x => x == 3); Assert.AreEqual(expected, actual); expected = -1; actual = source.IndexOf(x => x == 42); Assert.AreEqual(expected, actual); } [Test] public void Test_LastIndexOf_Item() { var source = Enumerable.Range(0, 10).Concat(Enumerable.Range(0, 10)); int expected = 13; int actual = source.LastIndexOf(3); Assert.AreEqual(expected, actual); expected = -1; actual = source.LastIndexOf(42); Assert.AreEqual(expected, actual); } [Test] public void Test_LastIndexOf_Predicate() { var source = Enumerable.Range(0, 10).Concat(Enumerable.Range(0, 10)); int expected = 13; int actual = source.LastIndexOf(x => x == 3); Assert.AreEqual(expected, actual); expected = -1; actual = source.LastIndexOf(x => x == 42); Assert.AreEqual(expected, actual); } [Test] public void Test_CopyTo() { var source = Enumerable.Range(1, 10); var array = new int[12]; source.CopyTo(array, 0); Assert2.AreSequenceEqual(source, array.Take(10)); source.CopyTo(array, 2); Assert2.AreSequenceEqual(source, array.Skip(2).Take(10)); Assert2.Throws( () => source.CopyTo(array, -1)); Assert2.Throws( () => source.CopyTo(array, 12)); Assert2.Throws( () => source.CopyTo(array, 3)); } [Test] public void Test_ContainsAny() { var list = new[] { 4, 8, 15, 16, 23, 42 }; var items1 = new[] { 15, 30, 40 }; var items2 = new[] { 1, 2, 3 }; Assert.IsTrue(list.ContainsAny(items1)); Assert.IsFalse(list.ContainsAny(items2)); } #region Test helpers private static IList GetFoos() { IList list = new List { new Foo { Bar = "abcd" }, new Foo { Bar = "efgh" }, new Foo { Bar = "ijkl" }, new Foo { Bar = "mnop" }, new Foo { Bar = "qrst" }, new Foo { Bar = "uvw" }, new Foo { Bar = "xyz" } }; return list; } #endregion } }