public static void CommonGetListStartReferenceTestBody <T>(this BaseTest test, Func <int> maxLimitSelector, Func <int, List <T> > fullListSelector, Func <int?, int?, string, T[]> listSelector, Func <T, string> tokenSelector, Action <IEnumerable <T>, IEnumerable <T>, string, string> listComparisonAction, Func <T, T, StringBuilder, bool> itemComparison, string itemName, RunStepDelegate runStepDelegate, AssertDelegate assert) { int maxLimit = maxLimitSelector(); List <T> infos = fullListSelector(maxLimit); if (infos == null || infos.Count == 0) { return; } test.ValidateTokensInList(infos, tokenSelector, assert); int count = infos.Count; // one last item if (count > 1) { T[] shortList = listSelector(maxLimit, count - 1, string.Format("Get {0} list with offset = {1}", itemName, count - 1)); test.CheckRequestedInfo <T>(shortList, infos[count - 1], tokenSelector, itemComparison, itemName, assert); } // first "maxLimit" items { List <T> expected = infos.Take(maxLimit).ToList(); T[] actual = listSelector(maxLimit, 0, string.Format("Get {0} list with offset = 0", itemName)); test.ValidateTokensInList(actual, tokenSelector, assert); listComparisonAction(expected, actual, string.Format("of first {0} {1}", maxLimit, itemName), "received when passing offset=0"); } if (count > 2) { int offset = count / 2; // 3 => 1, 4 => 2, 5 => 2, 6 => 3 System.Diagnostics.Debug.WriteLine(string.Format("Get {0} with offset = {1}", itemName, offset)); // expected list T[] infosArray = infos.ToArray(); int cnt = Math.Min(maxLimit, count - offset); T[] expected = new T[cnt]; Array.Copy(infosArray, offset, expected, 0, cnt); T[] actual = listSelector(maxLimit, offset, string.Format("Get {0} list with offset = {1}", itemName, offset)); test.ValidateTokensInList(actual, tokenSelector, assert); test.ValidateSubset(actual, expected, itemName, tokenSelector, itemComparison, assert); } }