public void ModifyUser() { IUsersStorageProviderV40 prov = GetProvider(); UserInfo user = new UserInfo("username", null, "*****@*****.**", false, DateTime.UtcNow, prov); prov.AddUser(user.Username, user.DisplayName, "password", user.Email, user.Active, user.DateTime); prov.AddUser("zzzz", null, "password2", "*****@*****.**", false, DateTime.UtcNow); // Set new password UserInfo expected = new UserInfo(user.Username, "New Display", "*****@*****.**", true, user.DateTime, prov); UserInfo result = prov.ModifyUser(user, "New Display", "newpass", "*****@*****.**", true); AssertUserInfosAreEqual(expected, result, true); UserInfo[] allUsers = prov.GetUsers(); Assert.AreEqual(2, allUsers.Length, "Wrong user count"); Array.Sort(allUsers, delegate(UserInfo x, UserInfo y) { return(x.Username.CompareTo(y.Username)); }); AssertUserInfosAreEqual(expected, allUsers[0], true); Assert.IsTrue(prov.TestAccount(user, "newpass"), "TestAccount should return true"); // Set null display name expected = new UserInfo(user.Username, null, "*****@*****.**", true, user.DateTime, prov); result = prov.ModifyUser(user, null, null, "*****@*****.**", true); AssertUserInfosAreEqual(expected, result, true); allUsers = prov.GetUsers(); Assert.AreEqual(2, allUsers.Length, "Wrong user count"); Array.Sort(allUsers, delegate(UserInfo x, UserInfo y) { return(x.Username.CompareTo(y.Username)); }); AssertUserInfosAreEqual(expected, allUsers[0], true); Assert.IsTrue(prov.TestAccount(user, "newpass"), "TestAccount should return true"); }
public void ModifyUser_InvalidNewEmail(string e) { IUsersStorageProviderV40 prov = GetProvider(); UserInfo user = new UserInfo("username", null, "*****@*****.**", true, DateTime.Now, prov); prov.AddUser(user.Username, user.DisplayName, "password", user.Email, user.Active, user.DateTime); prov.ModifyUser(user, "Display Name", null, e, false); }
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"); }
public void ModifyUser_NullUser() { IUsersStorageProviderV40 prov = GetProvider(); prov.ModifyUser(null, "Display Name", null, "*****@*****.**", true); }