public void Returns_Fizz_Buzz_if_input_is_Divisble_by_Three_and_Five()
        {
            //arrage
            var input    = 15;
            var expected = "Fizz Buzz";
            var divideByThreeCondition = Substitute.For <ICondition>();
            var divideByFiveCondition  = Substitute.For <ICondition>();


            divideByThreeCondition
            .Condition(Arg.Any <int>())
            .Returns("Fizz");


            divideByFiveCondition
            .Condition(Arg.Any <int>())
            .Returns("Buzz");

            var conditions = new List <ICondition>
            {
                divideByThreeCondition,
                divideByFiveCondition
            };
            var conditionsProcessor = new ConditionProcessor(conditions);

            //act
            var actual = conditionsProcessor.Process(input);

            divideByThreeCondition.Received(1).Condition(Arg.Any <int>());
            divideByFiveCondition.Received(1).Condition(Arg.Any <int>());

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void TestProcessNoPolicyCache()
        {
            IPolicyCache policyCache = new MockPolicyCache(0);
            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
            Assert.IsNull(routingProcessor.Process(pro));
        }
        public void TestProcessWordDocument()
        {
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));

            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            Assert.AreEqual(2, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);

            IContentItem contentItem = pro.ContentCollection[1];
            Assert.IsNotNull(contentItem);

            Assert.AreEqual(1, contentItem.PolicySetCollection.Count);
            IPolicySetResponse policySetResponse = contentItem.PolicySetCollection[0];
            Assert.IsNotNull(policySetResponse);

            Assert.AreEqual(1, policySetResponse.PolicyReportCollection.Count);
            IPolicyResponse policyResponse = policySetResponse.PolicyReportCollection[0];
            Assert.IsNotNull(policyResponse);

            Assert.AreEqual(1, policyResponse.ExpressionCollection.Count);
            IExpressionResponse expressionResponse = policyResponse.ExpressionCollection[0];
            Assert.IsNotNull(expressionResponse);

            Assert.IsTrue(expressionResponse.Triggered);

            Assert.AreEqual(1, expressionResponse.ExpressionDetailCollection.Count);
            IExpressionDetail expressionDetail = expressionResponse.ExpressionDetailCollection[0];
            Assert.IsNotNull(expressionDetail);
            Assert.AreEqual("ConditionSummary", expressionDetail.Name);
            Assert.AreEqual("File type is Word (.doc)", expressionDetail.Value);
        }
