Exemplo n.º 1
0
        public async Task QueryFollowersAndFollowees()
        {
            await LCUser.BecomeWithSessionToken(user2.SessionToken);

            LCQuery <LCObject>            query   = user2.FolloweeQuery();
            ReadOnlyCollection <LCObject> results = await query.Find();

            Assert.Greater(results.Count, 0);
            foreach (LCObject item in results)
            {
                Assert.IsTrue(item["followee"] is LCObject);
                Assert.AreEqual(user1.ObjectId, (item["followee"] as LCObject).ObjectId);
            }

            query   = user2.FollowerQuery();
            results = await query.Find();

            Assert.Greater(results.Count, 0);
            foreach (LCObject item in results)
            {
                Assert.IsTrue(item["follower"] is LCObject);
                Assert.AreEqual(user3.ObjectId, (item["follower"] as LCObject).ObjectId);
            }

            LCFollowersAndFollowees followersAndFollowees = await user2.GetFollowersAndFollowees(true, true, true);

            Assert.AreEqual(followersAndFollowees.FollowersCount, 1);
            Assert.AreEqual(followersAndFollowees.FolloweesCount, 1);
        }
Exemplo n.º 2
0
        public static async Task <Dictionary <string, LCObject> > GetObjectMap()
        {
            LCQuery <LCObject>            query = new LCQuery <LCObject>("Todo");
            ReadOnlyCollection <LCObject> todos = await query.Find();

            return(todos.ToDictionary(t => t.ObjectId));
        }
Exemplo n.º 3
0
        public static async Task <ReadOnlyCollection <LCObject> > GetObjects()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereGreaterThan("balance", 100);
            return(await query.Find());
        }
Exemplo n.º 4
0
        public async Task String()
        {
            // Start
            LCQuery <LCObject> query = new LCQuery <LCObject>("Hello");

            query.WhereStartsWith("stringValue", "hello");
            List <LCObject> results = await query.Find();

            results.ForEach(item => {
                string str = item["stringValue"] as string;
                Assert.IsTrue(str.StartsWith("hello"));
            });

            // End
            query = new LCQuery <LCObject>("Hello");
            query.WhereEndsWith("stringValue", "world");
            results = await query.Find();

            results.ForEach(item => {
                string str = item["stringValue"] as string;
                Assert.IsTrue(str.EndsWith("world"));
            });

            // Contains
            query = new LCQuery <LCObject>("Hello");
            query.WhereContains("stringValue", ",");
            results = await query.Find();

            results.ForEach(item => {
                string str = item["stringValue"] as string;
                Assert.IsTrue(str.Contains(','));
            });
        }
Exemplo n.º 5
0
        public async Task Geo()
        {
            LCObject   obj      = new LCObject("Todo");
            LCGeoPoint location = new LCGeoPoint(39.9, 116.4);

            obj["location"] = location;
            await obj.Save();

            // near
            LCQuery <LCObject> query = new LCQuery <LCObject>("Todo");
            LCGeoPoint         point = new LCGeoPoint(39.91, 116.41);

            query.WhereNear("location", point);
            ReadOnlyCollection <LCObject> results = await query.Find();

            Assert.Greater(results.Count, 0);

            // in box
            query = new LCQuery <LCObject>("Todo");
            LCGeoPoint southwest = new LCGeoPoint(30, 115);
            LCGeoPoint northeast = new LCGeoPoint(40, 118);

            query.WhereWithinGeoBox("location", southwest, northeast);
            results = await query.Find();

            Assert.Greater(results.Count, 0);
        }
Exemplo n.º 6
0
        public async Task Query()
        {
            LCObject   geoObj = new LCObject("GeoObj");
            Random     random = new Random();
            LCGeoPoint p1     = new LCGeoPoint(-90 + random.NextDouble() * 180, -180 + random.NextDouble() * 360);

            geoObj["location"] = p1;
            await geoObj.Save();

            LCGeoPoint p2 = new LCGeoPoint(p1.Latitude + 0.01, p1.Longitude + 0.01);

            double km = p1.KilometersTo(p2);

            TestContext.WriteLine($"km: {km}, {Math.Ceiling(km)}");
            LCQuery <LCObject> query = new LCQuery <LCObject>("GeoObj");

            query.WhereWithinKilometers("location", p2, Math.Ceiling(km));
            Assert.Greater((await query.Find()).Count, 0);

            double miles = p1.MilesTo(p2);

            query = new LCQuery <LCObject>("GeoObj");
            query.WhereWithinMiles("location", p2, Math.Ceiling(miles));
            Assert.Greater((await query.Find()).Count, 0);

            double radians = p1.RadiansTo(p2);

            query = new LCQuery <LCObject>("GeoObj");
            query.WhereWithinRadians("location", p2, Math.Ceiling(radians));
            Assert.Greater((await query.Find()).Count, 0);
        }
