Esempio n. 1
0
        public static async Task Populate_ASYNC_OpenCursor(ICrudDataStore store)
        {
            const int CNT = 1000;

            for (var i = 0; i < CNT; i++)
            {
                var patient = new TupleData
                {
                    COUNTER = i,
                    DATA    = i.ToString() + "-DATA"
                };
                store.Insert(patient);
            }

            var query  = new Query <TupleData>("CRUD.Queries.Tuple.LoadAll");
            var result = store.LoadOneRowset(query);

            Aver.AreEqual(CNT, result.Count);

            Aver.AreObjectsEqual(0, result[0]["COUNTER"].AsInt());
            Aver.AreObjectsEqual(CNT - 1, result[result.Count - 1]["COUNTER"].AsInt());

            var cursor = await store.OpenCursorAsync(query);

            Aver.IsFalse(cursor.Disposed);
            var cnt = 0;

            foreach (var row in cursor.AsEnumerableOf <TupleData>())
            {
                cnt++;
            }

            Aver.AreEqual(CNT, cnt);
            Aver.IsTrue(cursor.Disposed);  //foreach must have closed the cursor
        }
Esempio n. 2
0
        public static void Populate_OpenCursor(ICrudDataStore store)
        {
            const int CNT = 1000;

            for (var i = 0; i < CNT; i++)
            {
                var patient = new TupleData
                {
                    COUNTER = i,
                    DATA    = i.ToString() + "-DATA"
                };
                store.Insert(patient);
            }



            var query  = new Query <TupleData>("CRUD.Queries.Tuple.LoadAll");
            var result = store.LoadOneRowset(query);

            Aver.AreEqual(CNT, result.Count);

            Aver.AreObjectsEqual(0, result[0]["COUNTER"].AsInt());
            Aver.AreObjectsEqual(CNT - 1, result[result.Count - 1]["COUNTER"].AsInt());

            {
                using (var cursor = store.OpenCursor(query))
                {
                    Aver.IsFalse(cursor.Disposed);
                    var cnt = 0;
                    foreach (var row in cursor.AsEnumerableOf <TupleData>())
                    {
                        cnt++;
                    }

                    Aver.AreEqual(CNT, cnt);
                    Aver.IsTrue(cursor.Disposed); //foreach must have closed the cursor
                }
            }

            {
                var cursor = store.OpenCursor(query);

                Aver.IsFalse(cursor.Disposed);

                var cen = cursor.GetEnumerator();
                cen.MoveNext();
                Aver.IsNotNull(cen.Current);

                Console.WriteLine(cen.Current.Schema.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap));

                Aver.AreObjectsEqual(0, cen.Current["COUNTER"].AsInt());
                Aver.AreObjectsEqual("0-DATA", cen.Current["DATA"]);

                cen.MoveNext();
                Aver.IsNotNull(cen.Current);
                Aver.AreObjectsEqual(1, cen.Current["COUNTER"].AsInt());
                Aver.AreObjectsEqual("1-DATA", cen.Current["DATA"]);

                cen.MoveNext();
                Aver.IsNotNull(cen.Current);
                Aver.AreObjectsEqual(2, cen.Current["COUNTER"].AsInt());
                Aver.AreObjectsEqual("2-DATA", cen.Current["DATA"]);


                cursor.Dispose();
                Aver.IsTrue(cursor.Disposed);
            }

            {
                using (var cursor = store.OpenCursor(query))
                {
                    Aver.IsFalse(cursor.Disposed);
                    var cnt = 0;
                    foreach (var row in cursor.AsEnumerableOf <TupleData>())
                    {
                        cnt++;
                    }

                    Aver.AreEqual(CNT, cnt);
                    Aver.IsTrue(cursor.Disposed); //foreach must have closed the cursor
                    try
                    {
                        foreach (var row in cursor.AsEnumerableOf <TupleData>())
                        {
                            Aver.Fail("Must have failed");
                        }
                    }
                    catch
                    {
                    }
                }
            }

            {
                var cursor = store.OpenCursor(query);

                Aver.IsFalse(cursor.Disposed);

                var cen = cursor.GetEnumerator();
                cen.MoveNext();
                Aver.IsNotNull(cen.Current);
                Aver.AreObjectsEqual(0, cen.Current["COUNTER"].AsInt());

                try
                {
                    Aver.IsFalse(cursor.Disposed);

                    var cen2 = cursor.GetEnumerator();
                    Aver.Fail("This should not have heppened as cant iterate cursor the second time");
                }
                catch
                {
                }

                cursor.Dispose();
                Aver.IsTrue(cursor.Disposed);
            }
        }