public void TestEnforce_Construct_SystemNetMailMessage_CleanBody()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\SystemNetMailMessageRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\SystemNetMailMessageObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            string bodyText = "clean text";

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "subject line", bodyText);
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestClean.doc"));

            MailMessage mailMessage = engine.Enforce(RunAtMode.Client, message, null);
            Assert.IsTrue(mailMessage.BodyEncoding == System.Text.Encoding.ASCII);
            Assert.IsTrue(mailMessage.From.Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.To[0].Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.To[1].Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.To[2].Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.Subject == "subject line"); 
            Assert.IsTrue(mailMessage.Body == "clean text");    
            Assert.IsTrue(mailMessage.Attachments.Count == 1);

            Assert.IsTrue(auditor.m_MailMessage.Attachments.Length == 2);
            Assert.IsTrue(auditor.m_MailMessage.Attachments[0].Name == "TestClean.doc");
            Assert.IsTrue(auditor.m_MailMessage.Attachments[1].Name == "subject line");
        }
        //[Ignore("TODO: Fix this. Skipped by PW - test fails becaise ActionEntity action2 does not exist in ConditionRule")]
        public void TestEnforce_MailMessageEntity_ActionProperties()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            string bodyText = "4408 0412 3456 7890";

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "subject line", bodyText);
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"));
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));

            engine.Enforce(RunAtMode.Client, message, null);
            MailMessageEntity mailMessage = auditor.m_MailMessage;

            ActionEntity action1 = mailMessage.Attachments[0].DocumentEvents[0].ConditionRules[0].EventActions[0];
            Assert.IsTrue(action1.ActionProcessed);
            Assert.IsTrue(action1.ActionProperties.Length == 3);
            Assert.IsTrue(action1.ActionProperties[0].Name == "Unblock");
            Assert.IsTrue(action1.ActionProperties[0].PropertyValue == "False");
            Assert.IsTrue(action1.ActionProperties[1].Name == "AllowOverride");
            Assert.IsTrue(action1.ActionProperties[1].PropertyValue == "True");
            Assert.IsTrue(action1.ActionProperties[2].Name == "FileSelected");
            Assert.IsTrue(action1.ActionProperties[2].PropertyValue == "False");

            ActionEntity action3 = mailMessage.Attachments[2].DocumentEvents[0].ConditionRules[0].EventActions[0];
            Assert.IsTrue(action3.ActionProcessed);
            Assert.IsTrue(action3.ActionProperties.Length == 3);
            Assert.IsTrue(action1.ActionProperties[0].Name == "Unblock");
            Assert.IsTrue(action1.ActionProperties[0].PropertyValue == "False");
            Assert.IsTrue(action1.ActionProperties[1].Name == "AllowOverride");
            Assert.IsTrue(action1.ActionProperties[1].PropertyValue == "True");
            Assert.IsTrue(action1.ActionProperties[2].Name == "FileSelected");
            Assert.IsTrue(action1.ActionProperties[2].PropertyValue == "False");
        }
        public void TestMailMessage_AttachmentRemoved_ProfanityViolation()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\rsa_server_rules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\rsa_server_objects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            System.Net.Mail.MailMessage profanityMessage = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "random subject line", "random body text");
            profanityMessage.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));

            System.Net.Mail.MailMessage mailMessage = engine.Enforce(RunAtMode.Client, profanityMessage, null);
            Assert.IsTrue(mailMessage.Attachments.Count == 0);

            MailMessageEntity msgEntity = auditor.m_MailMessage;

            Assert.IsTrue(msgEntity.Attachments.Length == 2);
            ActionEntity actionEntity = msgEntity.Attachments[0].DocumentEvents[0].ConditionRules[0].EventActions[0];
            Assert.IsTrue(actionEntity.ActionData == "Server_Block");
        }
        public void TestExecuteEvents_AreCalled()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            string bodyText = "4408 0412 3456 7890";

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "subject line", bodyText);
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"));

            MockPolicyEvents policyEvents = new MockPolicyEvents();
            engine.SetPolicyEvents(policyEvents);

            Assert.IsTrue(policyEvents.AfterExecuteEventArgs.Count == 0);
            Assert.IsTrue(policyEvents.BeforeExecuteEventArgs.Count == 0);
            
            engine.Enforce(RunAtMode.Client, message, null);

            Assert.IsTrue(policyEvents.AfterExecuteEventArgs.Count == 2);
            Assert.IsTrue(policyEvents.BeforeExecuteEventArgs.Count == 2);
        }