Exemplo n.º 7
0
        public async Task BaseQuery()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Hello");

            query.Limit(2);
            ReadOnlyCollection <LCObject> list = await query.Find();

            TestContext.WriteLine(list.Count);
            Assert.AreEqual(list.Count, 2);

            foreach (LCObject item in list)
            {
                Assert.NotNull(item.ClassName);
                Assert.NotNull(item.ObjectId);
                Assert.NotNull(item.CreatedAt);
                Assert.NotNull(item.UpdatedAt);

                TestContext.WriteLine(item.ClassName);
                TestContext.WriteLine(item.ObjectId);
                TestContext.WriteLine(item.CreatedAt);
                TestContext.WriteLine(item.UpdatedAt);
                TestContext.WriteLine(item["intValue"]);
                TestContext.WriteLine(item["boolValue"]);
                TestContext.WriteLine(item["stringValue"]);
            }
        }
Exemplo n.º 8
0
        public async Task Array()
        {
            // equal
            LCQuery <LCObject> query = new LCQuery <LCObject>("Book");

            query.WhereEqualTo("pages", 3);
            List <LCObject> results = await query.Find();

            results.ForEach(item => {
                List <object> pages = item["pages"] as List <object>;
                Assert.IsTrue(pages.Contains(3));
            });

            // contain all
            List <int> containAlls = new List <int> {
                1, 2, 3, 4, 5, 6, 7
            };

            query = new LCQuery <LCObject>("Book");
            query.WhereContainsAll("pages", containAlls);
            results = await query.Find();

            results.ForEach(item => {
                List <object> pages = item["pages"] as List <object>;
                pages.ForEach(i => {
                    Assert.IsTrue(pages.Contains(i));
                });
            });

            // contain in
            List <int> containIns = new List <int> {
                4, 5, 6
            };

            query = new LCQuery <LCObject>("Book");
            query.WhereContainedIn("pages", containIns);
            results = await query.Find();

            results.ForEach(item => {
                List <object> pages = item["pages"] as List <object>;
                bool f = false;
                containIns.ForEach(i => {
                    f |= pages.Contains(i);
                });
                Assert.IsTrue(f);
            });

            // size
            query = new LCQuery <LCObject>("Book");
            query.WhereSizeEqualTo("pages", 7);
            results = await query.Find();

            results.ForEach(item => {
                List <object> pages = item["pages"] as List <object>;
                Assert.AreEqual(pages.Count, 7);
            });
        }
Exemplo n.º 9
0
        public async Task GreaterQuery()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereGreaterThan("balance", 200);
            ReadOnlyCollection <LCObject> list = await query.Find();

            TestContext.WriteLine(list.Count);
            Assert.Greater(list.Count, 0);
        }
Exemplo n.º 10
0
        async Task <ReadOnlyCollection <LCObject> > GetFriends()
        {
            LCUser user = await LCUser.GetCurrent();

            LCQuery <LCObject> query = new LCQuery <LCObject>("_Followee")
                                       .WhereEqualTo("user", user)
                                       .WhereEqualTo("friendStatus", true);

            return(await query.Find());
        }
Exemplo n.º 11
0
    async Task Query()
    {
        LCQuery <LCObject> query = new LCQuery <LCObject>("Hello");

        query.Limit(2);
        List <LCObject> list = await query.Find();

        foreach (LCObject obj in list)
        {
            Debug.Log($"object id: {obj.ObjectId}");
        }
    }
Exemplo n.º 12
0
        public async Task Select()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.Select("balance");
            List <LCObject> results = await query.Find();

            results.ForEach(item => {
                Assert.NotNull(item["balance"]);
                Assert.IsNull(item["user"]);
            });
        }
Exemplo n.º 13
0
        public async Task Select()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.Select("balance");
            ReadOnlyCollection <LCObject> results = await query.Find();

            foreach (LCObject item in results)
            {
                Assert.NotNull(item["balance"]);
                Assert.IsNull(item["user"]);
            }
        }
Exemplo n.º 14
0
        public async Task FetchAll()
        {
            LCQuery <LCObject>     query = new LCQuery <LCObject>("Hello");
            IEnumerable <string>   ids   = (await query.Find()).Select(obj => obj.ObjectId);
            IEnumerable <LCObject> list  = ids.Select(id => LCObject.CreateWithoutData("Hello", id));
            await LCObject.FetchAll(list);

            Assert.Greater(list.Count(), 0);
            foreach (LCObject obj in list)
            {
                Assert.NotNull(obj.CreatedAt);
            }
        }
