Пример #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"));
            }
        }
 public override void CreateRole(string roleName)
 {
     using(var session = this.DocumentStore.OpenSession())
     {
         try
         {
             var role = new Role(this.ApplicationName, roleName);
             session.Store(role);
             session.SaveChanges();
         }
         catch(Exception ex)
         {
             this.LogException(ex);
             throw;
         }
     }
 }
Пример #3
0
        public void StoreRoleWithApplicationName()
        {
            var newRole = new Role("Users", null);
            newRole.ApplicationName = "MyApplication";

            using (var store = NewInMemoryStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(newRole);
                    session.SaveChanges();
                }

                Thread.Sleep(500);

                using (var session = store.OpenSession())
                {
                    var role = session.Query<Role>().FirstOrDefault();
                    Assert.NotNull(role);
                    Assert.Equal("authorization/roles/myapplication/users", role.Id.ToLowerInvariant());
                }
            }
        }
Пример #4
0
        public void RoleExists()
        {
            var appName = "APPNAME";
            var newRole = new Role("TheRole", null);
            newRole.ApplicationName = appName;

            using (var store = NewInMemoryStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(newRole);
                    session.SaveChanges();
                }

                Thread.Sleep(500);

                var provider = new RavenDBRoleProvider();
                provider.DocumentStore = store;
                provider.ApplicationName = appName;
                Assert.True(provider.RoleExists("TheRole"));
            }
        }