예제 #1
0
        public void RemoveUsersFromRoles()
        {
            var roles = new Role[] { new Role("Role 1", null), new Role("Role 2", null), new Role("Role 3", null) };
            var user  = UserTests.CreateDummyUser();

            user.Username = "******";

            using (var store = NewInMemoryStore())
            {
                using (var session = store.OpenSession())
                {
                    foreach (var role in roles)
                    {
                        session.Store(role);
                    }
                    session.Store(user);
                    session.SaveChanges();
                }

                Thread.Sleep(500);

                var provider = new RavenDBRoleProvider();
                provider.DocumentStore = store;
                provider.AddUsersToRoles(new [] { user.Username }, new [] { "Role 1", "Role 2" });

                Assert.True(provider.IsUserInRole(user.Username, "Role 1"));
                Assert.True(provider.IsUserInRole(user.Username, "Role 2"));

                provider.RemoveUsersFromRoles(new[] { user.Username }, new[] { "Role 1" });

                Assert.False(provider.IsUserInRole(user.Username, "Role 1"));
                Assert.True(provider.IsUserInRole(user.Username, "Role 2"));
            }
        }
예제 #2
0
        public void FindUsersInRole_returns_users_in_role()
        {
            var roles = _testRoles;

            for (int i = 0; i < roles.Length; i++)
            {
                roles[i].ApplicationName = _appName;
            }
            var user = new User();

            user.Username        = _testUserName;
            user.ApplicationName = _appName;

            using (var store = NewInMemoryStore())
            {
                //Arrange
                store.Initialize();
                using (var session = store.OpenSession())
                {
                    foreach (var role in roles)
                    {
                        session.Store(role);
                    }
                    session.Store(user);
                    session.SaveChanges();
                }

                var provider = new RavenDBRoleProvider();
                RavenDBRoleProvider.DocumentStore = store;
                provider.ApplicationName          = _appName;
                provider.AddUsersToRoles(new[] { user.Username }, new[] { "Role 1", "Role 2" });

                //Act
                string[] users = provider.FindUsersInRole("Role 1", user.Username);

                //Assert
                Assert.True(users.Contains(user.Username));
            }
        }
예제 #3
0
        public void AddUsersToRoles()
        {
            var roles = _testRoles;

            for (int i = 0; i < roles.Length; i++)
            {
                roles[i].ApplicationName = _appName;
            }
            var user = new User();

            user.Username        = _testUserName;
            user.ApplicationName = _appName;

            using (var store = NewInMemoryStore())
            {
                store.Initialize();
                using (var session = store.OpenSession())
                {
                    foreach (var role in roles)
                    {
                        session.Store(role);
                    }
                    session.Store(user);
                    session.SaveChanges();
                }

                var provider = new RavenDBRoleProvider();
                RavenDBRoleProvider.DocumentStore = store;
                provider.ApplicationName          = _appName;
                provider.AddUsersToRoles(new [] { user.Username }, new [] { "Role 1", "Role 2" });

                using (var session = store.OpenSession())
                {
                    var u = session.Query <User>().Where(x => x.Username == user.Username && x.ApplicationName == user.ApplicationName).FirstOrDefault();
                    Assert.True(u.Roles.Any(x => x.ToLower().Contains("role 1")));
                    Assert.False(u.Roles.Any(x => x.ToLower().Contains("role 3")));
                }
            }
        }
예제 #4
0
        public void GetRolesForUser_returns_roles_for_given_users()
        {
            var roles = _testRoles;

            for (int i = 0; i < roles.Length; i++)
            {
                roles[i].ApplicationName = _appName;
            }
            var user = new User();

            user.Username        = _testUserName;
            user.ApplicationName = _appName;

            using (var store = NewInMemoryStore())
            {
                store.Initialize();
                using (var session = store.OpenSession())
                {
                    foreach (var role in roles)
                    {
                        session.Store(role);
                    }
                    session.Store(user);
                    session.SaveChanges();
                }

                var provider = new RavenDBRoleProvider();
                RavenDBRoleProvider.DocumentStore = store;
                provider.ApplicationName          = _appName;
                provider.AddUsersToRoles(new[] { user.Username }, new[] { "Role 1", "Role 2" });

                string[] returnedRoles = provider.GetRolesForUser(user.Username);

                Assert.True(returnedRoles.Contains("Role 1") && returnedRoles.Contains("Role 2") && !returnedRoles.Contains("Role 3"));
            }
        }