Exemplo n.º 15
0
        public async Task Query()
        {
            LCQuery <Account> query = new LCQuery <Account>("Account");

            query.WhereGreaterThan("balance", 500);
            ReadOnlyCollection <Account> list = await query.Find();

            TestContext.WriteLine(list.Count);
            Assert.Greater(list.Count, 0);
            foreach (Account account in list)
            {
                Assert.NotNull(account.ObjectId);
            }
        }
Exemplo n.º 16
0
        public async Task Regex()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Hello");

            query.WhereMatches("stringValue", "^HEllo.*", modifiers: "i");
            ReadOnlyCollection <LCObject> results = await query.Find();

            Assert.Greater(results.Count, 0);
            foreach (LCObject item in results)
            {
                string str = item["stringValue"] as string;
                Assert.IsTrue(str.StartsWith("hello"));
            }
        }
Exemplo n.º 17
0
    async void Reload()
    {
        scrollRect.ClearItemData();

        LCQuery <LCFriendshipRequest> query = new LCQuery <LCFriendshipRequest>("_FriendshipRequest")
                                              .WhereEqualTo("friend", LCManager.Instance.User)
                                              .WhereEqualTo("status", "pending")
                                              .Include("user");
        ReadOnlyCollection <LCFriendshipRequest> requests = await query.Find();

        foreach (LCFriendshipRequest request in requests)
        {
            scrollRect.AddItemData(request);
        }
    }
Exemplo n.º 18
0
    async void OnEnable()
    {
        scrollRect.ClearItemData();

        LCQuery <LCObject> query = new LCQuery <LCObject>("_Followee")
                                   .WhereEqualTo("user", LCManager.Instance.User)
                                   .WhereEqualTo("friendStatus", true)
                                   .Include("followee");
        ReadOnlyCollection <LCObject> friends = await query.Find();

        foreach (LCObject friend in friends)
        {
            scrollRect.AddItemData(friend);
        }
    }
Exemplo n.º 19
0
        public async Task Query()
        {
            LCQuery <LCRole> query = LCRole.GetQuery();
            List <LCRole>    list  = await query.Find();

            list.ForEach(item => {
                TestContext.WriteLine($"{item.ObjectId} : {item.Name}");
                Assert.NotNull(item.ObjectId);
                Assert.NotNull(item.Name);
                TestContext.WriteLine(item.Roles.GetType());
                TestContext.WriteLine(item.Users.GetType());
                Assert.IsTrue(item.Roles is LCRelation <LCRole>);
                Assert.IsTrue(item.Users is LCRelation <LCUser>);
            });
        }
Exemplo n.º 20
0
        public async Task OrderBy()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.OrderByAscending("balance");
            ReadOnlyCollection <LCObject> results = await query.Find();

            Assert.LessOrEqual((int)results[0]["balance"], (int)results[1]["balance"]);

            query = new LCQuery <LCObject>("Account");
            query.OrderByDescending("balance");
            results = await query.Find();

            Assert.GreaterOrEqual((int)results[0]["balance"], (int)results[1]["balance"]);
        }
Exemplo n.º 21
0
        public async Task Query()
        {
            LCObject.RegisterSubclass <Account>("Account", () => new Account());
            LCQuery <Account> query = new LCQuery <Account>("Account");

            query.WhereGreaterThan("balance", 500);
            List <Account> list = await query.Find();

            TestContext.WriteLine(list.Count);
            Assert.Greater(list.Count, 0);
            foreach (Account account in list)
            {
                Assert.NotNull(account.ObjectId);
            }
        }
Exemplo n.º 22
0
        public async Task Query()
        {
            LCQuery <LCRole>            query   = LCRole.GetQuery();
            ReadOnlyCollection <LCRole> results = await query.Find();

            foreach (LCRole item in results)
            {
                TestContext.WriteLine($"{item.ObjectId} : {item.Name}");
                Assert.NotNull(item.ObjectId);
                Assert.NotNull(item.Name);
                TestContext.WriteLine(item.Roles.GetType());
                TestContext.WriteLine(item.Users.GetType());
                Assert.IsTrue(item.Roles is LCRelation <LCRole>);
                Assert.IsTrue(item.Users is LCRelation <LCUser>);
            }
        }
Exemplo n.º 23
0
        public async Task Serialization()
        {
            await LCUser.Login("hello", "world");

            LCQuery <LCObject> query = new LCQuery <LCObject>("Account")
            {
                IncludeACL = true
            };

            query.OrderByDescending("createdAt");
            ReadOnlyCollection <LCObject> accounts = await query.Find();

            foreach (LCObject account in accounts)
            {
                TestContext.WriteLine($"public read access: {account.ACL.PublicReadAccess}");
                TestContext.WriteLine($"public write access: {account.ACL.PublicWriteAccess}");
            }
        }