Exemple #4
0
        public PartOneProgram()
        {
            var length = 100;
            var sb     = new StringBuilder();
            //instansiate processor here
            var conditionProcessor = new ConditionProcessor(new List <ICondition>
            {
                new DivideByThree(),
                new DivideByFive()
            });

            for (int i = 1; i <= length; i++)
            {
                var result = conditionProcessor.Process(i);

                sb.AppendLine(result);
            }

            Console.WriteLine(sb.ToString());
        }
        public void Returns_Buff_Six_Foo_if_input_is_Divisble_by_Three_and_Five()
        {
            //arrage
            var input    = 330;
            var expected = "Buff Six Foo";
            var divideByFiveCondition   = Substitute.For <ICondition>();
            var divideBySixCondition    = Substitute.For <ICondition>();
            var divideByElevenCondition = Substitute.For <ICondition>();


            divideByFiveCondition
            .Condition(Arg.Any <int>())
            .Returns("Buff");


            divideBySixCondition
            .Condition(Arg.Any <int>())
            .Returns("Six");

            divideByElevenCondition
            .Condition(Arg.Any <int>())
            .Returns("Foo");

            var conditions = new List <ICondition>
            {
                divideByFiveCondition,
                divideBySixCondition,
                divideByElevenCondition
            };
            var conditionsProcessor = new ConditionProcessor(conditions);

            //act
            var actual = conditionsProcessor.Process(input);

            divideByFiveCondition.Received(1).Condition(Arg.Any <int>());
            divideBySixCondition.Received(1).Condition(Arg.Any <int>());
            divideByElevenCondition.Received(1).Condition(Arg.Any <int>());

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void Returns_Buff_if_input_is_Divisble_by_Five()
        {
            //arrage
            var input               = 5;
            var expected            = "Buff";
            var buffReturnCondition = Substitute.For <ICondition>();

            buffReturnCondition
            .Condition(Arg.Any <int>())
            .Returns("Buff");
            var conditions = new List <ICondition> {
                buffReturnCondition
            };
            var conditionsProcessor = new ConditionProcessor(conditions);

            //act
            var actual = conditionsProcessor.Process(input);

            buffReturnCondition.Received(1).Condition(Arg.Any <int>());

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void Returns_Foo_if_input_is_Divisble_by_Eleven()
        {
            //arrage
            var input              = 6;
            var expected           = "Foo";
            var fooReturnCondition = Substitute.For <ICondition>();

            fooReturnCondition
            .Condition(Arg.Any <int>())
            .Returns("Foo");
            var conditions = new List <ICondition> {
                fooReturnCondition
            };
            var conditionsProcessor = new ConditionProcessor(conditions);

            //act
            var actual = conditionsProcessor.Process(input);

            fooReturnCondition.Received(1).Condition(Arg.Any <int>());

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void TestProcessNoAttachments()
        {
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);
                      
            List<string> attachments = new List<string>();
            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            Assert.AreEqual(1, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);

            IContentItem contentItem = pro.ContentCollection[0];
            Assert.IsNotNull(contentItem);

            Assert.AreEqual(1, contentItem.PolicySetCollection.Count);
            IPolicySetResponse policySetResponse = contentItem.PolicySetCollection[0];
            Assert.IsNotNull(policySetResponse);

            Assert.AreEqual(1, policySetResponse.PolicyReportCollection.Count);
            IPolicyResponse policyResponse = policySetResponse.PolicyReportCollection[0];
            Assert.IsNotNull(policyResponse);

            Assert.AreEqual(1, policyResponse.ExpressionCollection.Count);
            IExpressionResponse expressionResponse = policyResponse.ExpressionCollection[0];
            Assert.IsNotNull(expressionResponse);

            Assert.IsFalse(expressionResponse.Triggered);
            Assert.AreEqual(0, expressionResponse.ExpressionDetailCollection.Count);
        }
        public void TestProcessZipActionForContainer()
        {
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Dirty.doc"));

            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            // PROCESS CONDITIONS
            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            // PROCESS ROUTING
            RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
            Assert.IsNotNull(routingProcessor.Process(pro));

            Assert.AreEqual(3, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);

            // PROCESS ACTIONS
            ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
            actionProcessor.ProcessActions(pro);

            ContentItem contentItem = pro.ContentCollection[0] as ContentItem;
            Assert.IsNotNull(contentItem);
            Collection<IPolicyResponseAction> actionCollection = contentItem.PolicySetCollection[0].PolicyReportCollection[0].ActionCollection;
            // Actions not longer re-routed in action processor. Actions will be re-routed in action executor.
            Assert.IsNull(actionCollection);
            //Assert.IsNotNull(actionCollection);
            //Assert.AreEqual(1, actionCollection.Count);

            //contentItem = pro.ContentCollection[1] as ContentItem;
            //Assert.IsNotNull(contentItem);
            //actionCollection = contentItem.PolicySetCollection[0].PolicyReportCollection[0].ActionCollection;
            //Assert.IsNotNull(actionCollection);
            //Assert.AreEqual(1, actionCollection.Count);

            //contentItem = pro.ContentCollection[2] as ContentItem;
            //Assert.IsNotNull(contentItem);
            //actionCollection = contentItem.PolicySetCollection[0].PolicyReportCollection[0].ActionCollection;
            //Assert.IsNotNull(actionCollection);
            //Assert.AreEqual(1, actionCollection.Count);
        }
        public void TestFolderGroupingSmtp()
        {
            string rootTestFolder = System.IO.Path.Combine(m_documentFolder, "TestFolderGrouping");
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            TestHelpers.GetFilesInFolder(rootTestFolder, attachments);

            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            Assert.AreEqual(5, pro.UniversalRequestObject.Attachments.Count);
            Assert.AreEqual("TestDoc.txt", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
            Assert.AreEqual("TestProfanity.doc", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
            Assert.AreEqual("small.xls", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));
            Assert.AreEqual("test.ppt", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[3].Name));
            Assert.AreEqual("TestProfanity.doc", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[4].Name));

            Assert.AreEqual(6, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
            Assert.AreEqual(FileType.TextDocument.ToString(), pro.ContentCollection[1].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
            Assert.AreEqual(FileType.ExcelSheet.ToString(), pro.ContentCollection[3].Type);
            Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[4].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[5].Type);

            Assert.AreEqual(FileType.Email, (container as File).FileType);
            Assert.AreEqual(5, container.Files.Count);

            Assert.AreEqual(FileType.TextDocument, (container.Files[0] as File).FileType);
            Assert.AreEqual(FileType.WordDocument, (container.Files[1] as File).FileType);
            Assert.AreEqual(FileType.ExcelSheet, (container.Files[2] as File).FileType);
            Assert.AreEqual(FileType.PowerPoint, (container.Files[3] as File).FileType);
            Assert.AreEqual(FileType.WordDocument, (container.Files[4] as File).FileType);
        }
        public void TestFolderGroupingRemovableDevice()
        {
            string rootTestFolder = System.IO.Path.Combine(m_documentFolder, "TestFolderGrouping");
            string destinationFolder = System.IO.Path.Combine(m_documentFolder, "Destination");
            if (!System.IO.Directory.Exists(destinationFolder))
                System.IO.Directory.CreateDirectory(destinationFolder);

            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            TestHelpers.GetFilesInFolder(rootTestFolder, attachments);

            IUniversalRequestObject uro = TestHelpers.CreateRemovableDeviceUro(attachments, destinationFolder);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            Assert.AreEqual(5, pro.UniversalRequestObject.Attachments.Count);
            Assert.AreEqual("TestDoc.txt", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
            Assert.AreEqual("TestProfanity.doc", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
            Assert.AreEqual("small.xls", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));
            Assert.AreEqual("test.ppt", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[3].Name));
            Assert.AreEqual("TestProfanity.doc", System.IO.Path.GetFileName(pro.UniversalRequestObject.Attachments[4].Name));

            Assert.AreEqual(9, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Folder.ToString(), pro.ContentCollection[0].Type);
            Assert.AreEqual(FileType.Folder.ToString(), pro.ContentCollection[1].Type);
            Assert.AreEqual(FileType.TextDocument.ToString(), pro.ContentCollection[2].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type);
            Assert.AreEqual(FileType.Folder.ToString(), pro.ContentCollection[4].Type);
            Assert.AreEqual(FileType.Folder.ToString(), pro.ContentCollection[5].Type);
            Assert.AreEqual(FileType.ExcelSheet.ToString(), pro.ContentCollection[6].Type);
            Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[7].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[8].Type);

            Assert.AreEqual(FileType.Selection, (container as File).FileType);
            Assert.AreEqual(1, container.Files.Count);
            container = container.Files[0];
            Assert.AreEqual(FileType.Folder, (container as File).FileType);

            Assert.AreEqual(2, container.Files.Count);

            File file = container.Files[0] as File;
            Assert.AreEqual(FileType.Folder, file.FileType);
            Assert.AreEqual(2, file.Files.Count);
            Assert.AreEqual(FileType.TextDocument, (file.Files[0] as File).FileType);
            Assert.AreEqual(FileType.WordDocument, (file.Files[1] as File).FileType);

            file = container.Files[1] as File;
            Assert.AreEqual(FileType.Folder, file.FileType);
            Assert.AreEqual(3, file.Files.Count);
            Assert.AreEqual(FileType.Folder, (file.Files[0] as File).FileType);
            Assert.AreEqual(FileType.ExcelSheet, (file.Files[0].Files[0] as File).FileType);
            Assert.AreEqual(FileType.PowerPoint, (file.Files[1] as File).FileType);
            Assert.AreEqual(FileType.WordDocument, (file.Files[2] as File).FileType);
        }
        public void TestFolderGroupingNoFiles()
        {
            string destinationFolder = System.IO.Path.Combine(m_documentFolder, "Destination");
            if (!System.IO.Directory.Exists(destinationFolder))
                System.IO.Directory.CreateDirectory(destinationFolder);

            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            IUniversalRequestObject uro = TestHelpers.CreateRemovableDeviceUro(null, destinationFolder);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            Assert.AreEqual(0, pro.UniversalRequestObject.Attachments.Count);
            Assert.AreEqual(0, pro.ContentCollection.Count);

            Assert.AreEqual(FileType.Selection, (container as File).FileType);
            Assert.AreEqual(0, container.Files.Count);
        }
		public void Test_05_ExecuteAction_SMTP_ZipPolicy()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(
				new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(1, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			using (LocalCopyOfFileManager lcfm = new LocalCopyOfFileManager())
			{
				string folderName = lcfm.ManagedFolder;

				string fileName = Path.Combine(folderName, "TestProfanity.doc");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestProfanity.doc"), fileName);
				attachments.Add(fileName);
				fileName = Path.Combine(folderName, "Dirty.doc");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "Dirty.doc"), fileName);
				attachments.Add(fileName);
				fileName = Path.Combine(folderName, "TestDoc.ppt");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestDoc.ppt"), fileName);
				attachments.Add(fileName);

				IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

				// PROCESS CONDITIONS
				IContainer container;
				PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
				Assert.IsNotNull(pro);

				// PROCESS ROUTING
				RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
				Assert.IsNotNull(routingProcessor.Process(pro));

				Assert.AreEqual(4, pro.ContentCollection.Count);
				Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
				Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

				Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
				Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
				Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
				Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));

				// PROCESS ACTIONS
				ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
				actionProcessor.ProcessActions(pro);

				ActionUtils.PopulateResolvedActionCollection(pro);

				// EXECUTE ACTIONS
				ActionExecuter executer = new ActionExecuter(null);
				executer.ExecuteActions(pro, ref container);

				Assert.AreEqual(4, pro.ContentCollection.Count);
				Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
				Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

				Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
				Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
				Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
				Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));
			}
		}
		public void Test_10_ExecuteAction_SMTP_Default_Policy_And_ZIP_Policy()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { 
				Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\Policies\p5default.policy"),
				Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(2, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt"));

			IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

			// PROCESS CONDITIONS
			IContainer container;
			PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
			Assert.IsNotNull(pro);

			// PROCESS ROUTING
			RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
			Assert.IsNotNull(routingProcessor.Process(pro));

			Assert.AreEqual(4, pro.ContentCollection.Count);
			Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
			Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
			Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
			Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
			Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));

			// PROCESS ACTIONS
			ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
			actionProcessor.ProcessActions(pro);
			ActionUtils.PopulateResolvedActionCollection(pro);

			// EXECUTE ACTIONS
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(pro, ref container);

			//Assert.AreEqual(4, pro.ContentCollection.Count);
			//Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			//Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			//Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
			//Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(2, outputUro.Attachments.Count);
			Assert.AreEqual("TestDoc.ppt", outputUro.Attachments[0].Name);
			Assert.AreEqual("attachments.zip", outputUro.Attachments[1].Name);

			File outputFile = new File(outputUro.Attachments[1].Data, outputUro.Attachments[0].Name);
			Assert.IsNotNull(outputFile);
			outputFile.ExpandContainer(outputFile.Password);
			Assert.AreEqual(2, outputFile.Files.Count);
			Assert.AreEqual("TestProfanity.doc", outputFile.Files[0].DisplayName);
			Assert.AreEqual("Dirty.doc", outputFile.Files[1].DisplayName);
		}
		public void Test_06_ExecuteAction_SMTP_ZipPolicy_HasZip()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(
				new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(1, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "I am a dirty zip.zip"));

			IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

			// PROCESS CONDITIONS
			IContainer container;
			PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
			Assert.IsNotNull(pro);

			// PROCESS ROUTING
			RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
			Assert.IsNotNull(routingProcessor.Process(pro));

			Assert.AreEqual(4, pro.ContentCollection.Count);
			Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			Assert.AreEqual(FileType.ZIP.ToString(), pro.ContentCollection[2].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(2, pro.UniversalRequestObject.Attachments.Count);
			Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
			Assert.AreEqual("I am a dirty zip.zip", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));

			// PROCESS ACTIONS
			ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
			actionProcessor.ProcessActions(pro);
			ActionUtils.PopulateResolvedActionCollection(pro);

			// EXECUTE ACTIONS
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(pro, ref container);

			Assert.AreEqual(4, pro.ContentCollection.Count);
			Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			Assert.AreEqual(FileType.ZIP.ToString(), pro.ContentCollection[2].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(2, outputUro.Attachments.Count);
			Assert.AreEqual("TestProfanity.zip", outputUro.Attachments[0].Name);
			Assert.AreEqual("I am a dirty zip.zip", outputUro.Attachments[1].Name);
		}
        public void TestProcessWordDocumentAndTextFile()
        {
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "Zip Policy Set.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestDoc.txt"));

            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
            Assert.IsNotNull(routingProcessor.Process(pro));

            Assert.AreEqual(3, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
            Assert.AreEqual(FileType.TextDocument.ToString(), pro.ContentCollection[2].Type);

            IContentItem contentItem = pro.ContentCollection[1];
            Assert.IsNotNull(contentItem);

            Assert.AreEqual(1, contentItem.PolicySetCollection.Count);
            IPolicySetResponse policySetResponse = contentItem.PolicySetCollection[0];
            Assert.IsNotNull(policySetResponse);

            Assert.AreEqual(1, policySetResponse.PolicyReportCollection.Count);
            IPolicyResponse policyResponse = policySetResponse.PolicyReportCollection[0];
            Assert.IsNotNull(policyResponse);

            RoutingResponse routingResponse = policyResponse.Routing as RoutingResponse;
            Assert.IsNotNull(routingResponse);

            Assert.AreEqual("To External Recipients", routingResponse.Name);
            Assert.AreEqual("Low", routingResponse.Rating);
            Assert.AreEqual("w-7639d673-ab9d-4380-aad3-c5f7e3931d5e", routingResponse.ActionSetId);

            contentItem = pro.ContentCollection[2];
            Assert.IsNotNull(contentItem);

            Assert.AreEqual(1, contentItem.PolicySetCollection.Count);
            policySetResponse = contentItem.PolicySetCollection[0];
            Assert.IsNotNull(policySetResponse);

            Assert.AreEqual(1, policySetResponse.PolicyReportCollection.Count);
            policyResponse = policySetResponse.PolicyReportCollection[0];
            Assert.IsNotNull(policyResponse);

            routingResponse = policyResponse.Routing as RoutingResponse;
            Assert.IsNull(routingResponse);
        }
        /// <summary>
        /// Tests sending a mail with multiple LDAP routers set up
        /// </summary>
        /// <param name="clearAnalyzerList">
        /// If true, the analyzer list (DirectoryAnalyzers) is cleared prior to testing.
        /// </param>
        private void TestMultipleLdapRouters(bool clearAnalyzerList)
        {
            //  MultipleLdapRoutersTest.policy should contain a routing table with a sender DA0 and a receiver DA1
            //  DA0 should have the address "*****@*****.**", DA1 the address "*****@*****.**"
            if (clearAnalyzerList)
            {
                DirectorySearcher.DirectoryAnalyzers.Instance.Clear();
            }

            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { m_testPath + "MultipleLdapRoutersTest.policy" });
            Assert.IsNotNull(policyCache);
            Assert.AreEqual(1, policyCache.PolicySets.Count);

            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Clean.doc"));

            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments,"*****@*****.**","*****@*****.**");

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
            Assert.IsNotNull(routingProcessor.Process(pro));

            Assert.AreEqual(2, pro.ContentCollection.Count);
            Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
            Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);

            // Don't expect any routing response with the email body
            IContentItem contentItem = pro.ContentCollection[0];
            Assert.IsNotNull(contentItem);

            Assert.AreEqual(1, contentItem.PolicySetCollection.Count);
            IPolicySetResponse policySetResponse = contentItem.PolicySetCollection[0];
            Assert.IsNotNull(policySetResponse);

            Assert.AreEqual(1, policySetResponse.PolicyReportCollection.Count);
            IPolicyResponse policyResponse = policySetResponse.PolicyReportCollection[0];
            Assert.IsNotNull(policyResponse);

            IRoutingResponse routingResponse = policyResponse.Routing;
            Assert.IsNull(routingResponse);

            // Expect a routing response with the attachment
            contentItem = pro.ContentCollection[1];
            Assert.IsNotNull(contentItem);

            Assert.AreEqual(1, contentItem.PolicySetCollection.Count);
            policySetResponse = contentItem.PolicySetCollection[0];
            Assert.IsNotNull(policySetResponse);

            Assert.AreEqual(1, policySetResponse.PolicyReportCollection.Count);
            policyResponse = policySetResponse.PolicyReportCollection[0];
            Assert.IsNotNull(policyResponse);

            routingResponse = policyResponse.Routing;
            Assert.IsNotNull(routingResponse);

            Assert.AreEqual("DA0 to DA1", routingResponse.Name);
        }