public void Test01_HasEverything()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Has everthing.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
        public void Test04_HasNoActions()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Has no actions.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
            Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);

            List<string> errorMessages = policySetValidator.InvalidPolicies[policySet.Policies[0].Name.Value];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(errorMessages.Contains("No actions defined"));
        }
		public void TestIsPasswordCondition()
		{
			IPolicySet policySet = ReadPolicySet(m_testPath + "InvalidActionForPasswordCondition.policy");

			PolicySetValidator policySetValidator = new PolicySetValidator(policySet);
			policySetValidator.Validate();

			Assert.AreEqual(1, policySet.Policies.Count);
			IPolicy policy = policySet.Policies[0];

			IConditionGroup group = policy.Conditions[0] as IConditionGroup;
			Assert.IsTrue(ExpressionHelpers.IsPasswordCondition(group.Conditions[0] as ICondition));
		}
        public void Test21_FileTypeForActions_EmailFiletypeConflictingActions()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "TestFileTypeForActions_EmailFiletypeConflictingActions.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
            Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);

            List<string> errorMessages = policySetValidator.InvalidPolicies["InvalidFileTypeForActions"];
            Assert.AreEqual(1, errorMessages.Count);
        }
        public void Test20_ValidFileTypeForActions_EmailFiletype()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "TestFileTypeForActions_EmailFiletype.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
        public void Test18_IntraPolicyFileSizeValidation()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "TestIntraPolicyFileSizeValidation.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(3, policySetValidator.ConflictPolicies.Count);

            List<string> errorMessages = policySetValidator.ConflictPolicies["InvalidLessThanOrEqualToAndGreaterThan"];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(0 == String.Compare(errorMessages[0], Workshare.Policy.Properties.Resources.VALIDATION_INTRAPOLICY_FILESIZE_CONFLICT));

            errorMessages = policySetValidator.ConflictPolicies["InvalidGreaterThanOrEqualToAndLessThan"];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(0 == String.Compare(errorMessages[0], Workshare.Policy.Properties.Resources.VALIDATION_INTRAPOLICY_FILESIZE_CONFLICT));

            errorMessages = policySetValidator.ConflictPolicies["InvalidEqualsAndNotEquals"];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(0 == String.Compare(errorMessages[0], Workshare.Policy.Properties.Resources.VALIDATION_INTRAPOLICY_FILESIZE_CONFLICT));
        }
        public void Test17_IntraPolicyFileTypeValidation()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "TestIntraPolicyFileTypeValidation.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(2, policySetValidator.ConflictPolicies.Count);

            List<string> errorMessages = policySetValidator.ConflictPolicies["Invalid_IncorrectQuantity"];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(0 == String.Compare(errorMessages[0], Workshare.Policy.Properties.Resources.VALIDATION_INTRAPOLICY_FILETYPE_CONFLICT));

            errorMessages = policySetValidator.ConflictPolicies["Invalid_CorrectQuantityIncorrectTypes"];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(0 == String.Compare(errorMessages[0], Workshare.Policy.Properties.Resources.VALIDATION_INTRAPOLICY_FILETYPE_CONFLICT));
        }
        public void Test06_MultipleChannelWithActions()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Multiple channels have actions.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
        public void Test25_HasNonExistentAction()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "NonExistentActions.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
            Assert.AreEqual(2, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
		public void Test13_InterpolicyConflict()
		{
			IPolicySet policySet = ReadPolicySet(m_testPath + "ClashingFiletypes.policy");
			PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

			Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
			Assert.AreEqual(1, policySetValidator.ConflictPolicies.Count);

			List<string> errorMessages = policySetValidator.ConflictPolicies["Policy2"];
			Assert.AreEqual(1, errorMessages.Count);
			Assert.IsTrue(errorMessages.Contains("The filetype 'WordDocument' is already used in policy 'Policy1', which also triggers action 'Block Action'"));
		}
        public void Test12_ValidateRoutingItemCollections()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "RecipientGroupInvalid.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
            Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);

            List<string> errorMessages = policySetValidator.InvalidPolicies["New Policy"];
            Assert.AreEqual(2, errorMessages.Count);
            
            Assert.IsTrue(errorMessages.Contains("Source group 'New Group1' on 'Email Channel' has no members"));
            Assert.IsTrue(errorMessages.Contains("Destination group 'New Group5' on 'Email Channel' has no members"));

            //TODO: add test for device channel
        }
        public void Test10_DescriptionPopulated()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Description populated.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
        public void Test095_ActiveContentChannelInvalidFileTypes()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Active content channel Conflict Filetype.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid, but contain conflicts");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count, "Expecting 0 policy conflict");
        }
        public void Test09_ActiveContentChannel()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Active content channel test.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
        public void Test08_TwoPoliciesNotValid()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "Two Policies not valid.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
            Assert.AreEqual(2, policySetValidator.InvalidPolicies.Count);
            Assert.IsTrue(policySetValidator.InvalidPolicies.ContainsKey("Policy One"));
            Assert.IsTrue(policySetValidator.InvalidPolicies.ContainsKey("Policy Two"));

            List<string> errorMessages = policySetValidator.InvalidPolicies["Policy One"];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(errorMessages.Contains("No actions defined"));
            
            errorMessages = policySetValidator.InvalidPolicies["Policy Two"];
            Assert.AreEqual(2, errorMessages.Count);
            Assert.IsTrue(errorMessages.Contains("No expressions defined"));
            Assert.IsTrue(errorMessages.Contains("No actions defined"));
        }
        public void Test22_ValidateDefaultPolicy()
        {
            IPolicySet policySet = ReadPolicySet(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\hygiene\policies\p5default.policy"));
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
           Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
        public void Test24_PIIWithEmailAction()
        {
            IPolicySet policySet = ReadPolicySet(m_testPath + "PII with email action.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
        }
		public void Test14_InvalidConditionForSingleFiletype()
		{
			IPolicySet policySet = ReadPolicySet(m_testPath + "InvalidFileTypeForAction.policy");
			PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

			Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
			Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);

            List<string> errorMessages = policySetValidator.InvalidPolicies["Policy1"];
			Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(errorMessages.Contains("The following file types are not supported by the defined actions: TextDocument"));
		}
        public void Test26_ActionsWithImpliesIncident()
        {
            #region setup
            // verify the initial state
            IPolicySet policySet = ReadPolicySet(m_testPath + "TestFileTypeForActions_EmailFiletype.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
            Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);

            // set the tagmimeaction to
            IResourceAction tagMimeAction = null;
            try
            {
                IResourceManager resourceManager = ResourcesCache.GetResources();
                foreach (IResourceAction resourceAction in resourceManager.ResourceActions)
                {
                    if (resourceAction.ActionClass.Contains("TagMimeAction"))
                    {
                        tagMimeAction = resourceAction;
                        tagMimeAction.ImpliesIncident = true;
                    }
                }

                Assert.IsNotNull(tagMimeAction, "TagMimeAction not found");
            #endregion
                //execute

                Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
                Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);
                Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
            }
            finally
            {
                if (tagMimeAction != null)
                    tagMimeAction.ImpliesIncident = false;
            }
        }
		public void Test15_ValidConditionForMultipleFiletypes()
		{
			IPolicySet policySet = ReadPolicySet(m_testPath + "ValidPolicyForMultipleFileTypes.policy");
			PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

			Assert.IsTrue(policySetValidator.Validate(), "Expected the policy set to be valid");
			Assert.AreEqual(0, policySetValidator.InvalidPolicies.Count);
            Assert.AreEqual(0, policySetValidator.ConflictPolicies.Count);
		}
        public void Test05_DRMActionInPolicyButNotInResources()
        {
            // This test relies on the DRM action not existing in the resources. If
            // it does, then remove it and add it back again at the end
            const string DRM_ACTION_CLASS_NAME = "Workshare.Policy.Actions.DRMDocAction";
            IResourceActions resourceActions = ResourcesCache.GetResources().ResourceActions;
            IResourceAction drmDocAction = null;
            foreach (IResourceAction resourceAction in resourceActions)
            {
                if (resourceAction.ActionClass == DRM_ACTION_CLASS_NAME)
                {
                    drmDocAction = resourceAction;
                    drmDocAction.ActionClass = "Temp";
                }
            }

            IPolicySet policySet = ReadPolicySet(m_testPath + "Test DRM action not present in resources.policy");
            PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

            Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
            Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);

            List<string> errorMessages = policySetValidator.InvalidPolicies[policySet.Policies[0].Name.Value];
            Assert.AreEqual(1, errorMessages.Count);
            Assert.IsTrue(errorMessages[0].Contains("The following actions in the policy do not exist"));

            if (drmDocAction != null)
            {
                drmDocAction.ActionClass = DRM_ACTION_CLASS_NAME;
            }
        }
		public void Test16_InvalidActionForPasswordCondition()
		{
			IPolicySet policySet = ReadPolicySet(m_testPath + "InvalidActionForPasswordCondition.policy");
			PolicySetValidator policySetValidator = new PolicySetValidator(policySet);

			Assert.IsFalse(policySetValidator.Validate(), "Expected the policy set to be invalid");
			Assert.AreEqual(1, policySetValidator.InvalidPolicies.Count);

			List<string> errorMessages = policySetValidator.InvalidPolicies["Policy1"];
			Assert.AreEqual(1, errorMessages.Count);
			Assert.IsTrue(errorMessages.Contains("The policy cannot have action 'Clean Action' if a password condition is specified"));
		}