Exemplo n.º 24
0
        public async Task AddOrder()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.AddAscendingOrder("balance");
            query.AddDescendingOrder("createdAt");
            ReadOnlyCollection <LCObject> results = await query.Find();

            for (int i = 0; i + 1 < results.Count; i++)
            {
                LCObject a1 = results[i];
                LCObject a2 = results[i + 1];
                int      b1 = (int)a1["balance"];
                int      b2 = (int)a2["balance"];
                Assert.IsTrue(b1 < b2 ||
                              a1.CreatedAt.CompareTo(a2.CreatedAt) >= 0);
            }
        }
Exemplo n.º 25
0
        public async Task InQuery()
        {
            LCQuery <LCObject> worldQuery = new LCQuery <LCObject>("World");

            worldQuery.WhereEqualTo("content", "7788");
            LCQuery <LCObject> helloQuery = new LCQuery <LCObject>("Hello");

            helloQuery.WhereMatchesQuery("objectValue", worldQuery);
            helloQuery.Include("objectValue");
            ReadOnlyCollection <LCObject> hellos = await helloQuery.Find();

            Assert.Greater(hellos.Count, 0);
            foreach (LCObject item in hellos)
            {
                LCObject world = item["objectValue"] as LCObject;
                Assert.AreEqual(world["content"], "7788");
            }
        }
Exemplo n.º 26
0
        public async Task Exist()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereExists("user");
            List <LCObject> results = await query.Find();

            results.ForEach(item => {
                Assert.NotNull(item["user"]);
            });

            query = new LCQuery <LCObject>("Account");
            query.WhereDoesNotExist("user");
            results = await query.Find();

            results.ForEach(item => {
                Assert.IsNull(item["user"]);
            });
        }
Exemplo n.º 27
0
        public async Task NotInQuery()
        {
            LCQuery <LCObject> worldQuery = new LCQuery <LCObject>("World");

            worldQuery.WhereEqualTo("content", "7788");
            LCQuery <LCObject> helloQuery = new LCQuery <LCObject>("Hello");

            helloQuery.WhereDoesNotMatchQuery("objectValue", worldQuery);
            helloQuery.Include("objectValue");
            ReadOnlyCollection <LCObject> hellos = await helloQuery.Find();

            Assert.Greater(hellos.Count, 0);
            foreach (LCObject item in hellos)
            {
                LCObject world = item["objectValue"] as LCObject;
                Assert.IsTrue(world == null ||
                              world["content"] == null ||
                              world["content"] as string != "7788");
            }
        }
Exemplo n.º 28
0
        public async Task Or()
        {
            LCQuery <LCObject> q1 = new LCQuery <LCObject>("Account");

            q1.WhereLessThanOrEqualTo("balance", 100);
            LCQuery <LCObject> q2 = new LCQuery <LCObject>("Account");

            q2.WhereGreaterThanOrEqualTo("balance", 500);
            LCQuery <LCObject> query = LCQuery <LCObject> .Or(new List <LCQuery <LCObject> > {
                q1, q2
            });

            List <LCObject> results = await query.Find();

            TestContext.WriteLine(results.Count);
            results.ForEach(item => {
                int balance = (int)item["balance"];
                Assert.IsTrue(balance <= 100 || balance >= 500);
            });
        }
Exemplo n.º 29
0
        public async Task Exist()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereExists("user");
            ReadOnlyCollection <LCObject> results = await query.Find();

            foreach (LCObject item in results)
            {
                Assert.NotNull(item["user"]);
            }

            query = new LCQuery <LCObject>("Account");
            query.WhereDoesNotExist("user");
            results = await query.Find();

            foreach (LCObject item in results)
            {
                Assert.IsNull(item["user"]);
            }
        }
Exemplo n.º 30
0
        public async Task And()
        {
            LCQuery <LCObject> q1 = new LCQuery <LCObject>("Account");

            q1.WhereGreaterThan("balance", 100);
            LCQuery <LCObject> q2 = new LCQuery <LCObject>("Account");

            q2.WhereLessThan("balance", 500);
            LCQuery <LCObject> query = LCQuery <LCObject> .And(new List <LCQuery <LCObject> > {
                q1, q2
            });

            ReadOnlyCollection <LCObject> results = await query.Find();

            TestContext.WriteLine(results.Count);
            foreach (LCObject item in results)
            {
                int balance = (int)item["balance"];
                Assert.IsTrue(balance >= 100 || balance <= 500);
            }
        }