Пример #1
0
        public void SignUp()
        {
            ISecurityProvider Provider = new SecurityProvider(Context);

            var user = Provider.SignUp("testUser", "Mr", "James", "Bond", "password@1","*****@*****.**");

            user.ShouldNotBeNull();
            user.Id.ShouldBeGreaterThan(0);
        }
Пример #2
0
        public void SaveRole()
        {
            var role = SeedData.CreateAdmin(Context);
            ISecurityProvider provider = new SecurityProvider(Context, role);
            var privileges = SeedData.GetPrivileges(Context).Select(a => a.Security).ToList();
            var createRole = provider.SaveRole(null, "James", "MVP-role test", 0, privileges);

            createRole.RoleName.ShouldEqual("James");
            createRole.Privileges.Count().ShouldBeGreaterThan(0);
        }
Пример #3
0
        public void GetRoles()
        {
            var admin = SeedData.CreateAdmin(Context);
            ISecurityProvider provider = new SecurityProvider(Context, admin);
            var role = SeedData.CreateRole(Context, "Code Auditor");

            var getRole = provider.GetRoles().Count();

            getRole.ShouldBeGreaterThan(0);
        }
Пример #4
0
        public void UserLogin()
        {
            ISecurityProvider Provider = new SecurityProvider(Context);
            var testUser = SeedData.CreateUser(Context, "testUser", "password@1");

            var user = Provider.UserLogin(testUser.UserName, "password@1");

            user.ShouldNotBeNull();
            user.UserName.ShouldEqual(testUser.UserName);
            user.AllowedPrivileges.ShouldNotBeNull();
            Provider.CurrentUser.ShouldNotBeNull();
        }
Пример #5
0
        public static ICurrentUser CreateAdmin(DataContext context, string userName = "******", string password = "******")
        {
            var result = CreateUser(context, userName, password);
            var role = CreateRole(context);
            var currentUser = result.Roles.Where(a => a.RoleName == role.RoleName).SingleOrDefault();

            if (currentUser == null)
            {
                result.Roles.Add(role);
                context.SaveChanges();
            }

            var qPrivs = from userP in context.UserIdentitySet
                         from r in userP.Roles
                         from privileges in r.Privileges
                         where userP.Id == result.Id
                         select privileges.Security;
            result.AllowedPrivileges = qPrivs.Distinct().ToList();

            var provider = new SecurityProvider(context);
            return provider.UserIdentityToCurrentUser(result);
        }
Пример #6
0
 public UserController()
 {
     Context = new DataContext();
     SecurityProvider = new SecurityProvider(Context, CurrentUser);
 }
Пример #7
0
        public void UserLoginFailed()
        {
            ISecurityProvider Provider = new SecurityProvider(Context);

            var testUser = SeedData.CreateUser(Context,"test","password@1","Mr","Bond","James","*****@*****.**");

            var user = Provider.UserLogin(testUser.UserName, "password@1");
            user.ShouldNotBeNull();
        }
Пример #8
0
 public AccountController()
 {
     Context = new DataContext();
     _DisposeContext = true;
     SecurityProvider = new SecurityProvider(Context, CurrentUser);
 }