예제 #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");
        }
예제 #2
0
        public void GetUsersWithData()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo user1 = prov.AddUser("user1", "User1", "password", "*****@*****.**", true, DateTime.UtcNow);
            UserInfo user2 = prov.AddUser("user2", "User2", "password", "*****@*****.**", true, DateTime.UtcNow);
            UserInfo user3 = prov.AddUser("user3", "User3", "password", "*****@*****.**", true, DateTime.UtcNow);
            UserInfo user4 = prov.AddUser("user4", "User4", "password", "*****@*****.**", true, DateTime.UtcNow);

            Assert.AreEqual(0, prov.GetUsersWithData("Key").Count, "Wrong user count");

            prov.StoreUserData(user1, "Key", "Value");
            prov.StoreUserData(user2, "Key2", "Value");
            prov.StoreUserData(user4, "Key", "Value2");

            IDictionary <UserInfo, string> data = prov.GetUsersWithData("Key");

            Assert.AreEqual(2, data.Count, "Wrong user count");

            UserInfo[] users = new UserInfo[data.Count];
            data.Keys.CopyTo(users, 0);

            AssertUserInfosAreEqual(user1, users[0], true);
            AssertUserInfosAreEqual(user4, users[1], true);

            Assert.AreEqual("Value", data[users[0]], "Wrong data");
            Assert.AreEqual("Value2", data[users[1]], "Wrong data");
        }
예제 #3
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);
        }
예제 #4
0
        public void GetUserByEmail()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo user1 = prov.AddUser("user1", null, "password", "*****@*****.**", true, DateTime.UtcNow);
            UserInfo user2 = prov.AddUser("user2", null, "password", "*****@*****.**", true, DateTime.UtcNow);

            Assert.IsNull(prov.GetUserByEmail("*****@*****.**"), "TryGetUserByEmail should return null");

            UserInfo output = prov.GetUserByEmail("*****@*****.**");

            AssertUserInfosAreEqual(user1, output, true);
        }
예제 #5
0
        public void TestAccount()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo u1 = prov.AddUser("user1", null, "password", "*****@*****.**", true, DateTime.Now);
            UserInfo u2 = prov.AddUser("user2", "User", "password", "*****@*****.**", false, DateTime.Now);

            Assert.IsTrue(prov.TestAccount(u1, "password"), "TestAccount should return true");
            Assert.IsFalse(prov.TestAccount(new UserInfo(u1.Username.ToUpperInvariant(), null, "*****@*****.**", true, DateTime.Now, prov), "password"), "TestAccount should return false");
            Assert.IsFalse(prov.TestAccount(u2, "password"), "TestAccount should return false because the account is disabled");
            Assert.IsFalse(prov.TestAccount(new UserInfo("blah", null, "*****@*****.**", true, DateTime.Now, prov), "blah"), "TestAccount should return false");
            Assert.IsFalse(prov.TestAccount(u1, "password222"), "TestAccount should return false");
            Assert.IsFalse(prov.TestAccount(u1, ""), "TestAccount should return false");
        }
예제 #6
0
        public void TryManualLogin_NullPassword()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.AddUser("user", null, "password", "*****@*****.**", true, DateTime.Now);
            prov.TryManualLogin("user", null);
        }
예제 #7
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);
        }
예제 #8
0
        public void RetrieveUserData_InvalidKey(string k)
        {
            IUsersStorageProviderV40 prov = GetProvider();

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

            prov.RetrieveUserData(user, k);
        }
예제 #9
0
        public void RetrieveUserData_InexistentKey()
        {
            IUsersStorageProviderV40 prov = GetProvider();

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

            Assert.IsNull(prov.RetrieveUserData(user, "Inexistent"), "RetrieveUserData should return null");
        }
