Пример #1
0
        public async Task UserReadAndWrite()
        {
            await LCUser.Login("hello", "world");

            LCObject account     = new LCObject("Account");
            LCUser   currentUser = await LCUser.GetCurrent();

            LCACL acl = LCACL.CreateWithOwner(currentUser);

            account.ACL        = acl;
            account["balance"] = 512;
            await account.Save();

            Assert.IsTrue(acl.GetUserReadAccess(currentUser));
            Assert.IsTrue(acl.GetUserWriteAccess(currentUser));

            LCQuery <LCObject> query  = new LCQuery <LCObject>("Account");
            LCObject           result = await query.Get(account.ObjectId);

            TestContext.WriteLine(result.ObjectId);
            Assert.NotNull(result.ObjectId);

            await LCUser.Logout();

            result = await query.Get(account.ObjectId);

            Assert.IsNull(result);
        }
Пример #2
0
        public async Task UserReadAndWrite()
        {
            await LCUser.Login(TestPhone, TestPhone);

            account = new Account();
            LCUser currentUser = await LCUser.GetCurrent();

            account.ACL     = LCACL.CreateWithOwner(currentUser);
            account.Balance = 512;
            await account.Save();

            Assert.IsTrue(account.ACL.GetUserReadAccess(currentUser));
            Assert.IsTrue(account.ACL.GetUserWriteAccess(currentUser));

            LCQuery <LCObject> query  = new LCQuery <LCObject>("Account");
            LCObject           result = await query.Get(account.ObjectId);

            TestContext.WriteLine(result.ObjectId);
            Assert.NotNull(result.ObjectId);

            await LCUser.Logout();

            try {
                await query.Get(account.ObjectId);
            } catch (LCException e) {
                Assert.AreEqual(e.Code, 403);
            }
        }
Пример #3
0
        public async Task Get()
        {
            LCQuery <LCObject> query   = new LCQuery <LCObject>("Account");
            LCObject           account = await query.Get("5e0d9f7fd4b56c008e5d048a");

            Assert.AreEqual(account["balance"], 400);
        }
Пример #4
0
        public static async Task <LCObject> GetObject([LCEngineFunctionParam("className")] string className,
                                                      [LCEngineFunctionParam("id")] string id)
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>(className);

            return(await query.Get(id));
        }
Пример #5
0
        public async Task QueryFile()
        {
            LCQuery <LCFile> query = LCFile.GetQuery();
            LCFile           file  = await query.Get(avatar.ObjectId);

            Assert.NotNull(file.Url);
            TestContext.WriteLine(file.Url);
            TestContext.WriteLine(file.GetThumbnailUrl(32, 32));
        }
Пример #6
0
        public async Task QueryFile()
        {
            LCQuery <LCFile> query = LCFile.GetQuery();
            LCFile           file  = await query.Get("5e0dbfa0562071008e21c142");

            Assert.NotNull(file.Url);
            TestContext.WriteLine(file.Url);
            TestContext.WriteLine(file.GetThumbnailUrl(32, 32));
        }
Пример #7
0
        public async Task Query()
        {
            await LCUser.Login("game", "play");

            LCQuery <LCObject> query   = new LCQuery <LCObject>("Account");
            LCObject           account = await query.Get("5e144525dd3c13006a8f8de2");

            TestContext.WriteLine(account.ObjectId);
            Assert.NotNull(account.ObjectId);
        }
Пример #8
0
        public async Task Query()
        {
            await LCUser.Login(TestPhone, TestPhone);

            LCQuery <LCObject> query        = new LCQuery <LCObject>("Account");
            Account            queryAccount = (await query.Get(account.ObjectId)) as Account;

            TestContext.WriteLine(queryAccount.ObjectId);
            Assert.NotNull(queryAccount.ObjectId);
        }
Пример #9
0
        public async Task Include()
        {
            LCQuery <LCObject> query = new LCQuery <LCObject>("Hello");

            query.Include("objectValue");
            LCObject hello = await query.Get("5e0d55aedd3c13006a53cd87");

            LCObject world = hello["objectValue"] as LCObject;

            TestContext.WriteLine(world["content"]);
            Assert.AreEqual(world["content"], "7788");
        }
Пример #10
0
        public async Task Get()
        {
            Account account = new Account {
                Balance = 1024
            };
            await account.Save();

            LCQuery <LCObject> query      = new LCQuery <LCObject>("Account");
            Account            newAccount = (await query.Get(account.ObjectId)) as Account;

            Assert.AreEqual(newAccount.Balance, 1024);
        }
Пример #11
0
        public async Task WhereObjectEquals()
        {
            LCQuery <LCObject> worldQuery = new LCQuery <LCObject>("World");
            LCObject           world      = await worldQuery.Get("5e0d55ae21460d006a1ec931");

            LCQuery <LCObject> helloQuery = new LCQuery <LCObject>("Hello");

            helloQuery.WhereEqualTo("objectValue", world);
            LCObject hello = await helloQuery.First();

            TestContext.WriteLine(hello.ObjectId);
            Assert.AreEqual(hello.ObjectId, "5e0d55aedd3c13006a53cd87");
        }
Пример #12
0
        public async Task Decrement()
        {
            LCQuery <LCObject> query   = new LCQuery <LCObject>("Account");
            LCObject           account = await query.Get("5e154a5143c257006fbff63f");

            TestContext.WriteLine(account["balance"]);
            int balance = (int)account["balance"];

            account.Increment("balance", -10);
            await account.Save();

            TestContext.WriteLine(account["balance"]);
            Assert.AreEqual((int)account["balance"], balance - 10);
        }
