2019-09-02 14:23:23 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Collections.Generic;
|
2020-02-26 11:16:21 +08:00
|
|
|
|
using LeanCloud.Storage;
|
2020-03-04 15:17:53 +08:00
|
|
|
|
using LeanCloud.Common;
|
2019-09-02 14:23:23 +08:00
|
|
|
|
|
2019-09-17 11:53:28 +08:00
|
|
|
|
namespace LeanCloud.Test {
|
2020-02-26 11:16:21 +08:00
|
|
|
|
internal class Hello : LCObject {
|
|
|
|
|
internal World World => this["objectValue"] as World;
|
|
|
|
|
|
|
|
|
|
internal Hello() : base("Hello") { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class World : LCObject {
|
|
|
|
|
internal string Content {
|
2019-09-02 14:23:23 +08:00
|
|
|
|
get {
|
2020-02-26 11:16:21 +08:00
|
|
|
|
return this["content"] as string;
|
|
|
|
|
} set {
|
|
|
|
|
this["content"] = value;
|
2019-09-02 14:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-26 11:16:21 +08:00
|
|
|
|
internal World() : base("World") { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class Account : LCObject {
|
|
|
|
|
internal int Balance {
|
2019-09-02 14:23:23 +08:00
|
|
|
|
get {
|
2020-02-26 11:16:21 +08:00
|
|
|
|
return (int)this["balance"];
|
|
|
|
|
} set {
|
|
|
|
|
this["balance"] = value;
|
2019-09-02 14:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-26 11:16:21 +08:00
|
|
|
|
|
|
|
|
|
internal Account() : base("Account") { }
|
2019-09-02 14:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class SubClassTest {
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
2020-03-10 16:55:17 +08:00
|
|
|
|
LCLogger.LogDelegate += Utils.Print;
|
2020-03-10 16:26:21 +08:00
|
|
|
|
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
2020-02-26 11:16:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown() {
|
2020-03-10 16:55:17 +08:00
|
|
|
|
LCLogger.LogDelegate -= Utils.Print;
|
2019-09-02 14:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-02-26 11:16:21 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
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);
|
2019-09-02 14:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-26 11:16:21 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Delete() {
|
|
|
|
|
LCObject.RegisterSubclass<Account>("Account", () => new Account());
|
|
|
|
|
Account account = new Account() {
|
|
|
|
|
Balance = 1024
|
|
|
|
|
};
|
|
|
|
|
await account.Save();
|
|
|
|
|
await account.Delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
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");
|
|
|
|
|
}
|
2019-09-02 14:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|