Beispiel #1
0
        public void TestAddUser()
        {
            Task.Run(async() =>
            {
                var acl = new NCMBAcl();
                acl.SetPublicWriteAccess(true);

                var user1    = new NCMBUser();
                var userName = "******";
                var password = "******";
                user1.Set("userName", userName);
                user1.Set("password", password);
                await user1.SignUp();
                var user = await NCMBUser.Login(userName, password);
                user.SetAcl(acl);
                await user.Save();

                var user2 = new NCMBUser();
                userName  = "******";
                password  = "******";
                user2.Set("userName", userName);
                user2.Set("password", password);
                await user2.SignUp();

                user = await NCMBUser.Login(userName, password);
                user.SetAcl(acl);
                await user.Save();

                var role1 = new NCMBRole();
                role1.Set("roleName", "role5");
                await role1.Save();
                Assert.NotNull(role1.Get("objectId"));


                await role1.AddUser(user1).AddUser(user2).Save();

                await role1.Fetch();

                var users = await role1.FetchUser();
                // Console.WriteLine(users.Length);
                Assert.AreEqual(2, users.Length);
                role1.ClearOperation();
                await role1.RemoveUser(user1).Save();
                users = await role1.FetchUser();
                Assert.AreEqual(1, users.Length);
                // Assert.AreEqual(user1.Get("userName").ToString(), users[0].Get("userName").ToString());
                await role1.Delete();
                await user1.Delete();
                await user2.Delete();
            }).GetAwaiter().GetResult();
        }