Пример #13
0
        public async Task FileACL()
        {
            LCUser user = await LCUser.LoginAnonymously();

            LCFile file = new LCFile("avatar", AvatarFilePath);
            LCACL  acl  = new LCACL();

            acl.SetUserReadAccess(user, true);
            file.ACL = acl;
            await file.Save();

            LCQuery <LCFile> query  = LCFile.GetQuery();
            LCFile           avatar = await query.Get(file.ObjectId);

            Assert.NotNull(avatar.ObjectId);

            await LCUser.LoginAnonymously();

            try {
                LCFile forbiddenAvatar = await query.Get(file.ObjectId);
            } catch (LCException e) {
                Assert.AreEqual(e.Code, 403);
            }
        }
Пример #14
0
        public async Task RoleReadAndWrite()
        {
            LCQuery <LCRole> query = LCRole.GetQuery();
            LCRole           owner = await query.Get("5e1440cbfc36ed006add1b8d");

            LCObject account = new LCObject("Account");
            LCACL    acl     = new LCACL();

            acl.SetRoleReadAccess(owner, true);
            acl.SetRoleWriteAccess(owner, true);
            account.ACL = acl;
            await account.Save();

            Assert.IsTrue(acl.GetRoleReadAccess(owner));
            Assert.IsTrue(acl.GetRoleWriteAccess(owner));
        }
Пример #15
0
        public async Task Include()
        {
            LCObject.RegisterSubclass <Hello>("Hello", () => new Hello());
            LCObject.RegisterSubclass <World>("World", () => new World());

            LCQuery <Hello> helloQuery = new LCQuery <Hello>("Hello");

            helloQuery.Include("objectValue");
            Hello hello = await helloQuery.Get("5e0d55aedd3c13006a53cd87");

            World world = hello.World;

            TestContext.WriteLine(hello.ObjectId);
            Assert.AreEqual(hello.ObjectId, "5e0d55aedd3c13006a53cd87");
            TestContext.WriteLine(world.ObjectId);
            Assert.AreEqual(world.ObjectId, "5e0d55ae21460d006a1ec931");
            Assert.AreEqual(world.Content, "7788");
        }
Пример #16
0
        public async Task Include()
        {
            Hello hello = new Hello {
                World = new World {
                    Content = "7788"
                }
            };
            await hello.Save();

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

            query.Include("objectValue");
            Hello queryHello = (await query.Get(hello.ObjectId)) as Hello;
            World world      = queryHello.World;

            TestContext.WriteLine(world.Content);
            Assert.AreEqual(world.Content, "7788");
        }
Пример #17
0
        public async Task WhereObjectEquals()
        {
            World world = new World();
            Hello hello = new Hello {
                World = world
            };
            await hello.Save();

            LCQuery <LCObject> worldQuery = new LCQuery <LCObject>("World");
            LCObject           queryWorld = await worldQuery.Get(world.ObjectId);

            LCQuery <LCObject> helloQuery = new LCQuery <LCObject>("Hello");

            helloQuery.WhereEqualTo("objectValue", queryWorld);
            LCObject queryHello = await helloQuery.First();

            TestContext.WriteLine(queryHello.ObjectId);
            Assert.AreEqual(queryHello.ObjectId, hello.ObjectId);
        }
Пример #18
0
        public async Task ObjectWithFile()
        {
            LCUser user = await LCUser.Login("hello", "world");

            ObjectWithFile obj = new ObjectWithFile()
            {
                File  = new LCFile("avatar", "../../../../../assets/hello.png"),
                Owner = user
            };
            await obj.Save();

            LCQuery <ObjectWithFile> query = new LCQuery <ObjectWithFile>("ObjectWithFile");
            ObjectWithFile           obj2  = await query.Get(obj.ObjectId);

            TestContext.WriteLine(obj2.File.Url);
            TestContext.WriteLine(obj2.Owner.ObjectId);

            Assert.IsNotNull(obj2.File.Url);
            Assert.IsNotNull(obj2.Owner.ObjectId);
        }
Пример #19
0
        public async Task Query()
        {
            LCQuery <LCObject> query  = new LCQuery <LCObject>("Parent");
            LCObject           parent = await query.Get("5e13112021b47e0070ed0922");

            LCRelation <LCObject> relation = parent["children"] as LCRelation <LCObject>;

            TestContext.WriteLine(relation.Key);
            TestContext.WriteLine(relation.Parent);
            TestContext.WriteLine(relation.TargetClass);

            Assert.NotNull(relation.Key);
            Assert.NotNull(relation.Parent);
            Assert.NotNull(relation.TargetClass);

            LCQuery <LCObject> relationQuery = relation.Query;
            List <LCObject>    list          = await relationQuery.Find();

            list.ForEach(item => {
                TestContext.WriteLine(item.ObjectId);
                Assert.NotNull(item.ObjectId);
            });
        }
Пример #20
0
        public async Task Query()
        {
            LCQuery <LCObject> query       = new LCQuery <LCObject>("Parent");
            LCObject           queryParent = await query.Get(parent.ObjectId);

            LCRelation <LCObject> relation = queryParent["children"] as LCRelation <LCObject>;

            TestContext.WriteLine(relation.Key);
            TestContext.WriteLine(relation.Parent);
            TestContext.WriteLine(relation.TargetClass);

            Assert.NotNull(relation.Key);
            Assert.NotNull(relation.Parent);
            Assert.NotNull(relation.TargetClass);

            LCQuery <LCObject>            relationQuery = relation.Query;
            ReadOnlyCollection <LCObject> results       = await relationQuery.Find();

            foreach (LCObject item in results)
            {
                TestContext.WriteLine(item.ObjectId);
                Assert.NotNull(item.ObjectId);
            }
        }