Пример #1
0
		public void SimpleConditionTest()
		{
			SCConditionOwner owner = new SCConditionOwner();

			SCUser user1 = SCObjectGenerator.PrepareUserObject();

			SCObjectOperations.Instance.AddUser(user1, SCOrganization.GetRoot());

			SCUser user2 = SCObjectGenerator.PrepareUserObject();

			SCObjectOperations.Instance.AddUser(user2, SCOrganization.GetRoot());

			owner.OwnerID = UuidHelper.NewUuidString();

			string expression = string.Format("Users.CodeName == \"{0}\"", user2.CodeName);

			owner.Conditions.Add(new SCCondition() { Description = "基本测试", Condition = expression });

			SCConditionCalculator calculator = new SCConditionCalculator();

			IEnumerable<SchemaObjectBase> result = calculator.Calculate(owner);

			Assert.AreEqual(1, result.Count());

			foreach (SchemaObjectBase obj in result)
			{
				Console.WriteLine("ID:{0}, Name: {1}", obj.ID, obj.Properties.GetValue("Name", string.Empty));
			}
		}
		public void GenerateAllUserAndContainerSnapshotTest()
		{
			ProcessProgress.Clear();
			ProcessProgress.Current.RegisterResponser(TestProgressResponser.Instance);

			TestRoleData roleData = SCObjectGenerator.PrepareTestRoleWithOrgAndGroup();

			SCConditionCalculator calculator = new SCConditionCalculator();

			calculator.GenerateAllUserAndContainerSnapshot();

			Console.Error.WriteLine("Error: {0}", ProcessProgress.Current.GetDefaultError());
			Console.WriteLine("Output: {0}", ProcessProgress.Current.GetDefaultOutput());
		}
		public void IsChildByCodeNameBuiltInFunctionTest()
		{
			SchemaObjectAdapter.Instance.ClearAllData();

			TestRoleData roleData = SCObjectGenerator.PrepareTestRoleWithOrgAndGroup(data => string.Format("IsChild(\"{0}\", \"{1}\")", "CodeName", data.Organization.CodeName));

			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.IsTrue(snapshot.ContainsKey(roleData.UserInOrg.ID));
		}
		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));
		}
Пример #5
0
		public void SimpleGroupConditionsTest()
		{
			SCUser userInGroup;
			SCUser userNotInGroup;

			SCGroup group = SCObjectGenerator.PrepareGroupWithConditions(out userInGroup, out userNotInGroup);

			SCConditionCalculator calculator = new SCConditionCalculator();

			SCConditionOwner owner = SCConditionAdapter.Instance.Load(group.ID, string.Empty);

			SchemaObjectCollection calculateResult = calculator.Calculate(owner);

			ConditionCalculateResultAdapter.Instance.Update(group.ID, calculateResult);

			SchemaObjectCollection loadedResult = ConditionCalculateResultAdapter.Instance.LoadCurrentUsers(group.ID);

			Assert.IsTrue(loadedResult.ContainsKey(userInGroup.ID));
			Assert.IsFalse(loadedResult.ContainsKey(userNotInGroup.ID));
		}
		protected void ProcessGlobalCaculating(object sender, MCS.Web.WebControls.PostProgressDoPostedDataEventArgs e)
		{
			SCConditionCalculator calc = new SCConditionCalculator();

			calc.GenerateAllUserAndContainerSnapshot();

			SCCacheHelper.InvalidateAllCache();

			e.Result.DataChanged = true;
			e.Result.CloseWindow = false;
			e.Result.ProcessLog = ProcessProgress.Current.GetDefaultOutput();
		}
		protected void ProcessCaculating(object sender, MCS.Web.WebControls.PostProgressDoPostedDataEventArgs e)
		{
			SCConditionCalculator calc = new SCConditionCalculator();

			calc.GenerateUserAndContainerSnapshot(new[] { (SCRole)SchemaObjectAdapter.Instance.Load(this.calcProgress.Tag) });

			SCCacheHelper.InvalidateAllCache();

			e.Result.DataChanged = true;
			e.Result.CloseWindow = false;
			e.Result.ProcessLog = ProcessProgress.Current.GetDefaultOutput();
		}