Ejemplo n.º 1
0
        public static async Task <ReadOnlyCollection <LCObject> > GetObjects()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereGreaterThan("balance", 100);
            return(await query.Find());
        }
Ejemplo n.º 2
0
        public async Task Count()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereGreaterThan("balance", 200);
            int count = await query.Count();

            TestContext.WriteLine(count);
            Assert.Greater(count, 0);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public async Task Setup()
        {
            LCLogger.LogDelegate += Print;
            LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz",
                                     "NUKmuRbdAhg1vrb2wexYo1jo",
                                     "https://ikggdre2.lc-cn-n1-shared.com");

            LCObject.RegisterSubclass("Account", () => new Account());

            LCQuery <LCObject> query = new LCQuery <LCObject>("Account");

            query.WhereGreaterThan("balance", 100);
            liveQuery = await query.Subscribe();
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        public async Task SaveWithOption()
        {
            Account account = new Account {
                Balance = 10
            };
            await account.Save();

            LCQuery <LCObject> q = new LCQuery <LCObject>("Account");

            q.WhereGreaterThan("balance", 100);
            try {
                await account.Save(fetchWhenSave : true, query : q);
            } catch (LCException e) {
                WriteLine($"{e.Code} : {e.Message}");
                Assert.AreEqual(e.Code, 305);
            }
        }
Ejemplo n.º 8
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
            });

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

            TestContext.WriteLine(results.Count);
            results.ForEach(item => {
                int balance = (int)item["balance"];
                Assert.IsTrue(balance >= 100 || balance <= 500);
            });
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            WriteLine("Hello World!");

            SingleThreadSynchronizationContext.Run(async() => {
                LCLogger.LogDelegate += Print;
                LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz",
                                         "NUKmuRbdAhg1vrb2wexYo1jo",
                                         "https://ikggdre2.lc-cn-n1-shared.com");

                await LCUser.Login("hello", "world");
                LCQuery <LCUser> userQuery = LCUser.GetQuery();
                userQuery.WhereEqualTo("username", "hello");
                LCLiveQuery userLiveQuery = await userQuery.Subscribe();
                userLiveQuery.OnLogin     = (user) => {
                    WriteLine($"login: {user.Username}");
                };

                LCQuery <LCObject> query = new LCQuery <LCObject>("Account");
                query.WhereGreaterThan("balance", 100);
                LCLiveQuery liveQuery = await query.Subscribe();
                liveQuery.OnCreate    = (obj) => {
                    WriteLine($"create: {obj}");
                };
                liveQuery.OnUpdate = (obj, keys) => {
                    WriteLine($"update: {obj}");
                    WriteLine(keys.Count);
                };
                liveQuery.OnDelete = (objId) => {
                    WriteLine($"delete: {objId}");
                };
                liveQuery.OnEnter = (obj, keys) => {
                    WriteLine($"enter: {obj}");
                    WriteLine(keys.Count);
                };
                liveQuery.OnLeave = (obj, keys) => {
                    WriteLine($"leave: {obj}");
                    WriteLine(keys.Count);
                };
            });
        }