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); }
public void RemoveUserGroup() { IUsersStorageProviderV40 prov = GetProvider(); UserGroup group1 = prov.AddUserGroup("Group1", "Description1"); UserGroup group2 = prov.AddUserGroup("Group2", "Description2"); Assert.IsFalse(prov.RemoveUserGroup(new UserGroup("Inexistent", "Descr", prov)), "RemoveUserGroup should return false"); Assert.IsTrue(prov.RemoveUserGroup(new UserGroup("Group1", "Desc", prov)), "RemoveUser should return true"); UserGroup[] allGroups = prov.GetUserGroups(); Assert.AreEqual(1, allGroups.Length, "Wrong group count"); AssertUserGroupsAreEqual(group2, allGroups[0], true); }
public void AddUserGroup_GetUserGroups() { IUsersStorageProviderV40 prov = GetProvider(); UserGroup group1 = prov.AddUserGroup("Group1", "Test1"); UserGroup expected1 = new UserGroup("Group1", "Test1", prov); UserGroup group2 = prov.AddUserGroup("Group2", "Test2"); UserGroup expected2 = new UserGroup("Group2", "Test2", prov); Assert.IsNull(prov.AddUserGroup("Group1", "Test"), "AddUserGroup should return null"); AssertUserGroupsAreEqual(expected1, group1, true); AssertUserGroupsAreEqual(expected2, group2, 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(expected1, allGroups[0], true); AssertUserGroupsAreEqual(expected2, allGroups[1], true); }
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"); }