csharp-sdk-upm/Storage/Storage.Test/CloudTest.cs

86 lines
3.0 KiB
C#
Raw Normal View History

using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
2020-04-28 17:04:46 +08:00
using LeanCloud;
using LeanCloud.Storage;
2020-04-28 17:04:46 +08:00
namespace Storage.Test {
public class CloudTest {
[SetUp]
public void SetUp() {
2020-03-10 16:55:17 +08:00
LCLogger.LogDelegate += Utils.Print;
//LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
LCApplication.Initialize("8ijVI3gBAnPGynW0rVfh5gHP-gzGzoHsz", "265r8JSHhNYpV0qIJBvUWrQY", "https://8ijvi3gb.lc-cn-n1-shared.com");
}
[TearDown]
public void TearDown() {
2020-03-10 16:55:17 +08:00
LCLogger.LogDelegate -= Utils.Print;
}
[Test]
public async Task Call() {
Dictionary<string, object> response = await LCCloud.Run("hello", parameters: new Dictionary<string, object> {
{ "name", "world" }
});
TestContext.WriteLine(response["result"]);
Assert.AreEqual(response["result"], "Hello, world!");
}
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));
}
[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);
}
}
[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);
}
}
}
}