Пример #1
0
        public void GetUsersInRoleTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            AddUser("eve4", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2", "eve3", "eve4" },
                                         new string[] { "User" });
            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2" },
                                         new string[] { "Editor" });
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Administrator" });

            var users   = roleProvider.GetUsersInRole("User");
            var editors = roleProvider.GetUsersInRole("Editor");
            var admins  = roleProvider.GetUsersInRole("Administrator");


            Assert.AreEqual(4, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("eve2"));
            Assert.IsTrue(users.Contains("eve3"));
            Assert.IsTrue(users.Contains("eve4"));

            Assert.AreEqual(2, editors.Length);
            Assert.IsTrue(editors.Contains("eve"));
            Assert.IsTrue(editors.Contains("eve2"));
            Assert.IsFalse(editors.Contains("eve3"));
            Assert.IsFalse(editors.Contains("eve4"));

            Assert.AreEqual(1, admins.Length);
            Assert.IsTrue(admins.Contains("eve"));
            Assert.IsFalse(admins.Contains("eve2"));
            Assert.IsFalse(admins.Contains("eve3"));
            Assert.IsFalse(admins.Contains("eve4"));
        }
Пример #2
0
        public void GetUsersInRoleTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            AddUser("eve4", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2", "eve3", "eve4" },
                new string[] { "User" });
            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2" },
                new string[] { "Editor" });
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                new string[] { "Administrator" });

            var users = roleProvider.GetUsersInRole("User");
            var editors = roleProvider.GetUsersInRole("Editor");
            var admins = roleProvider.GetUsersInRole("Administrator");

            Assert.AreEqual(4, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("eve2"));
            Assert.IsTrue(users.Contains("eve3"));
            Assert.IsTrue(users.Contains("eve4"));

            Assert.AreEqual(2, editors.Length);
            Assert.IsTrue(editors.Contains("eve"));
            Assert.IsTrue(editors.Contains("eve2"));
            Assert.IsFalse(editors.Contains("eve3"));
            Assert.IsFalse(editors.Contains("eve4"));

            Assert.AreEqual(1, admins.Length);
            Assert.IsTrue(admins.Contains("eve"));
            Assert.IsFalse(admins.Contains("eve2"));
            Assert.IsFalse(admins.Contains("eve3"));
            Assert.IsFalse(admins.Contains("eve4"));
        }