public void TestAddUsersToRoles()
        {
            var membershipConfig = new NameValueCollection(_membershipConfig);
            var roleConfig = new NameValueCollection(_roleConfig);

            var membershipProvider = new MongoMembershipProvider();
            membershipProvider.Initialize(DefaultMembershipName, membershipConfig);

            var roleProvider = new MongoRoleProvider();
            roleProvider.Initialize(DefaultRoleName, roleConfig);

            MembershipCreateStatus status;
            membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status);
            membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status);

            roleProvider.CreateRole("role1");
            roleProvider.CreateRole("role2");

            roleProvider.AddUsersToRoles(new[] { "user1", "user2" }, new[] { "role1", "role2" });
            Assert.IsTrue(roleProvider.IsUserInRole("user1", "role1"));
            Assert.IsTrue(roleProvider.IsUserInRole("user1", "role2"));
            Assert.IsTrue(roleProvider.IsUserInRole("user2", "role1"));
            Assert.IsTrue(roleProvider.IsUserInRole("user2", "role2"));
        }
        public void TestIsUserInRoleWhenUserDoesNotExist()
        {
            var roleConfig = new NameValueCollection(_roleConfig);

            var roleProvider = new MongoRoleProvider();
            roleProvider.Initialize(DefaultRoleName, roleConfig);
            roleProvider.CreateRole("role1");

            Assert.Throws<ArgumentException>(() => roleProvider.IsUserInRole("user1", "role1"));
        }
        public void TestIsUserInRoleWhenRoleDoesNotExist()
        {
            var membershipConfig = new NameValueCollection(_membershipConfig);
            var roleConfig = new NameValueCollection(_roleConfig);

            var membershipProvider = new MongoMembershipProvider();
            membershipProvider.Initialize(DefaultMembershipName, membershipConfig);

            var roleProvider = new MongoRoleProvider();
            roleProvider.Initialize(DefaultRoleName, roleConfig);

            MembershipCreateStatus status;
            membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status);

            Assert.Throws<ArgumentException>(() => roleProvider.IsUserInRole("user1", "role1"));
        }
        public void TestDeleteRoleWhenPopulatedWithNoThrowOnPopulated()
        {
            var membershipConfig = new NameValueCollection(_membershipConfig);
            var roleConfig = new NameValueCollection(_roleConfig);

            var membershipProvider = new MongoMembershipProvider();
            membershipProvider.Initialize(DefaultMembershipName, membershipConfig);

            var roleProvider = new MongoRoleProvider();
            roleProvider.Initialize(DefaultRoleName, roleConfig);

            MembershipCreateStatus status;
            membershipProvider.CreateUser("user1", "123456", "*****@*****.**", null, null, true, null, out status);
            membershipProvider.CreateUser("user2", "123456", "*****@*****.**", null, null, true, null, out status);

            roleProvider.CreateRole("role1");
            roleProvider.CreateRole("role2");

            roleProvider.AddUsersToRoles(new[] { "user1", "user2" }, new[] { "role1", "role2" });

            roleProvider.DeleteRole("role1", false);
            Assert.IsFalse(roleProvider.RoleExists("role1"));
            Assert.Throws<ArgumentException>(() => roleProvider.IsUserInRole("user1", "role1"));
        }