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

58 lines
1.8 KiB
C#
Raw Normal View History

using NUnit.Framework;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using LeanCloud.Storage;
2020-04-28 17:04:46 +08:00
namespace Storage.Test {
2021-04-29 15:58:22 +08:00
public class SubClassTest : BaseTest {
[Test]
public async Task Create() {
Account account = new Account();
account.Balance = 1000;
await account.Save();
TestContext.WriteLine(account.ObjectId);
Assert.NotNull(account.ObjectId);
}
[Test]
public async Task Query() {
LCQuery<Account> query = new LCQuery<Account>("Account");
query.WhereGreaterThan("balance", 500);
ReadOnlyCollection<Account> list = await query.Find();
TestContext.WriteLine(list.Count);
Assert.Greater(list.Count, 0);
foreach (Account account in list) {
Assert.NotNull(account.ObjectId);
}
}
[Test]
public async Task Delete() {
Account account = new Account() {
Balance = 1024
};
await account.Save();
await account.Delete();
}
2021-05-21 14:48:53 +08:00
[Test]
public async Task ObjectWithFile() {
LCUser user = await LCUser.Login("hello", "world");
ObjectWithFile obj = new ObjectWithFile() {
File = new LCFile("avatar", "../../../../../assets/hello.png"),
Owner = user
};
await obj.Save();
LCQuery<ObjectWithFile> query = new LCQuery<ObjectWithFile>("ObjectWithFile");
ObjectWithFile obj2 = await query.Get(obj.ObjectId);
TestContext.WriteLine(obj2.File.Url);
TestContext.WriteLine(obj2.Owner.ObjectId);
Assert.IsNotNull(obj2.File.Url);
Assert.IsNotNull(obj2.Owner.ObjectId);
}
}
}