2019-08-27 15:19:19 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-02-27 12:31:48 +08:00
|
|
|
|
using System;
|
2019-08-27 15:19:19 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-02-27 12:31:48 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using LeanCloud.Storage;
|
2020-03-04 15:17:53 +08:00
|
|
|
|
using LeanCloud.Common;
|
2019-08-27 15:19:19 +08:00
|
|
|
|
|
2019-09-17 11:53:28 +08:00
|
|
|
|
namespace LeanCloud.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() {
|
2020-02-27 12:31:48 +08:00
|
|
|
|
Logger.LogDelegate += Utils.Print;
|
2020-03-10 16:26:21 +08:00
|
|
|
|
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
2020-02-27 12:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown() {
|
|
|
|
|
Logger.LogDelegate -= Utils.Print;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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();
|
|
|
|
|
List<LCRole> list = await query.Find();
|
|
|
|
|
list.ForEach(item => {
|
|
|
|
|
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>);
|
|
|
|
|
});
|
2019-08-27 15:19:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|