Ejemplo n.º 1
0
        public void ModifyUserGroup()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserGroup group1 = prov.AddUserGroup("Group1", "Description1");
            UserGroup group2 = prov.AddUserGroup("Group2", "Description2");

            Assert.IsNull(prov.ModifyUserGroup(new UserGroup("Inexistent", "Descr", prov), "New"), "ModifyUserGroup should return null");

            prov.SetUserMembership(prov.AddUser("user", "user", "pass", "*****@*****.**", true, DateTime.Now), new string[] { "Group2" });

            UserGroup group2Out = prov.ModifyUserGroup(new UserGroup("Group2", "Description2", prov), "Mod");

            UserGroup expected = new UserGroup("Group2", "Mod", prov);

            expected.Users = new string[] { "user" };

            AssertUserGroupsAreEqual(expected, group2Out, true);

            UserGroup[] allGroups = prov.GetUserGroups();
            Assert.AreEqual(2, allGroups.Length, "Wrong group count");
            Array.Sort(allGroups, delegate(UserGroup x, UserGroup y) { return(x.Name.CompareTo(y.Name)); });

            AssertUserGroupsAreEqual(new UserGroup("Group1", "Description1", prov), allGroups[0], true);
            AssertUserGroupsAreEqual(expected, allGroups[1], true);
        }
Ejemplo n.º 2
0
        public void SetUserMembership_NullGroups()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.SetUserMembership(prov.AddUser("user", "user", "pass", "*****@*****.**", true, DateTime.Now), null);
        }
Ejemplo n.º 3
0
        public void SetUserMembership_NullUser()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.SetUserMembership(null, new string[0]);
        }
Ejemplo n.º 4
0
        public void SetUserMembership()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            DateTime dt = DateTime.Now;

            UserInfo  user   = prov.AddUser("user", "user", "pass", "*****@*****.**", true, dt);
            UserGroup group1 = prov.AddUserGroup("Group1", "");
            UserGroup group2 = prov.AddUserGroup("Group2", "");

            Assert.IsNull(prov.SetUserMembership(new UserInfo("user222", "user222", "*****@*****.**", true, DateTime.Now, prov), new string[0]),
                          "SetUserMembership should return null");

            Assert.IsNull(prov.SetUserMembership(user, new string[] { "Group2", "Inexistent" }), "SetUserMembership should return null");

            UserInfo output = prov.SetUserMembership(user, new string[] { "Group2", "Group1" });

            AssertUserInfosAreEqual(new UserInfo("user", "user", "*****@*****.**", true, dt, prov), output, true);
            Assert.AreEqual(2, output.Groups.Length, "Wrong group count");
            Array.Sort(output.Groups);
            Assert.AreEqual("Group1", output.Groups[0], "Wrong group");
            Assert.AreEqual("Group2", output.Groups[1], "Wrong group");

            UserInfo[] allUsers = prov.GetUsers();
            Assert.AreEqual(2, allUsers[0].Groups.Length, "Wrong group count");
            Array.Sort(allUsers[0].Groups);
            Assert.AreEqual("Group1", allUsers[0].Groups[0], "Wrong group");
            Assert.AreEqual("Group2", allUsers[0].Groups[1], "Wrong group");

            // Also test ModifyUser
            UserInfo info = prov.ModifyUser(output, output.Username, "Pass", output.Email, output.Active);

            Array.Sort(allUsers[0].Groups);
            Assert.AreEqual("Group1", info.Groups[0], "Wrong group");
            Assert.AreEqual("Group2", info.Groups[1], "Wrong group");

            UserGroup[] allGroups = prov.GetUserGroups();

            Assert.AreEqual(2, allGroups.Length, "Wrong group count");

            UserGroup expected1 = new UserGroup("Group1", "", prov);

            expected1.Users = new string[] { "user" };
            UserGroup expected2 = new UserGroup("Group2", "", prov);

            expected2.Users = new string[] { "user" };

            Array.Sort(allGroups, delegate(UserGroup x, UserGroup y) { return(x.Name.CompareTo(y.Name)); });
            AssertUserGroupsAreEqual(expected1, allGroups[0], true);
            AssertUserGroupsAreEqual(expected2, allGroups[1], true);

            output = prov.SetUserMembership(user, new string[0]);
            AssertUserInfosAreEqual(new UserInfo("user", "user", "*****@*****.**", true, dt, prov), output, true);
            Assert.AreEqual(0, output.Groups.Length, "Wrong group count");

            allGroups = prov.GetUserGroups();

            Assert.AreEqual(2, allGroups.Length, "Wrong group count");

            expected1 = new UserGroup("Group1", "", prov);
            expected2 = new UserGroup("Group2", "", prov);

            Array.Sort(allGroups, delegate(UserGroup x, UserGroup y) { return(x.Name.CompareTo(y.Name)); });
            AssertUserGroupsAreEqual(expected1, allGroups[0], true);
            AssertUserGroupsAreEqual(expected2, allGroups[1], true);

            allUsers = prov.GetUsers();
            Assert.AreEqual(0, allUsers[0].Groups.Length, "Wrong group count");

            // Also test ModifyUser
            info = prov.ModifyUser(output, output.Username, "Pass", output.Email, output.Active);
            Assert.AreEqual(0, info.Groups.Length, "Wrong group count");
        }