Beispiel #1
0
        public void Paginate()
        {
            var list = RecipesList.Paginate(new ClientMock(MockResponse.RecipesList));

            var listClient = list.records.RecordClient;

            Assert.AreEqual(list.records.RecordEndpoint, "ingest_recipes");

            foreach (var item in list.Page)
            {
                Assert.AreEqual(item.record.RecordEndpoint, "ingest_recipes");
            }

            var per_page = "1";
            var query    = new Dictionary <string, string>()
            {
                { "per_page", per_page }
            };

            var list2 = RecipesList.Paginate(query, new ClientMock(MockResponse.RecipesList));

            var countItem = 0;

            foreach (var item in list2.Page)
            {
                countItem++;
            }

            Assert.AreEqual(countItem.ToString(), per_page);

            list = RecipesList.Paginate(new ClientMock(MockResponse.RecordPaginate));

            Assert.IsTrue(list.Next());
            Assert.IsTrue(list.Prevous());
            Assert.IsTrue(list.First());
            Assert.IsTrue(list.Last());

            list = RecipesList.Paginate(new ClientMock(MockResponse.RecordPaginateEmpty));

            Assert.IsFalse(list.Next());
            Assert.IsFalse(list.Prevous());
            Assert.IsFalse(list.First());
            Assert.IsFalse(list.Last());
        }
Beispiel #2
0
        public static void ReadingIngestRecipesList(string id, string token)
        {
            try {
                Console.WriteLine("--EachItem()--");
                foreach (Recipe item in RecipesList.EachItem())
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }

                Console.WriteLine("--EachItem(query)--");

                Dictionary <string, string> query = new Dictionary <string, string>()
                {
                    { "sort", "id" },
                    { "order", "desc" },
                    { "per_page", "2" }
                };

                Client client = new Client()
                {
                    CfgClientId = id, CfgAuthToken = token
                };
                foreach (var item in RecipesList.EachItem(query, client))
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }

                Console.WriteLine("--Paginate--");

                var items1 = RecipesList.Paginate();
                foreach (var item in items1.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }

                Console.WriteLine("--Paginate(query)--");

                var items2 = RecipesList.Paginate(query, new Client());

                Console.WriteLine("--Paginate(query)--Initial-First--");
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }

                while (items2.Next())
                {
                    Console.WriteLine("--Paginate(query)--Next--");

                    foreach (var item in items2.Page)
                    {
                        Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                    }
                }

                Console.WriteLine("--Paginate(query)--Previous--");
                items2.Prevous();
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }

                Console.WriteLine("--Paginate(query)--Last--");
                items2.Last();
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }

                Console.WriteLine("--Paginate(query)--First--");
                items2.First();
                foreach (var item in items2.Page)
                {
                    Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]);
                }
            } catch (VzaarApiException ve) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(ve.Message);
            } catch (Exception e) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(e.Message);

                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            Console.WriteLine(fe.Message);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void RecordsListValidation()
        {
            var expected = "Missing 'data' token";

            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingData));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "'data' value is not array";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.DataNotArray));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "Missing 'meta' token";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingMeta));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "Missing 'links' token";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingLinks));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "Missing 'next' token";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingNext));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "Missing 'previous' token";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingPrevious));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "Missing 'last' token";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingLast));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }

            expected = "Missing 'first' token";
            try {
                var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingFirst));

                //if the exception is not thrown, the below assert fails
                bool assert = true;
                Assert.IsFalse(assert);
            } catch (VzaarApiException ve) {
                StringAssert.Contains(expected, ve.Message);
            } catch (Exception e) {
                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            StringAssert.Contains(expected, fe.Message);
                        }
                    }
                }
            }
        }        // end