public static void CommonGetListNoLimitTestBody <T>(this BaseTest test, Func <int> maxLimitSelector, GetListStepMethod <T> listSelector, Func <T, string> tokenSelector, string itemName, AssertDelegate assert) { // Get maxLimit int maxLimit = maxLimitSelector(); List <T> fullList = new List <T>(); List <string> gotByThisMoment = new List <string>(); string offset = null; while (true) { T[] nextPart = null; offset = listSelector(null, offset, out nextPart, string.Format("Get {0} list without limit and start reference ='{1}'", itemName, offset)); int count = nextPart == null ? 0 : nextPart.Length; assert(count <= maxLimit, string.Format("{0} {1}s returned when MaxLimit is {2}", count, itemName, maxLimit), "Check that limit is not exceeded", string.Empty); if (count > 0) { List <string> newTokens = nextPart.Select(tokenSelector).ToList(); test.ValidateNextPart(gotByThisMoment, newTokens, itemName, assert); gotByThisMoment.AddRange(newTokens); fullList.AddRange(nextPart); } if (string.IsNullOrEmpty(offset)) { break; } } }
public static void CommonGetListStartReferenceLimitTestBody <T>(this BaseTest test, Func <int> maxLimitSelector, GetListStepMethod <T> listSelector, Func <T, string> tokenSelector, Func <T, T, StringBuilder, bool> itemComparison, string itemName, RunStepDelegate runStepDelegate, AssertDelegate assert) { // Get maxLimit int maxLimit = maxLimitSelector(); Func <int, List <T> > getList = (limit) => { List <T> fullList = new List <T>(); List <string> gotByThisMoment = new List <string>(); string offset = null; while (true) { T[] nextPart = null; offset = listSelector(limit, offset, out nextPart, string.Format("Get {0} list with limit = {1} and start reference ='{2}'", itemName, limit, offset)); //assert(nextPart != null, string.Format("No {0}s returned", itemName), "Check that result is not null", string.Empty); int count = nextPart == null ? 0 : nextPart.Length; assert(count <= limit, string.Format("{0} {1}s returned when limit is {2}", count, itemName, limit), "Check that limit is not exceeded", string.Empty); if (count > 0) { List <string> newTokens = nextPart.Select(tokenSelector).ToList(); test.ValidateNextPart(gotByThisMoment, newTokens, itemName, assert); gotByThisMoment.AddRange(newTokens); fullList.AddRange(nextPart); } if (string.IsNullOrEmpty(offset)) { break; } } return(fullList); }; // get full list by maxLimit chunks List <T> gotByMaxLimit = getList(maxLimit); // get full list by 1 item List <T> gotByOne = getList(1); // check order // compare items //test.ValidateOrderedLists(gotByMaxLimit, gotByOne, itemName, tokenSelector, // string.Format("received with limit ={0}", maxLimit), "received with limit=1", // itemComparison, assert); if (maxLimit > 2) { int middle = maxLimit / 2 + 1; // 3=>2, 4=>3, 5=>3 List <T> gotByMiddle = getList(middle); // check order // compare items //test.ValidateOrderedLists(gotByOne, gotByMiddle, itemName, tokenSelector, // "received with limit=1", // string.Format("received with limit ={0}", middle), // itemComparison, assert); } }
public static void CommonGetListLimitTestBody <T>(this BaseTest test, Func <int> maxLimitSelector, Func <List <T> > fullListSelector, GetListStepMethod <T> listSelector, Func <T, string> tokenSelector, string itemName, AssertDelegate assert) { // Get max limit int maxLimit = maxLimitSelector(); // Get full list. Exit test, if no items of interest registered List <T> infos = fullListSelector(); if (infos == null || infos.Count == 0) { return; } test.ValidateTokensInList(infos, tokenSelector, assert); int count = infos.Count; // Get one item { T[] shortList = null; listSelector(1, null, out shortList, string.Format("Get {0} list with limit = 1", itemName)); assert(shortList != null, string.Format("No {0}s returned", itemName), "Check that result is not null", string.Empty); assert(shortList.Length <= 1, string.Format("{0} {1}s returned when limit is {2}", shortList.Length, itemName, 1), "Check that limit is not exceeded", string.Empty); } // maxLimit if (count > 1) { T[] actual = null; listSelector(maxLimit, null, out actual, string.Format("Get {0} list with limit = {1}", itemName, maxLimit)); assert(actual != null, string.Format("No {0}s returned", itemName), "Check that result is not null", string.Empty); assert(actual.Length <= maxLimit, string.Format("{0} {1}s returned when limit is {2}", actual.Length, itemName, maxLimit), "Check that limit is not exceeded", string.Empty); test.ValidateTokensInList(actual, tokenSelector, assert); } int cnt = Math.Min(count, maxLimit); int limit = cnt / 2 + 1; // 3 => 2, 4=> 3, 5=> 3, if (limit != maxLimit && limit != 1) { T[] infosArray = infos.ToArray(); System.Diagnostics.Debug.WriteLine(string.Format("Get {0} with limit = {1}", itemName, limit)); T[] expected = new T[limit]; Array.Copy(infosArray, 0, expected, 0, limit); T[] actual = null; listSelector(limit, null, out actual, string.Format("Get {0} list with limit = {1}", itemName, limit)); assert(actual != null, string.Format("No {0}s returned", itemName), "Check that result is not null", string.Empty); assert(actual.Length <= limit, string.Format("{0} {1}s returned when limit is {2}", actual.Length, itemName, limit), "Check that limit is not exceeded", string.Empty); test.ValidateTokensInList(actual, tokenSelector, assert); } }