Пример #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 RemoveUsersFromRoles()
        {
            var roles = _testRoles;
            var user = new User();
            user.Username = _testUserName;
            user.ApplicationName = _appName;

            using (var store = NewInMemoryStore())
            {
                //Arrange
                using (var session = store.OpenSession())
                {
                    foreach (var role in roles)
                    {
                        role.ApplicationName = _appName;
                        session.Store(role);
                        user.Roles.Add(role.Id.ToLower().ToLower());
                    }
                    session.Store(user);
                    session.SaveChanges();
                }

                var provider = new RavenDBRoleProvider();
                provider.ApplicationName = _appName;
                RavenDBRoleProvider.DocumentStore = store;

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

                //Assert
                using (var session = store.OpenSession())
                {
                    var u = session.Query<User>().Where(x => x.Username == _testUserName && x.ApplicationName == _appName).FirstOrDefault();
                    Assert.False(u.Roles.Any(x => x.ToLower() == "role 1"));
                    Assert.True(u.Roles.Any(x => x.ToLower() != "role 2"));
                }
            }
        }