Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        public void AddUser_GetUsers()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo u1 = new UserInfo("user", "User", "*****@*****.**", true, DateTime.UtcNow.AddDays(-1), prov);
            UserInfo u2 = new UserInfo("john", null, "*****@*****.**", false, DateTime.UtcNow, prov);

            UserInfo u1Out = prov.AddUser(u1.Username, u1.DisplayName, "password", u1.Email, u1.Active, u1.DateTime);

            Assert.IsNotNull(u1Out, "AddUser should return something");
            AssertUserInfosAreEqual(u1, u1Out, true);

            UserInfo u2Out = prov.AddUser(u2.Username, u2.DisplayName, "password", u2.Email, u2.Active, u2.DateTime);

            Assert.IsNotNull(u2Out, "AddUser should return something");
            AssertUserInfosAreEqual(u2, u2Out, true);

            Assert.IsNull(prov.AddUser("user", null, "pwd999", "*****@*****.**", false, DateTime.UtcNow), "AddUser should return false");

            UserInfo[] users = prov.GetUsers();
            Array.Sort(users, delegate(UserInfo x, UserInfo y) { return(x.Username.CompareTo(y.Username)); });

            Assert.AreEqual(2, users.Length, "Wrong user count");

            AssertUserInfosAreEqual(u2, users[0], true);
            AssertUserInfosAreEqual(u1, users[1], true);
        }
Esempio n. 3
0
        public void RemoveUser()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo user = prov.AddUser("user", null, "password", "*****@*****.**", false, DateTime.Now);

            Assert.IsFalse(prov.RemoveUser(new UserInfo("user1", "Joe", "*****@*****.**", false, DateTime.Now, prov)), "RemoveUser should return false");

            Assert.IsTrue(prov.RemoveUser(user), "RemoveUser should return true");

            Assert.AreEqual(0, prov.GetUsers().Length, "Wrong user count");
        }
Esempio 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");
        }