예제 #1
0
 public void Can_Create_User()
 {
     var newUser = new User()
     {
         FirstName = "New User",
         LastName = "Galore",
         Email = "*****@*****.**",
         UserName = "******",
         EmailConfirmed = true
     };
     userManager.Create(newUser, "testpass");
     Assert.IsNotNull(userManager.Find("testuser", "testpass"));
     userManager.Delete(newUser);
 }
        public void Can_Add_User_To_Group()
        {
            var existingUser = userManager.FindByName("testuser");
            if(existingUser != null)
                userManager.Delete(existingUser);

            var existingGroup = groupManager.GetByName("Group A");
            if(existingGroup != null)
                groupManager.Delete(existingGroup.Id);

            var newUser = new User()
            {
                FirstName = "Test",
                LastName = "User",
                EmailConfirmed = true,
                Email = "*****@*****.**",
                UserName = "******"
            };
            userManager.Create(newUser, "password");

            var group = new Group() {Name = "Group A"};
            groupManager.Create(group);

            Assert.IsTrue(groupManager.AddUser(group.Id, newUser.Id));

            var groupUsers = groupManager.GetById(group.Id, new List<string>() {"Users"}).Users;
            Console.WriteLine("Group: " + group.Name + " Has the following assigned Users!");
            foreach (var groupUser in groupUsers)
            {
                Console.WriteLine("UserID: " + groupUser.Id);
                Console.WriteLine("Name: " + groupUser.FirstName + " " + groupUser.LastName);
            }

            userManager.Delete(newUser);
            groupManager.Delete(group.Id);
        }
        public void Can_Get_My_Child_Groups()
        {
            var existingUser = userManager.FindByName("testuser");
            if (existingUser != null)
                userManager.Delete(existingUser);

            var existingGroup = groupManager.GetByName("Group A");
            if (existingGroup != null)
                groupManager.Delete(existingGroup.Id);

            var existingGroup1 = groupManager.GetByName("Group B");
            if (existingGroup1 != null)
                groupManager.Delete(existingGroup1.Id);

            var newUser = new User()
            {
                FirstName = "Test",
                LastName = "User",
                EmailConfirmed = true,
                Email = "*****@*****.**",
                UserName = "******"
            };
            userManager.Create(newUser, "password");

            var group = new Group() { Name = "Group A" };
            groupManager.Create(group);

            var group1 = new Group() {Name = "Group B"};
            groupManager.Create(group1);

            groupManager.AssignParent(group1, group);

            Assert.IsTrue(groupManager.AddUser(group.Id, newUser.Id));

            var userGroups = userManager.GetById(newUser.Id, new List<string>() {"Groups", "Groups.ChildGroups"});
            var allMyGroups = new List<Group>();
            foreach (var myGroup in userGroups.Groups)
            {
                allMyGroups.Add(myGroup);
                allMyGroups.AddRange(myGroup.ChildGroups);
            }

            Console.WriteLine("All My Groups I Can View Below!");
            foreach (var allMyGroup in allMyGroups)
                Console.WriteLine("Group Name: " + allMyGroup.Name);

            userManager.Delete(newUser);
            groupManager.Delete(group.Id);
            groupManager.Delete(group1.Id);
        }