Exemple #1
0
        public async Task Delete()
        {
            LCObject.RegisterSubclass <Account>("Account", () => new Account());
            Account account = new Account()
            {
                Balance = 1024
            };
            await account.Save();

            await account.Delete();
        }
Exemple #2
0
        public async Task Create()
        {
            LCObject.RegisterSubclass <Account>("Account", () => new Account());
            Account account = new Account();

            account.Balance = 1000;
            await account.Save();

            TestContext.WriteLine(account.ObjectId);
            Assert.NotNull(account.ObjectId);
        }
Exemple #3
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();
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        public static void Initialize(string appId, string appKey, string server = null)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentException(nameof(appId));
            }
            if (string.IsNullOrEmpty(appKey))
            {
                throw new ArgumentException(nameof(appKey));
            }
            // 注册 LeanCloud 内部子类化类型
            LCObject.RegisterSubclass <LCUser>(LCUser.CLASS_NAME, () => new LCUser());
            LCObject.RegisterSubclass <LCRole>(LCRole.CLASS_NAME, () => new LCRole());
            LCObject.RegisterSubclass <LCFile>(LCFile.CLASS_NAME, () => new LCFile());

            HttpClient = new LCHttpClient(appId, appKey, server, SDKVersion, APIVersion);
        }
Exemple #6
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");
        }
Exemple #7
0
        public static void Initialize(string appId,
                                      string appKey,
                                      string server    = null,
                                      string masterKey = null)
        {
            LCCore.Initialize(appId, appKey, server, masterKey);

            LCCore.HttpClient.AddRuntimeHeaderTask(SessionHeaderKey, async() => {
                LCUser currentUser = await LCUser.GetCurrent();
                if (currentUser == null)
                {
                    return(null);
                }
                return(currentUser.SessionToken);
            });

            // 注册 LeanCloud 内部子类化类型
            LCObject.RegisterSubclass(LCUser.CLASS_NAME, () => new LCUser());
            LCObject.RegisterSubclass(LCRole.CLASS_NAME, () => new LCRole());
            LCObject.RegisterSubclass(LCFile.CLASS_NAME, () => new LCFile());
            LCObject.RegisterSubclass(LCStatus.CLASS_NAME, () => new LCStatus());
            LCObject.RegisterSubclass(LCFriendshipRequest.CLASS_NAME, () => new LCFriendshipRequest());
        }