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

63 lines
2.2 KiB
C#
Raw Normal View History

using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using LeanCloud.Storage;
2020-04-28 17:04:46 +08:00
namespace Storage.Test {
2021-04-29 15:58:22 +08:00
public class CloudTest : BaseTest {
[Test]
2021-04-29 15:58:22 +08:00
public async Task Ping() {
Dictionary<string, object> response = await LCCloud.Run("ping");
TestContext.WriteLine(response["result"]);
2021-04-29 15:58:22 +08:00
Assert.AreEqual(response["result"], "pong");
}
2021-03-24 16:24:41 +08:00
[Test]
2021-04-29 15:58:22 +08:00
public async Task Hello() {
string result = await LCCloud.Run<string>("hello", new Dictionary<string, object> {
{ "name", "world" }
2021-03-24 16:24:41 +08:00
});
2021-04-29 15:58:22 +08:00
TestContext.WriteLine(result);
Assert.AreEqual(result, "hello, world");
2021-03-24 16:24:41 +08:00
}
[Test]
2021-04-29 15:58:22 +08:00
public async Task GetObject() {
LCObject hello = new LCObject("Hello");
await hello.Save();
object reponse = await LCCloud.RPC("getObject", new Dictionary<string, object> {
{ "className", "Hello" },
{ "id", hello.ObjectId }
});
LCObject obj = reponse as LCObject;
Assert.AreEqual(obj.ObjectId, hello.ObjectId);
}
[Test]
2021-04-29 15:58:22 +08:00
public async Task GetObjects() {
object response = await LCCloud.RPC("getObjects");
List<object> list = response as List<object>;
IEnumerable<LCObject> objects = list.Cast<LCObject>();
TestContext.WriteLine(objects.Count());
Assert.Greater(objects.Count(), 0);
foreach (LCObject obj in objects) {
int balance = (int)obj["balance"];
Assert.Greater(balance, 100);
}
}
[Test]
2021-04-29 15:58:22 +08:00
public async Task GetObjectMap() {
object response = await LCCloud.RPC("getObjectMap");
Dictionary<string, object> dict = response as Dictionary<string, object>;
TestContext.WriteLine(dict.Count);
Assert.Greater(dict.Count, 0);
foreach (KeyValuePair<string, object> kv in dict) {
LCObject obj = kv.Value as LCObject;
Assert.AreEqual(kv.Key, obj.ObjectId);
}
}
}
}