public void GenerateUserAndContainerSnapshotTest() { TestRoleData roleData = SCObjectGenerator.PrepareTestRoleWithOrgAndGroup(); SCConditionCalculator calculator = new SCConditionCalculator(); ProcessProgress.Clear(); ProcessProgress.Current.RegisterResponser(TestProgressResponser.Instance); calculator.GenerateUserAndContainerSnapshot(new List <ISCUserContainerObject>() { roleData.Group }); calculator.GenerateUserAndContainerSnapshot(new List <ISCUserContainerObject>() { roleData.Role }); SameContainerUserAndContainerSnapshotCollection snapshot = UserAndContainerSnapshotAdapter.Instance.LoadByContainerID(roleData.Role.ID); Console.WriteLine(roleData.ToString()); Console.Error.WriteLine("Error: {0}", ProcessProgress.Current.GetDefaultError()); Console.WriteLine("Output: {0}", ProcessProgress.Current.GetDefaultOutput()); Assert.IsTrue(snapshot.ContainsKey(roleData.UserInGroup.ID)); Assert.IsTrue(snapshot.ContainsKey(roleData.UserInOrg.ID)); Assert.IsTrue(snapshot.ContainsKey(roleData.UserInRole.ID)); Assert.IsTrue(snapshot.ContainsKey(roleData.UserInConditionRole.ID)); Assert.IsTrue(snapshot.ContainsKey(roleData.UserInConditionGroup.ID)); }
public void AddUserToGroupExecutorTest() { SCGroup group = SCObjectGenerator.PrepareGroupObject(); SCObjectOperations.Instance.AddGroup(group, SCOrganization.GetRoot()); SCUser user1 = SCObjectGenerator.PrepareUserObject(); SCObjectOperations.Instance.AddUser(user1, SCOrganization.GetRoot()); SCMemberRelation mr = SCObjectOperations.Instance.AddUserToGroup(user1, group); Assert.AreEqual(group.SchemaType, mr.ContainerSchemaType); Assert.AreEqual(user1.SchemaType, mr.MemberSchemaType); SCUser user2 = SCObjectGenerator.PrepareUserObject(); SCObjectOperations.Instance.AddUser(user2, SCOrganization.GetRoot()); SCObjectOperations.Instance.AddUserToGroup(user2, group); Assert.AreEqual(2, group.CurrentUsers.Count); Assert.IsTrue(group.CurrentUsers.ContainsKey(user1.ID)); Assert.IsTrue(group.CurrentUsers.ContainsKey(user2.ID)); Assert.IsTrue(user1.CurrentGroups.ContainsKey(group.ID)); Assert.IsTrue(user2.CurrentGroups.ContainsKey(group.ID)); SameContainerUserAndContainerSnapshotCollection ugSnapshot = UserAndContainerSnapshotAdapter.Instance.LoadByContainerID(group.ID); Assert.IsTrue(ugSnapshot.ContainsKey(user1.ID)); Assert.IsTrue(ugSnapshot.ContainsKey(user2.ID)); }
public void MergeUserInGroupExecutorTest() { // 准备4位用户。User1位状态不变,User2待删除,User3新增加,User4复活 SCGroup group = SCObjectGenerator.PrepareGroupObject(); SCObjectOperations.Instance.AddGroup(group, SCOrganization.GetRoot()); SCUser user1 = SCObjectGenerator.PrepareUserObject(); SCObjectOperations.Instance.AddUser(user1, SCOrganization.GetRoot()); SCMemberRelation mr = SCObjectOperations.Instance.AddUserToGroup(user1, group); Assert.AreEqual(group.SchemaType, mr.ContainerSchemaType); Assert.AreEqual(user1.SchemaType, mr.MemberSchemaType); SCUser user2 = SCObjectGenerator.PrepareUserObject(); SCObjectOperations.Instance.AddUser(user2, SCOrganization.GetRoot()); SCObjectOperations.Instance.AddUserToGroup(user2, group); SCUser user3 = SCObjectGenerator.PrepareUserObject(); SCObjectOperations.Instance.AddUser(user3, SCOrganization.GetRoot()); SCUser user4 = SCObjectGenerator.PrepareUserObject(); SCObjectOperations.Instance.AddUser(user4, SCOrganization.GetRoot()); SCObjectOperations.Instance.AddUserToGroup(user4, group); SCObjectOperations.Instance.RemoveUserFromGroup(user4, group); user4.Status = SchemaObjectStatus.Normal; SchemaObjectCollection needMergeUsers = new SchemaObjectCollection() { user1, user3, user4 }; UserAndContainerSnapshotAdapter.Instance.Merge(group.ID, group.SchemaType, needMergeUsers); Console.WriteLine("Group ID: {0}", group.ID); SameContainerUserAndContainerSnapshotCollection ugSnapshot = UserAndContainerSnapshotAdapter.Instance.LoadByContainerID(group.ID); Assert.IsTrue(ugSnapshot.ContainsKey(user1.ID)); Assert.AreEqual(SchemaObjectStatus.Normal, ugSnapshot[user1.ID].Status); Assert.IsTrue(ugSnapshot.ContainsKey(user2.ID)); Assert.AreEqual(SchemaObjectStatus.Deleted, ugSnapshot[user2.ID].Status); Assert.IsTrue(ugSnapshot.ContainsKey(user3.ID)); Assert.AreEqual(SchemaObjectStatus.Normal, ugSnapshot[user3.ID].Status); Assert.IsTrue(ugSnapshot.ContainsKey(user4.ID)); Assert.AreEqual(SchemaObjectStatus.Normal, ugSnapshot[user4.ID].Status); }
private static SameContainerUserAndContainerSnapshotCollection GetInsertData(string containerID, string containerSchemaType, SameContainerUserAndContainerSnapshotCollection existedData, SchemaObjectCollection users) { SameContainerUserAndContainerSnapshotCollection newInfo = new SameContainerUserAndContainerSnapshotCollection(); foreach (SchemaObjectBase user in users) { if (existedData.ContainsKey(user.ID) == false && newInfo.ContainsKey(user.ID) == false) { UserAndContainerSnapshot uacs = new UserAndContainerSnapshot(); uacs.ContainerID = containerID; uacs.ContainerSchemaType = containerSchemaType; uacs.UserID = user.ID; uacs.UserSchemaType = "Users"; uacs.Status = SchemaObjectStatus.Normal; newInfo.Add(uacs); } } return(newInfo); }
/// <summary> /// 根据Container来加载UserAndContainerSnapshot的信息 /// </summary> /// <param name="containerID"></param> /// <param name="timePoint"></param> /// <returns></returns> public SameContainerUserAndContainerSnapshotCollection LoadByContainerID(string containerID, DateTime timePoint) { containerID.CheckStringIsNullOrEmpty("containerID"); ConnectiveSqlClauseCollection timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint); WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder(); whereBuilder.AppendItem("ContainerID", containerID); ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(whereBuilder, timePointBuilder); string sql = string.Format("SELECT * FROM {0} WHERE {1}", this.GetLoadingTableName(timePoint), connectiveBuilder.ToSqlString(TSqlBuilder.Instance)); SameContainerUserAndContainerSnapshotCollection result = new SameContainerUserAndContainerSnapshotCollection(); using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (reader.Read()) { UserAndContainerSnapshot item = new UserAndContainerSnapshot(); ORMapping.DataReaderToObject(reader, item); if (result.ContainsKey(item.UserID) == false) { result.Add(item); } } } } return(result); }
public void IsChildAllByIDBuiltInFunctionTest() { SchemaObjectAdapter.Instance.ClearAllData(); TestRoleData roleData = SCObjectGenerator.PrepareTestRoleWithOrgAndGroup(data => string.Format("IsChildAll(\"{0}\", \"{1}\")", "Guid", data.SidelineOrganization.ID)); SCConditionCalculator calculator = new SCConditionCalculator(); ProcessProgress.Clear(); ProcessProgress.Current.RegisterResponser(TestProgressResponser.Instance); calculator.GenerateUserAndContainerSnapshot(new List <ISCUserContainerObject>() { roleData.BuiltInFunctionRole }); SameContainerUserAndContainerSnapshotCollection snapshot = UserAndContainerSnapshotAdapter.Instance.LoadByContainerID(roleData.BuiltInFunctionRole.ID); Console.WriteLine(roleData.ToString()); Console.Error.WriteLine("Error: {0}", ProcessProgress.Current.GetDefaultError()); Console.WriteLine("Output: {0}", ProcessProgress.Current.GetDefaultOutput()); Assert.IsFalse(snapshot.ContainsKey(roleData.SidelineUserInOrg.ID)); }
private static SameContainerUserAndContainerSnapshotCollection GetInsertData(string containerID, string containerSchemaType, SameContainerUserAndContainerSnapshotCollection existedData, SchemaObjectCollection users) { SameContainerUserAndContainerSnapshotCollection newInfo = new SameContainerUserAndContainerSnapshotCollection(); foreach (SchemaObjectBase user in users) { if (existedData.ContainsKey(user.ID) == false && newInfo.ContainsKey(user.ID) == false) { UserAndContainerSnapshot uacs = new UserAndContainerSnapshot(); uacs.ContainerID = containerID; uacs.ContainerSchemaType = containerSchemaType; uacs.UserID = user.ID; uacs.UserSchemaType = "Users"; uacs.Status = SchemaObjectStatus.Normal; newInfo.Add(uacs); } } return newInfo; }
/// <summary> /// 根据Container来加载UserAndContainerSnapshot的信息 /// </summary> /// <param name="containerID"></param> /// <param name="timePoint"></param> /// <returns></returns> public SameContainerUserAndContainerSnapshotCollection LoadByContainerID(string containerID, DateTime timePoint) { containerID.CheckStringIsNullOrEmpty("containerID"); ConnectiveSqlClauseCollection timePointBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint); WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder(); whereBuilder.AppendItem("ContainerID", containerID); ConnectiveSqlClauseCollection connectiveBuilder = new ConnectiveSqlClauseCollection(whereBuilder, timePointBuilder); string sql = string.Format("SELECT * FROM {0} WHERE {1}", this.GetLoadingTableName(timePoint), connectiveBuilder.ToSqlString(TSqlBuilder.Instance)); SameContainerUserAndContainerSnapshotCollection result = new SameContainerUserAndContainerSnapshotCollection(); using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (reader.Read()) { UserAndContainerSnapshot item = new UserAndContainerSnapshot(); ORMapping.DataReaderToObject(reader, item); if (result.ContainsKey(item.UserID) == false) result.Add(item); } } } return result; }