public IEnumerator FetchAsyncDataNotAvailable()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) => {
            Assert.Null(e);

            NCMBUser.CurrentUser.SessionToken = "invalidToken";
            NCMBUser.CurrentUser._currentOperations.Clear();

            NCMBRole exampleRole = new NCMBRole("exampleRole");
            exampleRole.ObjectId = "roleInvalidObjectId";

            exampleRole.FetchAsync((NCMBException ex) =>
            {
                Assert.NotNull(ex);
                Assert.AreEqual("E404001", ex.ErrorCode);
                Assert.AreEqual("No data available.", ex.ErrorMessage);
                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
        public void TestAddRole()
        {
            Task.Run(async() =>
            {
                var role1 = new NCMBRole();
                role1.Set("roleName", "role1");
                await role1.Save();
                Assert.NotNull(role1.Get("objectId"));

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

                await role1.AddRole(role2).Save();

                await role1.Fetch();

                var roles = await role1.FetchRole();

                Assert.AreEqual(role2.Get("roleName").ToString(), roles[0].Get("roleName").ToString());

                await role1.Delete();
                await role2.Delete();
            }).GetAwaiter().GetResult();
        }
Exemple #3
0
    public void GetBaseUrlTest()
    {
        // テストデータ作成
        NCMBRole expertPlanRole = new NCMBRole("expertPlan");

        // internal methodの呼び出し
        MethodInfo method = expertPlanRole.GetType().GetMethod("_getBaseUrl", BindingFlags.NonPublic | BindingFlags.Instance);

        Assert.AreEqual("http://localhost:3000/2013-09-01/roles", method.Invoke(expertPlanRole, null).ToString());
    }
 public void TestCreateRole()
 {
     Task.Run(async() =>
     {
         var role = new NCMBRole();
         role.Set("roleName", "admin2");
         await role.Save();
         Assert.NotNull(role.Get("objectId"));
         await role.Delete();
     }).GetAwaiter().GetResult();
 }
        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();
        }
 public void RemoveFromRole()
 {
     if (isLogedIn)
     {
         NCMBRole.GetQuery().WhereEqualTo("roleName", roleName.text).FindAsync((roleList, error) =>
         {
             if (roleList.Count > 0)
             {
                 NCMBRole role = roleList[0];
                 if (role != null)
                 {
                     role.Users.Remove(NCMBUser.CurrentUser);
                     role.SaveAsync();
                 }
             }
         });
     }
 }
        public void TestAddAndRemoveRole()
        {
            Task.Run(async() =>
            {
                var role1 = new NCMBRole();
                role1.Set("roleName", "role3");
                await role1.Save();
                Assert.NotNull(role1.Get("objectId"));

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

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

                await role1.AddRole(role2).AddRole(role3).Save();

                await role1.Fetch();

                var roles = await role1.FetchRole();

                Assert.AreEqual(roles.Length, 2);

                // Assert.AreEqual(role3.Get("roleName").ToString(), roles[0].Get("roleName").ToString());

                role1.ClearOperation();
                await role1.RemoveRole(role2).Save();
                await role1.Fetch();

                var roles2 = await role1.FetchRole();
                Assert.AreEqual(roles2.Length, 1);

                await role1.Delete();
                await role2.Delete();
                await role3.Delete();
            }).GetAwaiter().GetResult();
        }
 public void AddToChildRole()
 {
     if (isLogedIn)
     {
         string   childRoleName = DateTime.Now.ToString("yyyyMMdd_HHmmss");
         NCMBRole childRole     = new NCMBRole(childRoleName);
         childRole.SaveAsync((NCMBException saveError) => {
             if (saveError != null)
             {
                 // エラー処理
             }
             else
             {
                 // 保存済みのロールに作成したロールを追加
                 NCMBRole.GetQuery().WhereEqualTo("roleName", roleName.text).FindAsync((roleList, findError) => {
                     if (findError != null)
                     {
                         // エラー処理
                     }
                     else
                     {
                         if (roleList.Count > 0)
                         {
                             NCMBRole bronzeRole = roleList[0];
                             if (bronzeRole != null)
                             {
                                 bronzeRole.Roles.Add(childRole);
                                 bronzeRole.SaveAsync();
                             }
                         }
                     }
                 });
             }
         });
     }
 }
Exemple #9
0
    public void AddRoleUserTest()
    {
        // ユーザー作成
        NCMBUser expertUser = new NCMBUser();

        expertUser.UserName = "******";
        expertUser.Password = "******";
        expertUser.SignUpAsync((error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(expertUser.ObjectId);

        // ロール作成
        NCMBRole expertPlanRole = new NCMBRole("expertPlan");

        expertPlanRole.SaveAsync((error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(expertPlanRole.ObjectId);

        // 空のロールを検索
        NCMBRole expertPlan = null;

        NCMBRole.GetQuery().WhereEqualTo("roleName", "expertPlan").FindAsync((roleList, error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
            else
            {
                expertPlan = roleList.FirstOrDefault();
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(expertPlan.ObjectId);

        // 空のロールにユーザーを追加
        expertPlan.Users.Add(expertUser);
        expertPlan.SaveAsync((error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
        });
        NCMBTestSettings.AwaitAsync();

        // ロールを検索
        expertPlan = null;
        NCMBRole.GetQuery().WhereEqualTo("roleName", "expertPlan").FindAsync((roleList, error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
            else
            {
                expertPlan = roleList.FirstOrDefault();
            }
        });
        NCMBTestSettings.AwaitAsync();

        // ロールに所属するユーザーを検索
        expertPlan.Users.GetQuery().FindAsync((userList, error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
            else
            {
                Assert.AreEqual(expertUser.ObjectId, userList.FirstOrDefault().ObjectId);
                NCMBTestSettings.CallbackFlag = true;
                // テストデータ削除
                expertPlan.DeleteAsync();
                expertUser.DeleteAsync();
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.True(NCMBTestSettings.CallbackFlag);
    }