Esempio n. 1
0
 public void TestFetchLimitASync()
 {
     Task.Run(async() =>
     {
         for (var i = 0; i < 5; i++)
         {
             var item = new NCMBObject("QueryTest");
             item.Set("message", "Test message");
             item.Set("number", 500 + i);
             await item.Save();
         }
         var query = new NCMBQuery("QueryTest");
         query.EqualTo("message", "Test message");
         var results = await query.FetchAll();
         Assert.AreEqual(results.Length, 5);
         query = new NCMBQuery("QueryTest");
         query.EqualTo("message", "Test message").Limit(2);
         results = await query.FetchAll();
         Assert.AreEqual(results.Length, 2);
         query   = new NCMBQuery("QueryTest");
         results = await query.FetchAll();
         foreach (var obj in results)
         {
             await obj.Delete();
         }
     }).GetAwaiter().GetResult();
 }
Esempio n. 2
0
        public void TestFetchPointerASync()
        {
            Task.Run(async() =>
            {
                var item1 = new NCMBObject("QueryTest");
                item1.Set("message", "Test message");
                item1.Set("number", 500);
                await item1.Save();

                var item2 = new NCMBObject("QueryTest");
                item2.Set("message", "Test message");
                item2.Set("number", 500);
                item2.Set("obj", item1);
                await item2.Save();

                var query = new NCMBQuery("QueryTest");
                query
                .EqualTo("objectId", item2.Get("objectId"))
                .Include("obj");
                var obj = await query.Fetch();
                Assert.AreEqual(obj.Get("objectId"), item2.Get("objectId"));
                Assert.AreEqual(((NCMBObject)obj.Get("obj")).Get("objectId"), item1.Get("objectId"));

                await obj.Delete();
                await item1.Delete();
            }).GetAwaiter().GetResult();
        }
Esempio n. 3
0
        public void TestFetchOr()
        {
            Task.Run(async() =>
            {
                for (var i = 0; i < 5; i++)
                {
                    var item = new NCMBObject("QueryTest");
                    item.Set("message", "Test message");
                    item.Set("number", i);
                    await item.Save();
                }

                var q1 = new NCMBQuery("QueryTest");
                var q2 = new NCMBQuery("QueryTest");

                q1.EqualTo("number", 0);
                q2.EqualTo("number", 1);
                var query = new NCMBQuery("QueryTest");
                query.Or(new NCMBQuery[2] {
                    q1, q2
                });
                var items = await query.FetchAll();

                Assert.AreEqual(2, items.Length);
                var num0 = items[0].Get("number") as JValue;
                var num1 = items[1].Get("number") as JValue;

                Assert.AreEqual(0, num0.ToObject <int>());
                Assert.AreEqual(1, num1.ToObject <int>());
                query = new NCMBQuery("QueryTest");
                items = await query.FetchAll();
                foreach (var item in items)
                {
                    await item.Delete();
                }
            }).GetAwaiter().GetResult();
        }