コード例 #1
0
ファイル: Extensions.cs プロジェクト: kudrinyaroslav/ON-0110
 public static void InvalidTokenTestBody <T>(this BaseTest test,
                                             Func <string[], T[]> listSelector,
                                             RunStepDelegate runStepDelegate,
                                             string itemName)
 {
     InvalidTokenTestBody(test, listSelector, runStepDelegate, itemName, OnvifFaults.NotFound);
 }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: kudrinyaroslav/ON-0110
        public static void InvalidTokenTestBody <T>(this BaseTest test,
                                                    Func <string, T> method,
                                                    RunStepDelegate runStepDelegate,
                                                    string itemName,
                                                    string expectedFault)
        {
            string token = Guid.NewGuid().ToString().Substring(0, 8);

            runStepDelegate(() => { T info = method(token); },
                            string.Format("Get {0} with invalid token", itemName), expectedFault, true, false);
        }
コード例 #3
0
ファイル: Extensions.cs プロジェクト: kudrinyaroslav/ON-0110
        public static void InvalidTokenTestBody <T>(this BaseTest test,
                                                    Func <string[], T[]> listSelector,
                                                    RunStepDelegate runStepDelegate,
                                                    string itemName,
                                                    string expectedFault)
        {
            string token = Guid.NewGuid().ToString().Substring(0, 8);

            T[] infosList = null;
            runStepDelegate(() => { infosList = listSelector(new string[] { token }); },
                            string.Format("Get {0} with invalid token", itemName), expectedFault, true, false);
        }
コード例 #4
0
ファイル: CommonTests.cs プロジェクト: kudrinyaroslav/ON-0110
 public static void InvalidTokenTestBody <T>(this BaseTest test,
                                             Action <string, T> method,
                                             T parameter,
                                             RunStepDelegate runStepDelegate,
                                             string message,
                                             string token,
                                             string expectedFault)
 {
     token = token ?? Guid.NewGuid().ToString().Substring(0, 8);
     runStepDelegate(() => { method(token, parameter); },
                     message, expectedFault, true, false);
 }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: kudrinyaroslav/ON-0110
        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);
            }
        }
コード例 #6
0
ファイル: Extensions.cs プロジェクト: kudrinyaroslav/ON-0110
        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);
            }
        }
コード例 #7
0
ファイル: Extensions.cs プロジェクト: kudrinyaroslav/ON-0110
        public static void CommonGetListByTokenListTestBody <T>(this BaseTest test,
                                                                Func <int> maxLimitSelector,
                                                                Func <List <T> > fullListSelector,
                                                                Func <string[], T[]> listSelector,
                                                                Func <T, string> tokenSelector,
                                                                Action <IEnumerable <T>, IEnumerable <T>, string, string> listComparisonAction,
                                                                string itemName,
                                                                string itemInfoName,
                                                                RunStepDelegate runStepDelegate,
                                                                AssertDelegate assert)
        {
            List <T> infos = fullListSelector();

            if (infos == null || infos.Count == 0)
            {
                return;
            }

            ValidateTokensInList(test, infos, tokenSelector, assert);

            //
            int maxLimit = maxLimitSelector();

            List <string> tokens = new List <string>();

            foreach (T info in infos)
            {
                tokens.Add(tokenSelector(info));
            }

            List <T>      expected            = new List <T>();
            List <string> tokensForSubsetTest = new List <string>();

            // create list of randomly selected tokens.
            // create "expected" list
            {
                List <T> fullListCopy = new List <T>(infos);

                for (int i = 0; i < maxLimit; i++)
                {
                    Random rnd = new Random();
                    int    idx = rnd.Next(0, fullListCopy.Count - 1);
                    tokensForSubsetTest.Add(tokenSelector(fullListCopy[idx]));
                    expected.Add(fullListCopy[idx]);
                    fullListCopy.RemoveAt(idx);
                    if (fullListCopy.Count == 0)
                    {
                        break;
                    }
                }
            }

            // test for random subset
            T[] actual = listSelector(tokensForSubsetTest.ToArray());

            assert(actual != null && actual.Length > 0,
                   "Empty list returned", "Check that the list is not empty", "");

            ValidateTokensInList(test, actual, tokenSelector, assert);

            test.ValidateSubset(actual, expected, itemName, tokenSelector, null, assert);

            // Get by one

            foreach (string token in tokens)
            {
                T[] shortList = listSelector(new string[] { token });

                CheckRequestedInfo(test, shortList, token, tokenSelector, itemName, assert);
            }
        }