2019-08-27 15:19:19 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-02-27 12:31:48 +08:00
|
|
|
|
using System;
|
2020-05-06 16:02:26 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
2019-08-27 15:19:19 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-02-27 12:31:48 +08:00
|
|
|
|
using LeanCloud.Storage;
|
2019-08-27 15:19:19 +08:00
|
|
|
|
|
2020-04-28 17:04:46 +08:00
|
|
|
|
namespace Storage.Test {
|
2019-09-02 14:23:23 +08:00
|
|
|
|
[TestFixture]
|
2019-08-27 15:19:19 +08:00
|
|
|
|
public class RoleTest {
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
2021-04-07 18:08:17 +08:00
|
|
|
|
Utils.SetUp();
|
2020-02-27 12:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown() {
|
2021-04-07 18:08:17 +08:00
|
|
|
|
Utils.TearDown();
|
2020-02-27 12:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task NewRole() {
|
|
|
|
|
LCUser currentUser = await LCUser.Login("game", "play");
|
|
|
|
|
LCACL acl = new LCACL();
|
|
|
|
|
acl.PublicReadAccess = true;
|
|
|
|
|
acl.SetUserWriteAccess(currentUser, true);
|
|
|
|
|
string name = $"role_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
|
|
|
|
|
LCRole role = LCRole.Create(name, acl);
|
|
|
|
|
role.AddRelation("users", currentUser);
|
|
|
|
|
await role.Save();
|
2019-08-27 15:19:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-02-27 12:31:48 +08:00
|
|
|
|
public async Task Query() {
|
|
|
|
|
LCQuery<LCRole> query = LCRole.GetQuery();
|
2020-05-06 16:02:26 +08:00
|
|
|
|
ReadOnlyCollection<LCRole> results = await query.Find();
|
|
|
|
|
foreach (LCRole item in results) {
|
2020-02-27 12:31:48 +08:00
|
|
|
|
TestContext.WriteLine($"{item.ObjectId} : {item.Name}");
|
|
|
|
|
Assert.NotNull(item.ObjectId);
|
|
|
|
|
Assert.NotNull(item.Name);
|
|
|
|
|
TestContext.WriteLine(item.Roles.GetType());
|
|
|
|
|
TestContext.WriteLine(item.Users.GetType());
|
|
|
|
|
Assert.IsTrue(item.Roles is LCRelation<LCRole>);
|
|
|
|
|
Assert.IsTrue(item.Users is LCRelation<LCUser>);
|
2020-05-06 16:02:26 +08:00
|
|
|
|
}
|
2019-08-27 15:19:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|