2019-07-30 16:47:10 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-08-28 11:07:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-07-30 16:47:10 +08:00
|
|
|
|
using LeanCloud;
|
|
|
|
|
|
|
|
|
|
namespace LeanCloudTests {
|
|
|
|
|
public class ObjectControllerTests {
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
2019-08-27 17:27:46 +08:00
|
|
|
|
Utils.InitNorthChina();
|
2019-07-30 16:47:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2019-08-28 11:07:12 +08:00
|
|
|
|
public async Task Save() {
|
2019-07-30 16:47:10 +08:00
|
|
|
|
TestContext.Out.WriteLine($"before at {Thread.CurrentThread.ManagedThreadId}");
|
2019-08-28 11:07:12 +08:00
|
|
|
|
AVObject obj = AVObject.Create("Foo");
|
2019-07-30 16:47:10 +08:00
|
|
|
|
obj["content"] = "hello, world";
|
|
|
|
|
await obj.SaveAsync();
|
2019-08-06 12:16:17 +08:00
|
|
|
|
TestContext.Out.WriteLine($"{obj.ObjectId} saved at {Thread.CurrentThread.ManagedThreadId}");
|
2019-07-30 16:47:10 +08:00
|
|
|
|
Assert.NotNull(obj.ObjectId);
|
|
|
|
|
Assert.NotNull(obj.CreatedAt);
|
|
|
|
|
Assert.NotNull(obj.UpdatedAt);
|
2019-08-27 17:27:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 12:10:59 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public async Task SaveWithQuery() {
|
|
|
|
|
AVObject account = AVObject.CreateWithoutData("Account", "5d65fa5330863b008065e476");
|
|
|
|
|
AVQuery<AVObject> query = new AVQuery<AVObject>("Account");
|
|
|
|
|
query.WhereGreaterThan("balance", 80);
|
|
|
|
|
account["balance"] = 50;
|
|
|
|
|
await account.SaveAsync(query);
|
|
|
|
|
TestContext.Out.WriteLine($"balance: {account["balance"]}");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 17:27:46 +08:00
|
|
|
|
[Test]
|
2019-08-28 11:07:12 +08:00
|
|
|
|
public async Task Fetch() {
|
2019-08-27 17:27:46 +08:00
|
|
|
|
AVObject obj = AVObject.CreateWithoutData("Todo", "5d5f6039d5de2b006cf29c8f");
|
|
|
|
|
await obj.FetchAsync();
|
|
|
|
|
Assert.NotNull(obj["title"]);
|
|
|
|
|
Assert.NotNull(obj["content"]);
|
|
|
|
|
TestContext.Out.WriteLine($"{obj["title"]}, {obj["content"]}");
|
|
|
|
|
}
|
2019-08-28 11:07:12 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task FetchWithKeys() {
|
|
|
|
|
AVObject obj = AVObject.CreateWithoutData("Post", "5d3abfa530863b0068e1b326");
|
|
|
|
|
await obj.FetchAsync(new List<string> { "pubUser" });
|
|
|
|
|
TestContext.Out.WriteLine($"{obj["pubUser"]}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task FetchWithIncludes() {
|
|
|
|
|
AVObject obj = AVObject.CreateWithoutData("Post", "5d3abfa530863b0068e1b326");
|
|
|
|
|
await obj.FetchAsync(includes: new List<string> { "tag" });
|
|
|
|
|
AVObject tag = obj["tag"] as AVObject;
|
|
|
|
|
TestContext.Out.WriteLine($"{tag["name"]}");
|
|
|
|
|
}
|
2019-07-30 16:47:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|