2020-02-26 11:48:42 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Linq;
|
2020-04-28 17:04:46 +08:00
|
|
|
|
using LeanCloud;
|
2020-02-26 11:48:42 +08:00
|
|
|
|
using LeanCloud.Storage;
|
|
|
|
|
|
2020-04-28 17:04:46 +08:00
|
|
|
|
namespace Storage.Test {
|
2020-02-26 11:48:42 +08:00
|
|
|
|
public class CloudTest {
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
2020-03-10 16:55:17 +08:00
|
|
|
|
LCLogger.LogDelegate += Utils.Print;
|
2021-03-24 16:01:34 +08:00
|
|
|
|
//LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
|
|
|
|
LCApplication.Initialize("8ijVI3gBAnPGynW0rVfh5gHP-gzGzoHsz", "265r8JSHhNYpV0qIJBvUWrQY", "https://8ijvi3gb.lc-cn-n1-shared.com");
|
2020-02-26 11:48:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown() {
|
2020-03-10 16:55:17 +08:00
|
|
|
|
LCLogger.LogDelegate -= Utils.Print;
|
2020-02-26 11:48:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Call() {
|
|
|
|
|
Dictionary<string, object> response = await LCCloud.Run("hello", parameters: new Dictionary<string, object> {
|
|
|
|
|
{ "name", "world" }
|
|
|
|
|
});
|
|
|
|
|
TestContext.WriteLine(response["result"]);
|
2021-03-24 16:01:34 +08:00
|
|
|
|
Assert.AreEqual(response["result"], "Hello, world!");
|
2020-02-26 11:48:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 16:24:41 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public async Task RunAverageScore() {
|
|
|
|
|
float score = await LCCloud.Run<float>("averageStars", new Dictionary<string, object> {
|
|
|
|
|
{ "movie", "夏洛特烦恼" }
|
|
|
|
|
});
|
|
|
|
|
TestContext.WriteLine($"score: {score}");
|
|
|
|
|
Assert.True(score.Equals(3.8f));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-26 11:48:42 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public async Task CallWithoutParams() {
|
|
|
|
|
await LCCloud.Run("hello");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task RPC() {
|
|
|
|
|
List<object> result = await LCCloud.RPC("getTycoonList") as List<object>;
|
|
|
|
|
IEnumerable<LCObject> tycoonList = result.Cast<LCObject>();
|
|
|
|
|
foreach (LCObject item in tycoonList) {
|
|
|
|
|
TestContext.WriteLine(item.ObjectId);
|
|
|
|
|
Assert.NotNull(item.ObjectId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-24 16:01:34 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task RPCObject() {
|
|
|
|
|
LCQuery<LCObject> query = new LCQuery<LCObject>("Todo");
|
|
|
|
|
LCObject todo = await query.Get("6052cd87b725a143ea83dbf8");
|
|
|
|
|
object result = await LCCloud.RPC("getTodo", todo);
|
|
|
|
|
LCObject obj = result as LCObject;
|
|
|
|
|
TestContext.WriteLine(obj.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task RPCObjects() {
|
|
|
|
|
Dictionary<string, object> parameters = new Dictionary<string, object> {
|
|
|
|
|
{ "limit", 20 }
|
|
|
|
|
};
|
|
|
|
|
List<object> result = await LCCloud.RPC("getTodos", parameters) as List<object>;
|
|
|
|
|
IEnumerable<LCObject> todos = result.Cast<LCObject>();
|
|
|
|
|
foreach (LCObject todo in todos) {
|
|
|
|
|
TestContext.WriteLine(todo.ObjectId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task RPCObjectMap() {
|
|
|
|
|
Dictionary<string, object> result = await LCCloud.RPC("getTodoMap") as Dictionary<string, object>;
|
|
|
|
|
foreach (KeyValuePair<string, object> kv in result) {
|
|
|
|
|
LCObject todo = kv.Value as LCObject;
|
|
|
|
|
TestContext.WriteLine(todo.ObjectId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-26 11:48:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|