private UserInfo ConverToUser(DirectoryEntry userEntry) { if (userEntry == null) { return(null); } var account = GetEntryPropertyValue(userEntry, "SAMAccountName"); UserInfo userInfo = UserInfoRepo .Read() .FirstOrDefault(ui => ui.Account != null && ui.Account.ToLower() == account.ToLower()); if (userInfo == null) { userInfo = new UserInfo(); userInfo.Id = StringFactory.NewGuid(); userInfo.IsActive = true; } userInfo.Account = account; userInfo.Name = GetEntryPropertyValue(userEntry, "DisplayName") ?? GetEntryPropertyValue(userEntry, "Name") ?? userInfo.Account; userInfo.Email = GetEntryPropertyValue(userEntry, "Mail") ?? ""; userEntry.Dispose(); return(userInfo); }
public void Save() { Organization org = Organization.Create(); org.Code = StringFactory.NewGuid(); org.Name = "org-test-name"; org.FullName = "org-test-fullname"; org.Save(); Position position = Position.Create(); position.Code = StringFactory.NewGuid(); position.OrganizationId = org.Id; position.Name = "test-add-Postion"; Position position1 = Position.GetPosition(org.Code, position.Code); Assert.IsNull(position1); position.Save(); Position position2 = Position.GetPosition(org.Code, position.Code); Assert.IsNotNull(position2); position.Delete(); position2.Delete(); org.Delete(); }
public void RemoveTarget() { Target target = Target.Create(); target.Code = StringFactory.NewGuid(); App app = App.Create(); app.Save(); app.AddTarget(target); App app1 = App.GetApp(app.Key); Assert.AreEqual(1, app1.TargetList.Count); app1.RemoveTarget(target); App app2 = App.GetApp(app1.Key); Assert.AreEqual(0, app1.TargetList.Count); app.Delete(); target.Delete(); }
public void GiveRole() { Role role = Role.Create(); role.Name = "test-role-add"; role.IsActive = true; role.Save(); Organization org = Organization.Create(); org.Code = StringFactory.NewGuid(); org.Name = "org-test-name"; org.FullName = "org-test-fullname"; org.Save(); Position position = Position.Create(); position.Code = StringFactory.NewGuid(); position.OrganizationId = org.Id; position.Name = "test-add-Postion"; position.Save(); position.GiveRole(role); var position1 = Position.GetPosition(org.Code, position.Code); Assert.AreEqual(1, position1.RoleList.Count); role.Delete(); position.CancelRole(role); position.Delete(); org.Delete(); }
public void DeepUserList() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); User user1 = new User(); user1.Account = "test-user-add" + StringFactory.NewGuid().Substring(0, 4); user1.IsActive = true; user1.Save(); org1.AddUser(user1); Organization org2 = Organization.GetOrganization(org1.Code); Assert.IsNotNull(org2); Assert.AreNotEqual(0, org2.DeepUserList.Count); org1.Delete(); org1.RemoveUser(user1); user1.Delete(); }
public void GetApp() { App app = App.Create(); app.Save(); Target target = Target.Create(); target.Code = StringFactory.NewGuid(); target.AppId = app.Key; app.AddTarget(target); Target target1 = Target.GetTargetById(target.Id); Operation operation = new Operation(); target1.AddOperation(operation); Operation operation1 = Operation.GetOperationById(operation.Id); Assert.IsNotNull(operation1); App app1 = operation1.GetApp(); Assert.IsNotNull(app1); app.RemoveTarget(target); app.Delete(); target.RemoveOperation(operation); }
public void GetDeepTargetOperationList() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); Role role = Role.Create(); role.Code = StringFactory.NewGuid(); role.Save(); org1.GiveRole(role); Operation operation = new Operation(); operation.AppId = StringFactory.NewGuid(); operation.Code = StringFactory.NewGuid(); operation.TargetId = StringFactory.NewGuid(); role.GivePermission(operation); Organization org2 = Organization.GetOrganization(org1.Code); Assert.IsNotNull(org2); Assert.IsNotNull(org2.DeepOperationList); org1.Delete(); org1.CancelRole(role); role.CancelPermission(operation); role.Delete(); }
public void Delete() { Organization org = Organization.Create(); org.Code = StringFactory.NewGuid(); org.Name = "org-test-name"; org.FullName = "org-test-fullname"; org.Save(); Position position = Position.Create(); position.Code = StringFactory.NewGuid(); position.OrganizationId = org.Id; position.Name = "test-add-Postion"; position.Save(); User user = User.Create(); user.Account = "test-add-user" + StringFactory.NewGuid().Substring(0, 5); user.Save(); position.AddUser(user); Position postion1 = Position.GetPosition(org.Code, position.Code); Assert.IsNotNull(postion1); postion1.Delete(); Position position2 = Position.GetPosition(org.Code, postion1.Code); Assert.IsNull(position2); org.Delete(); user.Delete(); }
public void Delete() { App app = App.Create(); app.Save(); Target target = Target.Create(); target.Code = StringFactory.NewGuid(); target.Name = "test-target-add"; app.AddTarget(target); Target target1 = Target.GetTargetById(target.Id); Assert.IsNotNull(target1); Operation operation = new Operation(); operation.Code = StringFactory.NewGuid(); target1.AddOperation(operation); target.Delete(); Assert.AreEqual(0, Operation.GetOperationList().Where(o => o.Id == operation.Id).ToList().Count()); app.Delete(); }
public void CancelPermission() { Role role = Role.Create(); role.Name = "test-role-add"; role.Save(); Operation targetoperation = new Operation(); targetoperation.Code = StringFactory.NewGuid(); targetoperation.AppId = StringFactory.NewGuid(); targetoperation.TargetId = StringFactory.NewGuid(); targetoperation.Name = "test-add-RoleTargetOperation"; role.GivePermission(targetoperation); var roletarget = role.OperationList; Assert.IsNotNull(roletarget); role.CancelPermission(targetoperation); var newroletarget = role.OperationList; Assert.AreEqual(0, newroletarget.Count); role.Delete(); }
public void AddChild() { Organization org = Organization.Create(); org.Code = StringFactory.NewGuid(); org.Name = "org-test-name"; org.FullName = "org-test-fullname"; org.Save(); Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); org.AddChild(org1); Organization org2 = Organization.GetOrganization(org.Code); Assert.IsNotNull(org2.Children.FirstOrDefault(o => o.Code == org1.Code)); org.Delete(); org1.Delete(); org2.Delete(); }
public void CancelRole() { User user = new User(); user.Name = "test-add-user"; user.Account = StringFactory.NewGuid(); user.Save(); Role role = Role.Create(); role.Code = StringFactory.NewGuid(); role.Name = "test-giverole-role"; role.Save(); user.GiveRole(role); User user1 = User.GetUser(user.Account); var user2 = user1.RoleList.Where(r => r.Code == role.Code).ToList(); Assert.AreEqual(1, user2.Count); user1.CancelRole(role); var user3 = user1.RoleList.Where(r => r.Code == role.Code).ToList(); Assert.AreEqual(0, user3.Count); role.Delete(); user.Delete(); }
public void GetDeepRoleList() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); Role role = Role.Create(); role.Code = StringFactory.NewGuid(); role.Name = "test-role-add"; role.Save(); org1.GiveRole(role); Organization org2 = Organization.GetOrganization(org1.Code); Assert.IsNotNull(org2); Assert.AreEqual(1, org2.DeepRoleList.Where(ro => ro.Code == role.Code).ToList().Count); org1.Delete(); org1.CancelRole(role); role.Delete(); }
public void GetOperationList() { App app = App.Create(); app.Save(); Target target = Target.Create(); target.Code = StringFactory.NewGuid(); target.AppId = app.Id; app.AddTarget(target); Target target1 = Target.GetTargetById(target.Id); Operation operation = new Operation(); target1.AddOperation(operation); var list = Operation.GetOperationList().Where(o => o.AppId == app.Id && o.TargetId == target.Id).ToList(); Assert.AreEqual(1, list.Count()); app.RemoveTarget(target); app.Delete(); target.RemoveOperation(operation); }
public void AddUser() { User user = new User(); user.Account = "test-adduser-" + StringFactory.NewGuid().Substring(0, 4); user.Name = "test-add-user"; user.IsActive = true; user.Save(); Organization org = Organization.Create(); org.Code = StringFactory.NewGuid(); org.Name = "org-test-name"; org.FullName = "org-test-fullname"; org.Save(); Position position = Position.Create(); position.Code = StringFactory.NewGuid(); position.OrganizationId = org.Id; position.Name = "test-add-Postion"; position.Save(); position.AddUser(user); var userInfo = position.UserList.FirstOrDefault(u => u.Account == user.Account); Assert.IsNotNull(userInfo); user.Delete(); position.RemoveUser(user); position.Delete(); org.Delete(); }
public void CancelRole() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); Role role = Role.Create(); role.Code = StringFactory.NewGuid(); role.Name = "test-add-role"; role.Save(); org1.GiveRole(role); var roleorg = org1.RoleList.FirstOrDefault(ro => ro.Code == role.Code); Assert.IsNotNull(roleorg); org1.CancelRole(role); var roleorg1 = org1.RoleList.FirstOrDefault(ro => ro.Code == role.Code); Assert.IsNull(roleorg1); org1.Delete(); role.Delete(); }
public void DeepPositionList() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); Position position = Position.Create(); position.Name = "test-Position-add"; position.Code = StringFactory.NewGuid(); position.OrganizationId = org1.Code; org1.AddPosition(position); Organization org2 = Organization.GetOrganization(org1.Code); Assert.IsNotNull(org2); Assert.AreNotEqual(0, org2.DeepPositionList.Count); org1.Delete(); org1.RemovePosition(position); org2.Delete(); }
public void RemoveUser() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); User user1 = new User(); user1.Account = "test-user-add" + StringFactory.NewGuid().Substring(0, 4); user1.IsActive = true; user1.Save(); org1.AddUser(user1); var positionuser = org1.UserList.Where(pu => pu.Account == user1.Account).ToList(); Assert.AreEqual(1, positionuser.Count); org1.RemoveUser(user1); var positionuser1 = org1.UserList.Where(pu => pu.Account == user1.Account).ToList(); Assert.AreEqual(0, positionuser1.Count); org1.Delete(); user1.Delete(); }
public void DeepChildrenOrg() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); Organization org2 = Organization.Create(); org2.Code = StringFactory.NewGuid(); org2.Name = "org-test-name"; org2.FullName = "org-test-fullname"; org2.Save(); org1.AddChild(org2); Organization org3 = Organization.GetOrganization(org1.Code); Assert.IsNotNull(org3); Assert.IsNotNull(org3.DeepChildren.Where(de => de.Id == org1.Id).ToList()); org1.Delete(); org1.RemoveChild(org2); org2.Delete(); org3.Delete(); }
public void SetParent() { Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); Organization org2 = Organization.Create(); org2.Code = StringFactory.NewGuid(); org2.Name = "org-test-name"; org2.FullName = "org-test-fullname"; org2.Save(); org2.SetParent(org1); Organization org3 = Organization.GetOrganization(org2.Code); Assert.IsNotNull(org3.GetParent()); org1.Delete(); org1.RemoveChild(org2); org2.Delete(); org3.Delete(); }
public void RemoveChild() { Organization org = Organization.Create(); org.Code = StringFactory.NewGuid(); org.Name = "org-test-name"; org.FullName = "org-test-fullname"; org.Save(); Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); org.AddChild(org1); Organization org2 = Organization.GetOrganization(org.Code); Assert.IsNotNull(org2.Children.FirstOrDefault(o => o.Code == org1.Code)); org.RemoveChild(org1); Organization org4 = Organization.GetOrganization(org.Code); var a = org4.Children.Where(o => o.Code == org1.Code).ToList(); Assert.AreEqual(0, a.Count); org.Delete(); org1.Delete(); }
public void DeepOrganizationList() { User user = new User(); user.Account = "test-add-user" + StringFactory.NewGuid().Substring(0, 4); user.Save(); Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.IsActive = true; org1.Save(); Position position = Position.Create(); position.Name = "test-Position-add"; position.Code = StringFactory.NewGuid(); position.OrganizationId = org1.Id; position.Save(); position.AddUser(user); User user1 = User.GetUser(user.Account); Assert.IsNotNull(user1); Assert.AreEqual(1, user1.DeepOrganizationList.Count); user.Delete(); position.RemoveUser(user); position.Delete(); org1.Delete(); }
public void RemoveOperation() { Target target = Target.Create(); target.Code = StringFactory.NewGuid(); target.Name = "test-target-add"; target.AppId = StringFactory.NewGuid(); target.Save(); Operation targetoperation = new Operation(); targetoperation.Name = "test-add-RoleTargetOperation"; targetoperation.Code = StringFactory.NewGuid(); target.AddOperation(targetoperation); Target target1 = Target.GetTargetById(target.Id); Assert.AreEqual(1, target1.OperationList.Count); target.RemoveOperation(targetoperation); Target target2 = Target.GetTargetById(target1.Id); Assert.AreEqual(0, target2.OperationList.Count); target.Delete(); }
/// <summary> /// 构造函数 /// </summary> public static App Create() { App app = new App(); app.Key = StringFactory.NewGuid(); app.Secret = StringFactory.NewGuid(); return(app); }
public void Delete() { App app = App.Create(); app.Save(); //验证Target是否存在 Target target = Target.Create(); target.Code = StringFactory.NewGuid(); app.AddTarget(target); App app1 = App.GetApp(app.Key); Assert.IsNotNull(app1); Assert.AreEqual(1, app1.TargetList.Count); Role role = Role.Create(); role.Name = "test-role-add"; role.Save(); Operation targetoperation = new Operation(); targetoperation.Code = StringFactory.NewGuid(); targetoperation.AppId = StringFactory.NewGuid(); targetoperation.TargetId = StringFactory.NewGuid(); targetoperation.Name = "test-add-RoleTargetOperation"; targetoperation.Save(); target.AddOperation(targetoperation); Target target1 = Target.GetTargetById(target.Id); Assert.IsNotNull(target1.OperationList); App app2 = App.GetApp(app1.Key); Assert.IsNotNull(app2); app2.Delete(); App app3 = App.GetApp(app1.Key); Assert.IsNull(app3); Target target2 = Target.GetTargetById(target.Id); Assert.IsNull(target2); app.Delete(); app.RemoveTarget(target); target.RemoveOperation(targetoperation); role.Delete(); targetoperation.Delete(); }
public void Save() { Operation operation = new Operation(); operation.Code = StringFactory.NewGuid(); operation.Save(); Operation operation1 = Operation.GetOperationById(operation.Id); Assert.IsNotNull(operation1); operation.Delete(); }
public void DeapTargetList() { User user = new User(); user.Name = "test-add-user"; user.Account = StringFactory.NewGuid(); user.Save(); Role role = Role.Create(); role.Name = "test-giverole-role"; role.Save(); user.GiveRole(role); Organization org1 = Organization.Create(); org1.Code = StringFactory.NewGuid(); org1.Name = "org-test-name"; org1.FullName = "org-test-fullname"; org1.Save(); Assert.IsNotNull(org1); org1.GiveRole(role); Target target = Target.Create(); target.Code = StringFactory.NewGuid(); target.AppId = StringFactory.NewGuid(); target.Save(); Operation targetoperation = new Operation(); targetoperation.Code = StringFactory.NewGuid(); targetoperation.AppId = StringFactory.NewGuid(); targetoperation.TargetId = StringFactory.NewGuid(); targetoperation.Code = StringFactory.NewGuid(); target.AddOperation(targetoperation); role.GivePermission(targetoperation); User user1 = User.GetUser(user.Account); Assert.IsNotNull(user.DeapTargetList); user.Delete(); role.Delete(); org1.Delete(); org1.CancelRole(role); target.Delete(); target.RemoveOperation(targetoperation); role.CancelPermission(targetoperation); }
public void GetTargetList() { Target target = Target.Create(); target.Code = StringFactory.NewGuid(); target.Save(); var target1 = Target.GetTargetList(); Assert.IsNotNull(target1); target.Delete(); }
public void Save() { App app1 = App.Create(); app1.Key = StringFactory.NewGuid(); app1.Name = "app-test"; app1.Secret = "app-test-secret"; app1.Save(); App app2 = App.GetApp(app1.Key); Assert.IsNotNull(app2); app1.Delete(); }
public void GetRole() { Role role = Role.Create(); role.Code = StringFactory.NewGuid(); role.Name = "test-role-add"; role.Save(); Role role1 = Role.GetRole(role.Code); Assert.IsNotNull(role1); role.Delete(); }