예제 #10
0
        public void StoreUserData_RetrieveUserData_RemoveUser()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo user  = prov.AddUser("User", "User", "password", "*****@*****.**", true, DateTime.Now);
            UserInfo user2 = prov.AddUser("User2", "User2", "password2", "*****@*****.**", true, DateTime.Now);

            Assert.IsTrue(prov.StoreUserData(user, "Key", "Value"), "StoreUserData should return true");
            Assert.IsTrue(prov.StoreUserData(user2, "Key", "Value"), "StoreUserData should return true");
            prov.RemoveUser(user);

            string value = prov.RetrieveUserData(user, "Key");

            Assert.IsNull(value, "Wrong value");
            string value2 = prov.RetrieveUserData(user2, "Key");

            Assert.AreEqual(value2, "Value", "Wrong value");
        }
예제 #11
0
        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);
        }
예제 #12
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");
        }
예제 #13
0
        public void RetrieveAllUserData()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            Assert.AreEqual(0, prov.RetrieveAllUserData(new UserInfo("Inexistent", "Inex", "*****@*****.**", true, DateTime.Now, prov)).Count, "Wrong data count");

            UserInfo user1 = prov.AddUser("user1", "User1", "password", "*****@*****.**", true, DateTime.Now);
            UserInfo user2 = prov.AddUser("user2", "User2", "password", "*****@*****.**", true, DateTime.Now);

            Assert.AreEqual(0, prov.RetrieveAllUserData(user1).Count, "Wrong data count");

            prov.StoreUserData(user1, "Key", "Value");
            prov.StoreUserData(user1, "Key2", "Value2");
            prov.StoreUserData(user2, "Key", "Value3");

            IDictionary <string, string> data = prov.RetrieveAllUserData(user1);

            Assert.AreEqual(2, data.Count, "Wrong data count");
            Assert.AreEqual("Value", data["Key"], "Wrong data");
            Assert.AreEqual("Value2", data["Key2"], "Wrong data");
        }
예제 #14
0
        public void TryManualLogin()
        {
            IUsersStorageProviderV40 prov = GetProvider();

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

            prov.AddUser("user2", null, "password", "*****@*****.**", false, DateTime.UtcNow);

            UserInfo output = prov.TryManualLogin("inexistent", "password");

            Assert.IsNull(output, "TryManualLogin should return null");

            output = prov.TryManualLogin("inexistent", "");
            Assert.IsNull(output, "TryManualLogin should return null");

            output = prov.TryManualLogin("", "password");
            Assert.IsNull(output, "TryManualLogin should return null");

            output = prov.TryManualLogin("user2", "password");
            Assert.IsNull(output, "TryManualLogin should return null because the account is inactive");

            output = prov.TryManualLogin("user", "password");
            AssertUserInfosAreEqual(user, output, true);
        }
예제 #15
0
        public void StoreUserData_RetrieveUserData()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            UserInfo user = new UserInfo("User", "User", "*****@*****.**", true, DateTime.Now, prov);

            Assert.IsFalse(prov.StoreUserData(user, "Key", "Value"), "StoreUserData should return false");

            user = prov.AddUser("User", "User", "password", "*****@*****.**", true, DateTime.Now);

            Assert.IsTrue(prov.StoreUserData(user, "Key", "Value"), "StoreUserData should return true");
            Assert.IsTrue(prov.StoreUserData(user, "Key2", "Value2"), "StoreUserData should return true");
            string value = prov.RetrieveUserData(user, "Key");

            Assert.AreEqual("Value", value, "Wrong value");
            string value2 = prov.RetrieveUserData(user, "Key2");

            Assert.AreEqual("Value2", value2, "Wrong value");
        }
예제 #16
0
        public void AddUser_InvalidUsername(string u)
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.AddUser(u, null, "pass", "*****@*****.**", true, DateTime.Now);
        }
예제 #17
0
        public void AddUser_InvalidEmail(string e)
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.AddUser("user", null, "pass", e, true, DateTime.Now);
        }
예제 #18
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");
        }
예제 #19
0
        public void SetUserMembership_NullGroups()
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.SetUserMembership(prov.AddUser("user", "user", "pass", "*****@*****.**", true, DateTime.Now), null);
        }
예제 #20
0
        public void AddUser_InvalidPassword(string p)
        {
            IUsersStorageProviderV40 prov = GetProvider();

            prov.AddUser("user", null, p, "*****@*****.**", true, DateTime.Now);
        }