public void TestOrderedChannels()
        {
            TreeViewControllerPolicyOrientedTester controller = new TreeViewControllerPolicyOrientedTester();

            //nominal case
            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            IPolicyChannel channel1 = ChannelFactory.CreateChannel("channel1", ChannelType.HTTP);
            IPolicyChannel channel2 = ChannelFactory.CreateChannel("channel4", ChannelType.SMTP);
            IPolicyChannel channel3 = ChannelFactory.CreateChannel("channel5", ChannelType.ActiveContent);
            channels.Add(channel1);
            channels.Add(channel2);
            channels.Add(channel3);

            List<IPolicyChannel> orderedChannels = controller.OrderedChannels(channels);

            Assert.AreEqual(3, orderedChannels.Count, "unexpected number of channels");
            Assert.AreSame(channel2, orderedChannels[0], "wrong channel");
            Assert.AreSame(channel1, orderedChannels[1], "wrong channel");
            Assert.AreSame(channel3, orderedChannels[2], "wrong channel");            

            //multiple of same type
            IPolicyChannel channel4 = ChannelFactory.CreateChannel("channel4", ChannelType.SMTP);
            channels.Add(channel4);

            orderedChannels = controller.OrderedChannels(channels);

            Assert.AreEqual(4, orderedChannels.Count, "unexpected number of channels");
            Assert.AreSame(channel2, orderedChannels[0], "wrong channel");
            Assert.AreSame(channel4, orderedChannels[1], "wrong channel");
            Assert.AreSame(channel1, orderedChannels[2], "wrong channel");
            Assert.AreSame(channel3, orderedChannels[3], "wrong channel");
        }
        public void TestGetDisplayName()
        {

            //nominal case - display name already set
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Header)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.TextBox)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.StringArray, dataItems);
            ConditionDisplayParameterContext contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("Header, Text box", contextParam.GetDisplayName(), "unexpected displayname - display name should be same as dataElement");

            //data items in collection
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("Header, Text box", contextParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("Header, Text box", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data items in collection
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT, contextParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), ConditionUnitFactory.FileContextType.Endnote)));
            contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            contextParam.Object = dataElement;
            try
            {
                string displayName = contextParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = contextParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
        public void TestGetDisplayName()
        {

            //nominal case - display name already set
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem("This is a preset Display Name"), DataType.StringArray, dataItems);
            ConditionDisplayParameterFileType fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.GetDisplayName(), "unexpected displayname - displayname should be the same dataElement");

            //data items in collection
            dataElement.DisplayName.Value = "";
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data items in collection
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT, fileTypeParam.GetDisplayName(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT, dataElement.DisplayName.Value, "unexpected length on dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            fileTypeParam.Object = dataElement;
            try
            {
                string displayName = fileTypeParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = fileTypeParam.GetDisplayName();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterContext contextParam = new ConditionDisplayParameterContext(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, contextParam.Object), "unexpected Object");
            Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_DEFAULT == contextParam.Text, "unexpected Text");

            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.CellText)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Footer)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, contextParam.Object), "unexpected Object");
            Assert.AreEqual("Cell text, Footer", contextParam.Text, "unexpected Text");

            m_callbackCalled = false;
            contextParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, contextParam.Object), "unexpected Object");
            Assert.AreEqual("Cell text, Footer", contextParam.Text, "unexpected Text - display name should be same dataElement");

            m_callbackCalled = false;
            contextParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), ConditionUnitFactory.FileContextType.Footnote)));
                contextParam = new ConditionDisplayParameterContext(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
        public void TestConstructor2()
        {
            //empty dataElement
            ConditionDisplayParameterContent contentParam = new ConditionDisplayParameterContent(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, contentParam.Object), "unexpected Object");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT, contentParam.Text, "unexpected Text");

            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "some content"));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "more content"));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Boolean, true));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Boolean, false));
            IDataElement matchWordElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("matchWholeWords"), new NonTranslateableLanguageItem(""), DataType.BooleanArray, dataItems);
            contentParam = new ConditionDisplayParameterContent(dataElement, matchWordElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, contentParam.Object), "unexpected Object");

            m_callbackCalled = false;
            contentParam.Execute();
            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(dataElement, contentParam.Object), "unexpected Object");
            Assert.AreEqual("some content, more content", contentParam.Text, "unexpected Text, display name should be the same as dataElement");

            m_callbackCalled = false;
            contentParam.Execute();
            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, "My content");
                contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
        public void TestConstructor()
        {
            //empty dataElement
            ConditionDisplayParameterFileType fileTypeParam = new ConditionDisplayParameterFileType(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
            Assert.IsTrue(Object.ReferenceEquals(null, fileTypeParam.Object), "unexpected Object");
            Assert.IsTrue(Properties.Resources.IDS_EXPRESSION_PARAM_FILETYPE_DEFAULT == fileTypeParam.Text, "unexpected Text");
                        
            //nominal case with no display name
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument)));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, fileTypeParam.Object), "unexpected Object");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.Text, "unexpected Text");

            m_callbackCalled = false;
            fileTypeParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //nominal case with display name
            dataElement.DisplayName.Value = "This is a display name";
            fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);

            Assert.IsTrue(Object.ReferenceEquals(dataElement, fileTypeParam.Object), "unexpected Object");
            Assert.AreEqual("Word (.doc/.docx/.docm/.dotx/.dotm), Excel Spreadsheet (.xls/.xlsx/.xlsm/.xltx/.xltm)", fileTypeParam.Text, "unexpected Text - displayname should be the same as dataElement");

            m_callbackCalled = false;
            fileTypeParam.Execute();

            Assert.IsTrue(m_callbackCalled, "Execute not called");

            //invalid format case
            try
            {
                dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.ExcelSheet)));
                fileTypeParam = new ConditionDisplayParameterFileType(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
                Assert.IsTrue(false, "Didnt throw on invalid dataelement");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "unexpected exception thrown");
            }
        }
Ejemplo n.º 7
0
 public static object StringArrayToPolicyObjectModelStringArray(string[] items)
 {
     IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
     foreach (string item in items)
     {
         dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, item));
     }
     return dataItems;
 }
Ejemplo n.º 8
0
        public void TestClone_CollectionOfItems()
        {
            PolicyObjectCollection<IDataItem> items = new PolicyObjectCollection<IDataItem>();

            items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 1"));
            items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 2"));
            items.Add(DataItem.CreateDataItem(new TranslateableLanguageItem(Guid.NewGuid()), DataType.String, "string 3"));

            DataElement elem = new DataElement(
                new TranslateableLanguageItem(Guid.NewGuid()),
                new TranslateableLanguageItem(Guid.NewGuid()),
                DataType.String,
                items
                );

            DataElement copy = elem.Clone() as DataElement;
            Assert.IsNotNull(copy.Data);

            PolicyObjectCollection<IDataItem> copyOfItems = copy.Data as PolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(copyOfItems);

            Assert.AreEqual(3, copyOfItems.Count);

            for (int i = 0; i < copyOfItems.Count; i++)
            {
                IDataItem item = items[i];
                IDataItem copyOfItem = copyOfItems[i];

                Assert.IsNotNull(item);
                Assert.IsNotNull(copyOfItem);

                Assert.AreNotEqual(item.Identifier, copyOfItem.Identifier);
                Assert.AreNotEqual(item.Name.Identifier, copyOfItem.Name.Identifier);
                Assert.AreEqual(item.Name.Value, copyOfItem.Name.Value);
                Assert.AreEqual(item.ReadOnly, copyOfItem.ReadOnly);
                Assert.AreEqual(item.Value, copyOfItem.Value);
            }
        }
Ejemplo n.º 9
0
        public IPolicyObjectCollection<IDataElement> Read()
        {
            if (m_dataElementsNode == null)
                throw new Workshare.Policy.Exceptions.ArgumentNullException("m_dataElementsNode", "Data elements node is null");

            IPolicyObjectCollection<IDataElement> dataElements = new PolicyObjectCollection<IDataElement>();

            foreach (XmlNode dataElementNode in m_dataElementsNode)
            {
                dataElements.Add(new XmlDataElementReader(dataElementNode).Read());
            }

            return dataElements;
        }
Ejemplo n.º 10
0
        private void FilterPolicies(IPolicySet policySet)
        {
            if (null == policySet)
                return;

            IPolicyObjectCollection<IPolicy> policies = new PolicyObjectCollection<IPolicy>();

            foreach (IPolicy policy in policySet.Policies)
            {
                IPolicy reducedPolicy = FilterPolicy(policy);
                if (null == reducedPolicy)
                    continue;

                policies.Add(reducedPolicy);
            }
            
            m_reducedPolicySet.Policies = policies;
        }
Ejemplo n.º 11
0
        public void TestWriteRuleHttpRouting()
        {
            string testLanguage = m_testPath + "TestHttpRoutingLanguage.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{E4C8224A-4CBC-4BFF-B50E-A7E60AAABCFD}"), languageId, catalogueStore);
            policyCatalogue.Name = new TranslateableLanguageItem("{3DDE25D7-E892-430D-A85C-075EBA5535AC}");
            catalogueStore.AddPolicyCatalogue(policyCatalogue);

            XmlStore store = new XmlStore();

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);

            RoutingTable routing = RoutingTableFactory.Instance.Create(ChannelType.HTTP, new Guid("{8B097CCF-02C8-40C4-9866-AD6EC09C5AB2}"), new NonTranslateableLanguageItem("Test active content routing"), false) as RoutingTable;
            Assert.IsNotNull(routing);
            IRoutingItemCollection defaultRecipient = routing.DefaultDestination;
            Assert.IsNotNull(defaultRecipient);
            IRoutingItemCollection defaultSender = routing.DefaultSource;
            Assert.IsNotNull(defaultSender);
            IRoutingMatrixCell routingCell = routing[defaultSender, defaultRecipient];
            Assert.IsNotNull(routingCell);

            channel.Routing = routing;
            channels.Add(channel);

            policy.Channels = channels;

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");
            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            TestHelpers.CompareXml(m_testPath + "TestHttpRoutingPolicySet.xml", store.StoreXML);

            string expectedCatalogue = System.IO.File.ReadAllText(m_testPath + "TestHttpRoutingCatalogue.xml");
            expectedCatalogue = expectedCatalogue.Replace("{A176A59A-8AFB-4820-B7D4-4074B64C9F14}", defaultSender.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{14C8BE82-D52D-4CE3-9131-FBEA60C88731}", defaultRecipient.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{ABBFAC23-846B-42D8-BA14-84CB9E5A095A}", routingCell.Description.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6D82D228-A194-4F00-BEE1-DF01368E572F}", defaultSender.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{7EC9EBD4-67B3-42C3-A750-12CFC9B4DFD0}", defaultRecipient.Name.Identifier.ToString("B").ToUpper());

            string catalogueFile = m_testPath + "TestHttpRoutingCatalogue.xml.tmp";
            System.IO.File.WriteAllText(catalogueFile, expectedCatalogue);

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            TestHelpers.CompareXml(catalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 12
0
        public void TestWriteChildCollectionRuleChannels()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            channel.Actions = BuildActionMatrix(policy, false); 
            channel.Routing = BuildSmtpRouting();
            channels.Add(channel);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, null, policy.Conditions);
            writer.WriteChildCollection(policySet, policy, "Copy of test rule", CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteChildCollectionRuleChannels.xml", store.StoreXML);
        }
Ejemplo n.º 13
0
        public void TestWriteMultiplePoliciesMultipleChannels()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);

            IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>();
            PolicyChannel channel = new PolicyChannel(new Guid("{EB97BB54-CB76-46EE-B024-3F747ED4424F}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            channel.Routing = BuildSmtpRouting();
            channel.Actions = BuildActionMatrix(policy, false);
            channels.Add(channel);

            writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels);

            ObjectModel.PolicySet policySet2 = new ObjectModel.PolicySet(new Guid("{807F2757-373C-4629-AB4E-F0AEB3DE447B}"), new TranslateableLanguageItem("{F7916FE9-8871-4650-A3ED-9597A3F91A74}"), store, policyCatalogue, false);
            writer.WritePolicySet(policySet2);
            writer.WritePolicy(policySet2, policy);
            writer.WriteChildCollection(policySet2, policy, "Conditions", policy.Conditions);

            channel = new PolicyChannel(new Guid("{B28CD900-603B-4FE7-9994-EE2B7BCAD2F8}"), new TranslateableLanguageItem("{BFC3A7A1-E753-48CF-BB41-F2765D08B1B5}"), ChannelType.SMTP);
            channel.Routing = BuildSmtpRouting();
            channels.Add(channel);

            writer.WriteChildCollection(policySet2, policy, policy.Name.Value, channels);

            writer.Close();

            TestHelpers.CompareXml(m_testPath + "ExpectedWriteMultiplePoliciesMultipleChannels.xml", store.StoreXML);
        }
Ejemplo n.º 14
0
        public void TestWriteReadOnlyChannelActions()
        {
            string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml";
            string testLanguage = m_testPath + "TestRealPolicyLanguage.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);

            channel.Actions = BuildActionMatrix(policy, false);

            Dictionary<KeyValuePair<Guid, Guid>, IActionMatrixCell>.Enumerator actionMatrixEnumerator = channel.Actions.GetEnumerator();
            actionMatrixEnumerator.MoveNext();

            IActionMatrixCell actionMatrixCell = actionMatrixEnumerator.Current.Value;
            IActionConditionGroup actionConditionGroup = actionMatrixCell.ActionConditionGroups[0];
            ObjectModel.Action action = actionConditionGroup.ActionGroup.ActionGroups[0].Actions[0] as ObjectModel.Action;
            actionConditionGroup.ActionGroup.ActionGroups[0].Actions.RemoveAt(0);
            actionConditionGroup.ActionGroup.ActionGroups[0].Actions.Insert(0, action.DeepCopy(true));

            channels.Add(channel);

            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels);
            writer.Close();

			TestHelpers.CompareXml(m_testPath + "ExpectedWriteReadOnlyChannelActions.xml", store.StoreXML);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        private void EditFileTypeParameter(RuleObject sender)
        {
            List<Workshare.Policy.FileType> originalFileTypes = GetCurrentFileTypes();

            //work out what file types have contexts
            Array enumTypes = Enum.GetValues(typeof(Workshare.Policy.FileType));
            List<Workshare.Policy.FileType> availableFileTypes = new List<Workshare.Policy.FileType>();
            foreach (Workshare.Policy.FileType type in enumTypes)
            {
				if (FileTypeToContextMapper.Instance.FileTypeHasContext(type))
				{
					availableFileTypes.Add(type);
				}
            }

            //do editing
            ((ConditionDisplayParameterFileType)sender).Edit(availableFileTypes);
            List<Workshare.Policy.FileType> newFileTypes = GetCurrentFileTypes();

            bool fileTypesChanged = false;
            if (originalFileTypes.Count == newFileTypes.Count)
            {                
                foreach (Workshare.Policy.FileType fileType in newFileTypes)
                {
                    if (!originalFileTypes.Contains(fileType))
                    {
                        fileTypesChanged = true;
                        break;
                    }
                }
            }
            else
            {
                fileTypesChanged = true;
            }

            if (fileTypesChanged)
            {
                //update contexts to contain only those allowed by the new file type selection

                //create list of currently selected contexts that are valid for the new file types
                IDataElement dataElement = m_contextData.Object as IDataElement;
                IPolicyObjectCollection<IDataItem> originalContexts = dataElement.Data as IPolicyObjectCollection<IDataItem>;
                IPolicyObjectCollection<IDataItem> newContexts = new PolicyObjectCollection<IDataItem>();
                List<ConditionUnitFactory.FileContextType> validContexts = FileTypeToContextMapper.Instance.GetContextsForFileType(newFileTypes, m_type);
                foreach (IDataItem dataItem in originalContexts)
                {
                    ConditionUnitFactory.FileContextType contextType = (ConditionUnitFactory.FileContextType)Enum.Parse(typeof(ConditionUnitFactory.FileContextType), dataItem.Value.ToString());
                    if (validContexts.Contains(contextType))
                    {
                        newContexts.Add(dataItem);
                    }
                }

                //ensure we have at least one value set
                if (newContexts.Count == 0)
                {
                    ConditionUnitFactory.FileContextType defaultContext = FileTypeToContextMapper.Instance.GetDefaultContextForFileType(newFileTypes[0]);
                    newContexts.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileContextType), defaultContext)));
                }

                //update the selected contexts
                originalContexts.Clear();
                foreach (IDataItem dataItem in newContexts)
                {
                    originalContexts.Add(dataItem);
                }

                //set display name
                if (newContexts.Count == validContexts.Count)
                {
                    dataElement.DisplayName.Value = Properties.Resources.IDS_EXPRESSION_PARAM_CONTEXT_ANY;
                }
                else
                {
                    dataElement.DisplayName.Value = m_contextData.GetDisplayNameFromDataItems();
                }
                m_contextData.Text = dataElement.DisplayName.Value;
            }
        }
Ejemplo n.º 16
0
        public void TestActionExceptionHandlerWithOffline()
        {
            string testCatalogue = m_testPath + "TestActionExceptionHandlerWithOffline.Catalogue.xml";
            string testLanguage = m_testPath + "TestActionExceptionHandlerWithOffline.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);

            // Build the ActionException cell for the action matrix.
            IActionMatrix actions = new ObjectModel.ActionMatrix();

            ActionExceptionCell actionExceptionCell = actions.ActionExceptionHandler as ObjectModel.ActionExceptionCell;
            Assert.IsNotNull(actionExceptionCell);

            OfflineActionMatrixCell offlineCell = actions.Offline as OfflineActionMatrixCell;

            ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false);
            ICondition subCondition = new Condition(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), "ITestOne", OperatorType.GreaterThan);

            DataMethod dataMethod = new DataMethod("Test method");
            dataMethod.Parameters.Add(new Parameter("FindSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "missing")));
            dataMethod.Parameters.Add(new Parameter("RunSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "just do it!")));
            DataSource dataSource = new DataSource("Testme.dll", "TestMe", dataMethod);
            subCondition.DataLeft = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Do testing stuff"), new TranslateableLanguageItem(""), DataType.Object, dataSource);
            IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, "10");
            subCondition.DataRight = new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new TranslateableLanguageItem(""), DataType.Long, dataItem);
            conditionGroup.Conditions.Add(subCondition);

            policy.Conditions.Add(conditionGroup);
            actionExceptionCell.AddActionCondition(conditionGroup, BuildActionGroup(), false);

            channel.Actions = actions;
            channels.Add(channel);
            policy.Channels = channels;

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");
            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, policy.Conditions);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            string expectedPolicySetFile = m_testPath + "TestActionExceptionHandlerWithOffline.PolicySet.xml";
            TestHelpers.CompareXml(expectedPolicySetFile, store.StoreXML);
        }
Ejemplo n.º 17
0
        private IPolicyObjectCollection<IPolicyObject> BuildConditions()
        {
            DataMethod dataMethod = new DataMethod("Test method");
            dataMethod.Parameters.Add(new Parameter("FindSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "missing")));
            dataMethod.Parameters.Add(new Parameter("RunSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "just do it!")));
            DataSource dataSource = new DataSource("Testme.dll", "TestMe", dataMethod);

            ICondition subCondition = new Condition(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), "ITestOne", OperatorType.GreaterThan);
            subCondition.DataLeft = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Do testing stuff"), new TranslateableLanguageItem(""), DataType.Object, dataSource);
            IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, "10");
            subCondition.DataRight = new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new TranslateableLanguageItem(""), DataType.Long, dataItem);

            IConditionGroup subConditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Test group two"), ConditionLogic.AND, false);
            subConditionGroup.Conditions.Add(subCondition);
            IConditionGroup conditionGroup = new ConditionGroup(new Guid("{D64056E5-A19D-4B29-8F4A-A70337B42A19}"), new TranslateableLanguageItem("Test group one"), ConditionLogic.OR, true);
            conditionGroup.Conditions.Add(subConditionGroup);

            DataMethod dataMethod2 = new DataMethod("Test method two");
            dataMethod2.Parameters.Add(new Parameter("DoIt", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "You should do this")));
            dataMethod2.Parameters.Add(new Parameter("DontDoIt", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "You should not do this")));
            DataSource dataSource2 = new DataSource("Test2.dll", "JustDoIt", dataMethod2);

            ICondition condition = new Condition(new Guid("{A6F876B6-AD6D-4842-BC0D-4635D1EEE916}"), "ITestTwo", OperatorType.GreaterThanOrEqualTo);
            condition.DataLeft = new DataElement(new Guid("{7CED5561-FD8C-423C-838F-9440EDFE6758}"), new TranslateableLanguageItem("Some data source"), new TranslateableLanguageItem(""), DataType.Object, dataSource2);
            IDataItem dataItem2 = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item 2"), DataType.Long, "2");
            condition.DataRight = new DataElement(new Guid("{C6E38158-AB8C-496B-B97D-FD413680977D}"), new TranslateableLanguageItem("Test result2"), new TranslateableLanguageItem(""), DataType.Long, dataItem2);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            conditions.Add(conditionGroup);
            conditions.Add(condition);

            return conditions;
        }
Ejemplo n.º 18
0
        public void TestCanLoadAction()
        {
            AddEditActionsForm addEditActionsForm = new AddEditActionsForm(null);
            IPolicyObjectCollection<IAction> currentlyLoadedActions = new PolicyObjectCollection<IAction>();

            //Test that we can load an action when there are none currently active in the cell.
            addEditActionsForm.CurrentActions = new PolicyObjectCollection<IAction>();
            MockResourceAction mockAction1 = new MockResourceAction("TestAction", true);
            Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, mockAction1), "Expected to be able to load an action when the current list is empty");

            MockResourceAction nonCoExistableAction = new MockResourceAction("NoCoExistableAction", false);
            Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, nonCoExistableAction), "Expected to be able to load an action when the current list is empty when coexist = false");

            //Test that we cannot load actions into a non empty cell when co-exist = false
            IPolicyObjectCollection<IAction> actions = new PolicyObjectCollection<IAction>();
            actions.Add(new MockAction("TestAction"));
            addEditActionsForm.CurrentActions = actions;
            Assert.IsFalse(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("OtherTestAction", false)), "Should not be able to load any other actions if the action you are trying to add has CoExist = false");

            //Test that we can load another action into the cell when co-exist = true
            Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("OtherTestAction", true)), "Should be able to load other actions if the action you are trying to add has CoExist = true");

            //Test that we cannot load two actions of the same type into any cell.
            Assert.IsFalse(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("TestAction", true)), "Should not be able to add an action of this class because the current list already contains one");

            //Test that we can add actions of different types with no problem
            Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionA", true)), "If the class name is unique to the list and co-exist is true, should be able to add this item.");
            Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionB", true)), "If the class name is unique to the list and co-exist is true, should be able to add this item.");
            Assert.IsTrue(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionC", true)), "If the class name is unique to the list and co-exist is true, should be able to add this item.");

            actions.Add(new MockAction("ActionC"));
            addEditActionsForm.CurrentActions = actions;
            Assert.IsFalse(CanLoadActionHelper(addEditActionsForm, new MockResourceAction("ActionC", true)), "Should not be able to add an action of this class because the current list already contains one");
            
        }
Ejemplo n.º 19
0
		private static ICondition CreateEmailAddressesCondition()
		{
			//condition
			ICondition condition = new Condition(Guid.NewGuid(), "IDataComparer", new TranslateableLanguageItem(""), OperatorType.Equals);

			//condition attributes
			CustomAttributes.SetPreDefinedConditionType(condition, PreDefinedConditionType.EmailAdresses);
			CustomAttributes.SetIgnore(condition, false);
			CustomAttributes.SetLongDescription(condition, "");
			CustomAttributes.SetRiskRating(condition, RiskRatingType.Medium);
			CustomAttributes.SetConditionSummary(condition, "");


			//data left
			IDataMethod method = new DataMethod("AddressMatch");

			//file parameter to allow filtering on types within the condition code, not actually displayed in the designer
			IDataMethod fileMethod = new DataMethod("CurrentFile");
			IDataSource dataSource = new DataSource("this", "this", fileMethod);
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("file"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			IParameter parameter = new Parameter("file", dataElement);
			method.Parameters.Add(parameter);

			//source and destination
			IDataMethod destinationMethod = new DataMethod("Destination");
			dataSource = new DataSource("this", "this", destinationMethod);
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("destination"), new NonTranslateableLanguageItem(""),
				DataType.Object, dataSource);
			parameter = new Parameter("destination", dataElement);
			method.Parameters.Add(parameter);

			IDataMethod sourceMethod = new DataMethod("Source");
			dataSource = new DataSource("this", "this", sourceMethod);
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("source"), new NonTranslateableLanguageItem(""),
				DataType.Object, dataSource);
			parameter = new Parameter("source", dataElement);
			method.Parameters.Add(parameter);


			//addressType fields parameter
			IPolicyObjectCollection<IDataItem> collection = new PolicyObjectCollection<IDataItem>();
			collection.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(AddressTypes),
				AddressTypes.To)));
			collection.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(AddressTypes),
				AddressTypes.Cc)));
			collection.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(AddressTypes),
				AddressTypes.Bcc)));

			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("addressTypes"), new NonTranslateableLanguageItem(""), DataType.StringArray, collection);

			parameter = new Parameter("addressTypes", dataElement);
			method.Parameters.Add(parameter);


			//address parameter
			collection = new PolicyObjectCollection<IDataItem>();
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("address"), new NonTranslateableLanguageItem(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT), DataType.StringArray, collection);
			parameter = new Parameter("address", dataElement);
			method.Parameters.Add(parameter);



			dataSource = new DataSource("Workshare.Policy.Condition.ContentAnalysis.dll", "Workshare.Policy.Condition.EmailAnalyzer", method);
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("emailAddresses"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			condition.DataLeft = dataElement;

			//dataright
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("addressMatch"), new NonTranslateableLanguageItem(""), DataType.Boolean, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Boolean, Boolean.TrueString));
			condition.DataRight = dataElement;

			return condition;
		}
Ejemplo n.º 20
0
		private static ICondition CreateHiddenDataInFileTypeCondition()
		{
			//hidden data in file type condition
			ICondition condition = new Condition(Guid.NewGuid(), "IDataLengthComparer", new TranslateableLanguageItem(""), OperatorType.GreaterThan);

			//condition attributes            
			CustomAttributes.SetPreDefinedConditionType(condition, PreDefinedConditionType.HiddenDataInFile);
			CustomAttributes.SetIgnore(condition, false);
			CustomAttributes.SetLongDescription(condition, "");
			CustomAttributes.SetRiskRating(condition, RiskRatingType.Medium);

			//dataleft
			IDataMethod method = new DataMethod("RegExLookupInFileType");

			//file parameter
			IDataMethod fileMethod = new DataMethod("CurrentFile");
			IDataSource dataSource = new DataSource("this", "this", fileMethod);
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("file"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			IParameter parameter = new Parameter("file", dataElement);
			method.Parameters.Add(parameter);

			//file types parameter
			method.Parameters.Add(CreateFileTypesParameter());

			//content parameter - will be empty, and is not editable by the user
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("content"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, ""));
			parameter = new Parameter("", dataElement);
			method.Parameters.Add(parameter);

			//hidden data parameter
			IPolicyObjectCollection<IDataItem> collection = new PolicyObjectCollection<IDataItem>();
			collection.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(FileHiddenDataType), FileHiddenDataType.TrackChange)));
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("hidden data type"), new NonTranslateableLanguageItem(""), DataType.StringArray, collection);
			parameter = new Parameter("hidden data type", dataElement);
			method.Parameters.Add(parameter);

			dataSource = new DataSource("Workshare.Policy.Condition.ContentAnalysis.dll", "Workshare.Policy.Condition.ContentAnalysis", method);
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("hiddenDataInFile"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			condition.DataLeft = dataElement;

			//dataright
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("numberOfOccurrences"), new NonTranslateableLanguageItem(""), DataType.Long, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Long, 0));
			condition.DataRight = dataElement;

			return condition;
		}
Ejemplo n.º 21
0
		private static ICondition CreateRegexInFileContextCondition()
		{
			//file type contains regex in file context condition
			ICondition condition = new Condition(Guid.NewGuid(), "IDataLengthComparer", new TranslateableLanguageItem(""), OperatorType.GreaterThan);

			//condition attributes
			CustomAttributes.SetPreDefinedConditionType(condition, PreDefinedConditionType.RegexInFileContext);
			CustomAttributes.SetIgnore(condition, false);
			CustomAttributes.SetLongDescription(condition, "");
			CustomAttributes.SetRiskRating(condition, RiskRatingType.Medium);

			//dataleft
			IDataMethod method = new DataMethod("RegExLookupInFileType");

			//file parameter
			IDataMethod fileMethod = new DataMethod("CurrentFile");
			IDataSource dataSource = new DataSource("this", "this", fileMethod);
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("file"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			IParameter parameter = new Parameter("file", dataElement);
			method.Parameters.Add(parameter);

			//file types parameter
			method.Parameters.Add(CreateFileTypesParameter());

			//regex parameter
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("regex"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Properties.Resources.IDS_EXPRESSION_PARAM_REGEX_DEFAULT));
			parameter = new Parameter("regex", dataElement);
			method.Parameters.Add(parameter);

			//context parameter
			IPolicyObjectCollection<IDataItem> collection = new PolicyObjectCollection<IDataItem>();
			collection.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(FileContextType), FileContextType.Paragraph)));
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("context"), new NonTranslateableLanguageItem(""), DataType.StringArray, collection);
			parameter = new Parameter("context", dataElement);
			method.Parameters.Add(parameter);

			dataSource = new DataSource("Workshare.Policy.Condition.ContentAnalysis.dll", "Workshare.Policy.Condition.ContentAnalysis", method);
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("regexInFileContext"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource);
			condition.DataLeft = dataElement;

			//dataright
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("numberOfOccurrences"), new NonTranslateableLanguageItem(""), DataType.Long, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.Long, 0));
			condition.DataRight = dataElement;

			return condition;
		}
		/// <summary>
		/// 
		/// </summary>
		private void EditFileTypeParameter(RuleObject sender)
		{
			List<Policy.FileType> originalFileTypes = GetFileTypes();

			//work out what file types have hidden data
			Array enumTypes = Enum.GetValues(typeof(Policy.FileType));
			List<Policy.FileType> availableFileTypes = new List<Policy.FileType>();
			foreach (Policy.FileType type in enumTypes)
			{
				if (FileTypeToHiddenDataMapper.FileTypeHasHiddenData(type))
				{
					if (type != Policy.FileType.PDFDocument) // We have a PDF Hidden Data condition
						availableFileTypes.Add(type);
				}
			}

			//do editing
			((ConditionDisplayParameterFileType) sender).Edit(availableFileTypes);
			List<Policy.FileType> newFileTypes = GetFileTypes();

			//has file type selection changed?
			bool fileTypesChanged = false;
			if (originalFileTypes.Count == newFileTypes.Count)
			{
				foreach (Policy.FileType fileType in newFileTypes)
				{
					if (!originalFileTypes.Contains(fileType))
					{
						fileTypesChanged = true;
						break;
					}
				}
			}
			else
			{
				fileTypesChanged = true;
			}

			//update selected contexts
			if (fileTypesChanged)
			{
				IDataElement dataElement = m_hiddenDataTypeData.Object as IDataElement;
				IPolicyObjectCollection<IDataItem> originalHiddenData = dataElement.Data as IPolicyObjectCollection<IDataItem>;
				IPolicyObjectCollection<IDataItem> newHiddenData = new PolicyObjectCollection<IDataItem>();
				List<ConditionUnitFactory.FileHiddenDataType> validHiddenData = FileTypeToHiddenDataMapper.GetHiddenDataForFileType(newFileTypes);

				foreach (IDataItem dataItem in originalHiddenData)
				{
					ConditionUnitFactory.FileHiddenDataType hiddenDataType = (ConditionUnitFactory.FileHiddenDataType) Enum.Parse(typeof(ConditionUnitFactory.FileHiddenDataType), dataItem.Value.ToString());
					if (validHiddenData.Contains(hiddenDataType))
					{
						newHiddenData.Add(dataItem);
					}
				}

				//ensure we have at least one value set
				if (newHiddenData.Count == 0)
				{
					ConditionUnitFactory.FileHiddenDataType defaultHiddenData = FileTypeToHiddenDataMapper.GetDefaultHiddenDataForFileType(newFileTypes[0]);
					newHiddenData.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), defaultHiddenData)));
				}

				//update the selected hidden data types
				originalHiddenData.Clear();
				foreach (IDataItem dataItem in newHiddenData)
				{
					originalHiddenData.Add(dataItem);
				}

				//set display name
				if (newHiddenData.Count == validHiddenData.Count)
				{
					dataElement.DisplayName.Value = Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_ANY;
				}
				else
				{
					dataElement.DisplayName.Value = m_hiddenDataTypeData.GetDisplayNameFromDataItems();
				}
				m_hiddenDataTypeData.Text = dataElement.DisplayName.Value;
			}
		}
Ejemplo n.º 23
0
        public void TestWriteSmtpOfflineRouting()
        {
            string testCatalogue = m_testPath + "TestSmtpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestSmtpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.SMTP);
            IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called
            channel.Routing = routings;
            channels.Add(channel);
            policy.Channels = channels;

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestSmtpOfflineRouting.Catalogue.Modified.xml";
            string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile);
            expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogueFile = expectedCatalogueFile + ".tmp";
            System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue);

            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 24
0
        public void TestAddCondition_AddFromCatalogue()
        {
            //set up environment
            IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", m_policySet, PolicyStatus.Active, "None");
            IConditionGroup rootConditionGroup = (IConditionGroup)policy.Conditions[0];
            DynamicMock conditionsCatalogueSelectForm = new DynamicMock(typeof(IConditionsCatalogueSelectorForm));

            //set up test object
            AddConditionState state = new AddConditionStateTester();
            state.Policy = policy;
            state.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            state.ConditionGroup = rootConditionGroup;
            //state.ConditionMethodDisplay = null;
            state.Source = AddConditionState.ConditionSource.FromCatalogue;
            state.SelectionUI = conditionsCatalogueSelectForm.MockInstance;

            //test conditions group is empty
            Assert.AreEqual(0, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //add new condition
            IState showConditionsState = new ShowConditionsState();
            m_stateMachine.ExpectAndReturn("GetState", showConditionsState, StateTypeEnum.ShowConditions);
            m_stateMachine.Expect("SetState", showConditionsState);

            IPolicyObjectCollection<IPolicyObject> selectedConditions = new PolicyObjectCollection<IPolicyObject>();
            ICondition condition1 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.ContentInFileContext);
            ICondition condition2 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.ContentInFileName);
            ICondition condition3 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.FileSize);
            selectedConditions.Add(condition1);
            selectedConditions.Add(condition2);
            selectedConditions.Add(condition3);
            conditionsCatalogueSelectForm.ExpectAndReturn("get_SelectedConditions", selectedConditions, new object[0]);

            state.Enter();

            //test root condition group
            Assert.AreEqual(3, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //test conditions
            ICondition condition1Copy = rootConditionGroup.Conditions[0] as ICondition;
            ICondition condition2Copy = rootConditionGroup.Conditions[1] as ICondition;
            ICondition condition3Copy = rootConditionGroup.Conditions[2] as ICondition;

            //condition1
            Assert.IsNotNull(condition1Copy, "unexpected object type in condition");
            Assert.AreEqual(condition1.Name.Value, condition1Copy.Name.Value, "unexpected condition name");
            Assert.AreEqual(condition1.Operator, condition1Copy.Operator, "unexpected name in condition");
            Assert.AreEqual(condition1.Class, condition1Copy.Class, "unexpected class in condition");
            Assert.AreEqual(condition1["preDefinedConditionType"].Identifier, condition1Copy["preDefinedConditionType"].Identifier, "unexpected pre-defined condition type");
            Assert.AreEqual(condition1["preDefinedConditionType"].Value, condition1Copy["preDefinedConditionType"].Value, "unexpected pre-defined condition type");
            Assert.AreEqual(condition1["Ignore"].Identifier, condition1Copy["Ignore"].Identifier, "unexpected identifier on Ignore attribute on condition1");
            Assert.AreEqual(condition1["Ignore"].Value, condition1Copy["Ignore"].Value, "unexpected value on Ignore attribute on condition1");

            //condition1copy.dataleft
            IDataElement dataLeft = condition1.DataLeft as IDataElement;
            IDataElement dataLeftCopy = condition1Copy.DataLeft as IDataElement;
            Assert.AreEqual(dataLeft.DisplayName.Identifier, dataLeftCopy.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft");
            Assert.AreEqual(dataLeft.DisplayName.Value, dataLeftCopy.DisplayName.Value, "unexpected display name in condition1copy.dataleft");
            Assert.AreEqual(dataLeft.Name.Identifier, dataLeftCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft");
            Assert.AreEqual(dataLeft.Name.Value, dataLeftCopy.Name.Value, "unexpected name in condition1copy.dataleft");
            Assert.AreEqual(dataLeft.ReadOnly, dataLeftCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft");
            Assert.AreEqual(dataLeft.Type, dataLeftCopy.Type, "unexpected type in condition1copy.dataleft");

            //condition1copy.dataleft.data 
            IDataSource dataSource = dataLeft.Data as IDataSource;
            IDataSource dataSourceCopy = dataLeftCopy.Data as IDataSource;
            Assert.AreEqual(dataSource.Assembly, dataSourceCopy.Assembly, "unexpected assembly in condition1copy.dataleft.data");
            Assert.AreEqual(dataSource.Class, dataSourceCopy.Class, "unexpected class in condition1copy.dataleft.data");
            Assert.AreEqual(dataSource.Name.Identifier, dataSourceCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.dataleft.data");
            Assert.AreEqual(dataSource.Name.Value, dataSourceCopy.Name.Value, "unexpected name in condition1copy.dataleft.data");

            //condition1copy.dataleft.data.method 
            IDataMethod dataMethod = dataSource.Method as IDataMethod;
            IDataMethod dataMethodCopy = dataSourceCopy.Method as IDataMethod;
            Assert.AreEqual(dataMethod.Name.Identifier, dataMethodCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method");
            Assert.AreEqual(dataMethod.Name.Value, dataMethodCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method");
            Assert.AreEqual(dataMethod.Parameters.Count, dataMethodCopy.Parameters.Count, "unexpected number of parameters in condition1copy.dataleft.data.method");

            //condition1copy.dataleft.data.method.parameters[0]
            IParameter parameter = dataMethod.Parameters[0];
            IParameter parameterCopy = dataMethodCopy.Parameters[0];
            Assert.AreEqual(parameter.Name.Identifier, parameterCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[0]");
            Assert.AreEqual(parameter.Name.Value, parameterCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[0]");

            //condition1copy.dataleft.data.method.parameters[0].value
            IDataElement dataElement = dataMethod.Parameters[0].Value as IDataElement;
            IDataElement dataElementCopy = dataMethodCopy.Parameters[0].Value as IDataElement;
            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(dataElement.DisplayName.Value, dataElementCopy.DisplayName.Value, "unexpected displayname in condition1copy.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(dataElement.ReadOnly, dataElementCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(dataElement.Type, dataElementCopy.Type, "unexpected datatype in condition1copy.dataleft.data.method.parameters[0].value");

            //condition1copy.dataleft.data.method.parameters[0].value.data
            dataSource = dataElement.Data as IDataSource;
            dataSourceCopy = dataElementCopy.Data as IDataSource;
            Assert.AreEqual(dataSource.Assembly, dataSourceCopy.Assembly, "unexpected assembly in condition1copy.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual(dataSource.Class, dataSourceCopy.Class, "unexpected class in condition1copy.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual(dataSource.Name.Identifier, dataSourceCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual(dataSource.Name.Value, dataSourceCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[0].value.data");

            //condition1copy.dataleft.data.method.parameters[0].value.data.method
            IDataMethod fileDataMethod = dataSource.Method as IDataMethod;
            IDataMethod fileDataMethodCopy = dataSourceCopy.Method as IDataMethod;
            Assert.AreEqual(fileDataMethod.Name.Identifier, fileDataMethodCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[0].value.method");
            Assert.AreEqual(fileDataMethod.Name.Value, fileDataMethodCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual(fileDataMethod.Parameters.Count, fileDataMethodCopy.Parameters.Count, "unexpected number of parameters in condition1copy.dataleft.data.method.parameters[0].value.data.method");

            //condition1copy.dataleft.data.method.parameters[1]
            parameter = dataMethod.Parameters[1];
            parameterCopy = dataMethodCopy.Parameters[1];
            Assert.AreEqual(parameter.Name.Identifier, parameterCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[1]");
            Assert.AreEqual(parameter.Name.Value, parameterCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1]");

            //condition1copy.dataleft.data.method.parameters[1].value
            dataElement = parameter.Value as IDataElement;
            dataElementCopy = parameterCopy.Value as IDataElement;
            Assert.IsNotNull(dataElementCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(dataElement.DisplayName.Value, dataElementCopy.DisplayName.Value, "unexpected displayname in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(dataElement.ReadOnly, dataElementCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition1copy.dataleft.data.method.parameters[1].value");

            //condition1copy.dataleft.data.method.parameters[1].value.data
            IPolicyObjectCollection<IDataItem> collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            IPolicyObjectCollection<IDataItem> collectionCopy = dataElementCopy.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collectionCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[1].value.data");
            Assert.AreEqual(collection.Count, collectionCopy.Count, "unexpected number of items in condition1copy.dataleft.data.method.parameters[1].value.data");

            //condition1copy.dataleft.data.method.parameters[1].value.data[0]
            IDataItem dataItem = collection[0] as IDataItem;
            IDataItem dataItemCopy = collectionCopy[0] as IDataItem;
            Assert.IsNotNull(dataItemCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(dataItem.Name.Identifier, dataItemCopy.Name.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(dataItem.Name.Value, dataItemCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(dataItem.ReadOnly, dataItemCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(dataItem.Value, dataItemCopy.Value, "unexpected value in condition1copy.dataleft.data.method.parameters[1].value.data[0]");

            //condition1copy.dataleft.data.method.parameters[2]
            parameter = dataMethod.Parameters[2];
            parameterCopy = dataMethodCopy.Parameters[2];
            Assert.AreEqual(parameter.Name.Identifier, parameterCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[2]");
            Assert.AreEqual(parameter.Name.Value, parameterCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[2]");

            //condition1copy.dataleft.data.method.parameters[2].value
            dataElement = parameter.Value as IDataElement;
            dataElementCopy = parameter.Value as IDataElement;
            Assert.IsNotNull(dataElementCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(dataElement.DisplayName.Value, dataElementCopy.DisplayName.Value, "unexpected displayname in condition1copy.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(dataElement.ReadOnly, dataElementCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(dataElement.Type, dataElementCopy.Type, "unexpected datatype in condition1copy.dataleft.data.method.parameters[2].value");

            //condition1copy.dataleft.data.method.parameters[2].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            collectionCopy = dataElementCopy.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collectionCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[2].value.data");
            Assert.AreEqual(collection.Count, collectionCopy.Count, "unexpected number of items in condition1copy.dataleft.data.method.parameters[2].value.data");

            //condition1copy.dataleft.data.method.parameters[3]
            parameter = dataMethod.Parameters[3];
            parameterCopy = dataMethodCopy.Parameters[3];
            Assert.AreEqual(parameter.Name.Identifier, parameterCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[3]");
            Assert.AreEqual(parameter.Name.Value, parameterCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[3]");

            //condition1copy.dataleft.data.method.parameters[3].value
            dataElement = parameter.Value as IDataElement;
            dataElementCopy = parameterCopy.Value as IDataElement;
            Assert.IsNotNull(dataElementCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(dataElement.DisplayName.Value, dataElementCopy.DisplayName.Value, "unexpected displayname in condition1copy.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(dataElement.ReadOnly, dataElementCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(dataElement.Type, dataElementCopy.Type, "unexpected datatype in condition1copy.dataleft.data.method.parameters[3].value");

            //condition1copy.dataleft.data.method.parameters[3].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            collectionCopy = dataElementCopy.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collectionCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[3].value.data");
            Assert.AreEqual(collection.Count, collectionCopy.Count, "unexpected number of items in condition1copy.dataleft.data.method.parameters[3].value.data");

            //condition1copy.dataleft.data.method.parameters[3].value.data[0]
            dataItem = collection[0] as IDataItem;
            dataItemCopy = collectionCopy[0] as IDataItem;
            Assert.IsNotNull(dataItemCopy, "unexpected object type in condition1copy.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(dataItem.Name.Identifier, dataItemCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(dataItem.Name.Value, dataItemCopy.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(dataItem.ReadOnly, dataItemCopy.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(dataItem.Value, dataItemCopy.Value, "unexpected value in conditiongroup.conditions[1].dataleft.data.method.parameters[3].value.data[0]");

            //condition1copy.dataright
            IDataElement dataRight = condition1.DataRight as IDataElement;
            IDataElement dataRightCopy = condition1Copy.DataRight as IDataElement;
            Assert.AreEqual(Guid.Empty, dataRightCopy.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataright");
            Assert.AreEqual(dataRight.DisplayName.Value, dataRightCopy.DisplayName.Value, "unexpected display name in condition1copy.dataright");
            Assert.AreEqual(dataRight.Name.Identifier, dataRightCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataright");
            Assert.AreEqual(dataRight.Name.Value, dataRightCopy.Name.Value, "unexpected name in condition1copy.dataright");
            Assert.AreEqual(dataRight.ReadOnly, dataRightCopy.ReadOnly, "unexpected readonly in condition1copy.dataright");
            Assert.AreEqual(dataRight.Type, dataRightCopy.Type, "unexpected type in condition1copy.dataright");

            //condition1copy.dataright.data
            dataItem = dataRight.Data as IDataItem;
            dataItemCopy = dataRightCopy.Data as IDataItem;
            Assert.AreEqual(dataItem.Name.Identifier, dataItemCopy.Name.Identifier, "unexpected name identifier in condition1copy.dataright.data");
            Assert.AreEqual(dataItem.Name.Value, dataItemCopy.Name.Value, "unexpected name in condition1copy.dataright.data");
            Assert.AreEqual(dataItem.ReadOnly, dataItemCopy.ReadOnly, "unexpected readonly in condition1copy.dataright.data");
            Assert.AreEqual(dataItem.Value, dataItemCopy.Value, "unexpected value in condition1copy.dataright.data");                

            //condition2copy
            Assert.IsNotNull(condition2Copy, "unexpected object type in condition2copy");
            Assert.AreNotEqual(condition2.Identifier, condition2Copy.Identifier);
            Assert.AreEqual(condition2.Name.Value, condition2Copy.Name.Value);
            Assert.AreEqual(condition2.Class, condition2Copy.Class);
            Assert.AreEqual(condition2.Operator, condition2Copy.Operator);
            Assert.AreEqual(Guid.Empty, condition2Copy["preDefinedConditionType"].Identifier, "unexpected identifier on pre-defined condition type in conditiongroup");
            Assert.AreEqual(condition2["preDefinedConditionType"].Value, condition2Copy["preDefinedConditionType"].Value, "unexpected pre-defined condition type on condition2");
            Assert.AreEqual(Guid.Empty, condition2Copy["expressionEntity"].Identifier, "unexpected identifier on \"ExpressionEntity\" attribute in condition2");
            Assert.AreEqual(condition2["expressionEntity"].Value, condition2Copy["expressionEntity"].Value, "unexpected \"ExpressionEntity\" attribute in condition2");

            //condition2copy.dataleft
            dataElement = condition2.DataLeft as IDataElement;
            dataElementCopy = condition2Copy.DataLeft as IDataElement;
            Assert.AreNotEqual(dataElement.Identifier, dataElementCopy.Identifier, "unexpected identifier in condtion2copy.dataleft");
            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier, "unexpected name identifier in condtion2copy.dataleft"); //non-translatable
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value, "unexpected name in condtion2copy.dataleft");
            Assert.AreEqual(dataElement.Type, dataElementCopy.Type, "unexpected type in condtion2copy.dataleft");
            Assert.AreEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier, "unexpected displayname identifier in condtion2copy.dataleft"); //nontranslateable
            Assert.AreEqual(dataElement.DisplayName.Value, dataElementCopy.DisplayName.Value, "unexpected displayname in condtion2copy.dataleft");

            //condition2copy.dataleft.data 
            dataSource = dataElement.Data as IDataSource;
            dataSourceCopy = dataElementCopy.Data as IDataSource;
            Assert.IsNotNull(dataSourceCopy, "unexpected object type in condition2copy.dataleft.data");
            Assert.AreNotEqual(dataSource.Identifier, dataSourceCopy.Identifier, "unexpected identifier in condtion2copy.dataleft.data");
            Assert.AreEqual(dataSource.Assembly, dataSourceCopy.Assembly, "unexpected assembly in condition2copy.dataleft.data");
            Assert.AreEqual(dataSource.Class, dataSourceCopy.Class, "unexpected class in condition2copy.dataleft.data");
            Assert.AreEqual(dataSource.Name.Identifier, dataSourceCopy.Name.Identifier, "unexpected name identifier in condition2copy.dataleft.data"); //nontranslateable
            Assert.AreEqual(dataSource.Name.Value, dataSourceCopy.Name.Value, "unexpected name in condition2copy.dataleft.data");

            //assume that lower level copying is working, as we have already tested in condition 1 and it is covered in the 
            //object model tests

            //condition3Copy
            Assert.AreNotEqual(condition3.Identifier, condition3Copy.Identifier);
            Assert.AreEqual(condition3.Name.Value, condition3Copy.Name.Value);
            Assert.AreEqual(condition3.Class, condition3Copy.Class);
            Assert.AreEqual(condition3.Operator, condition3Copy.Operator);
            Assert.AreEqual(Guid.Empty, condition3Copy["preDefinedConditionType"].Identifier, "unexpected identifier on pre-defined condition type in condition3");
            Assert.AreEqual(condition3["preDefinedConditionType"].Value, condition3Copy["preDefinedConditionType"].Value, "unexpected pre-defined condition type on condition3");
            Assert.AreEqual(Guid.Empty, condition3Copy["expressionEntity"].Identifier, "unexpected identifier on \"ExpressionEntity\" attribute in condition3");
            Assert.AreEqual(condition3["expressionEntity"].Value, condition3Copy["expressionEntity"].Value, "unexpected \"ExpressionEntity\" attribute in condition3");

            //condition3copy.dataleft
            dataElement = condition3.DataLeft as IDataElement;
            dataElementCopy = condition3Copy.DataLeft as IDataElement;
            Assert.AreNotEqual(dataElement.Identifier, dataElementCopy.Identifier, "unexpected identifier in condtion3copy.dataleft");
            Assert.AreEqual(dataElement.Name.Identifier, dataElementCopy.Name.Identifier, "unexpected name identifier in condtion3copy.dataleft"); //non-translatable
            Assert.AreEqual(dataElement.Name.Value, dataElementCopy.Name.Value, "unexpected name in condtion3copy.dataleft");
            Assert.AreEqual(dataElement.Type, dataElementCopy.Type, "unexpected type in condtion3copy.dataleft");
            Assert.AreEqual(dataElement.DisplayName.Identifier, dataElementCopy.DisplayName.Identifier, "unexpected displayname identifier in condtion3copy.dataleft"); //nontranslateable
            Assert.AreEqual(dataElement.DisplayName.Value, dataElementCopy.DisplayName.Value, "unexpected displayname in condtion3copy.dataleft");

            //condition3copy.dataleft.data 
            dataSource = dataElement.Data as IDataSource;
            dataSourceCopy = dataElementCopy.Data as IDataSource;
            Assert.IsNotNull(dataSource, "unexpected object type in condition3copy.dataleft.data");
            Assert.AreNotEqual(dataSource.Identifier, dataSourceCopy.Identifier, "unexpected identifier in condtion3copy.dataleft.data");
            Assert.AreEqual(dataSource.Assembly, dataSourceCopy.Assembly, "unexpected assembly in condition3copy.dataleft.data");
            Assert.AreEqual(dataSource.Class, dataSourceCopy.Class, "unexpected class in condition3copy.dataleft.data");
            Assert.AreEqual(dataSource.Name.Identifier, dataSourceCopy.Name.Identifier, "unexpected name identifier in condition3copy.dataleft.data"); //nontranslateable
            Assert.AreEqual(dataSource.Name.Value, dataSourceCopy.Name.Value, "unexpected name in condition3copy.dataleft.data");

            //assume that lower level copying is working, as we have already tested in condition 1 and it is covered in the 
            //object model tests

            //test state machine state
            m_stateMachine.Verify();

        }
Ejemplo n.º 25
0
        public void TestWriteHttpOfflineRouting()
        {
            string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);
            IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.HTTP);
            IRoutingItemCollection defaultSender = routings.DefaultSource;
            IRoutingItemCollection defaultRecipient = routings.DefaultDestination;
            IRoutingMatrixCell routingCell = routings[defaultSender, defaultRecipient];
            IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called
            channel.Routing = routings;
            channels.Add(channel);
            policy.Channels = channels;

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestHttpOfflineRouting.Catalogue.Modified.xml";
            string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile);
            expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogue = expectedCatalogue.Replace("{73B623E3-7D1A-470B-9C3A-BCE2B4D2B3CD}", defaultSender.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{0FC0FBD3-FC51-4D19-B7CE-04C6A5447E8C}", defaultSender.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E811E002-16F5-41B6-877E-6C7741529965}", defaultRecipient.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{3D594866-8C44-4896-91FD-A549B6481722}", defaultRecipient.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{1BE90656-9FF3-4747-960D-176E6183C673}", routingCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogueFile = expectedCatalogueFile + ".tmp";
            System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue);

            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
Ejemplo n.º 26
0
        public void TestAddCondition_CreateNewCondition()
        {
            //set up environment
            IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", m_policySet, PolicyStatus.Active, "None");
            IConditionGroup rootConditionGroup = (IConditionGroup)policy.Conditions[0];
            DynamicMock conditionsResourceSelectForm = new DynamicMock(typeof(IConditionsResourceSelectorForm));

            //set up test object
            AddConditionState state1 = new AddConditionStateTester();
            state1.Policy = policy;
            state1.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            state1.ConditionGroup = rootConditionGroup;
            //state1.ConditionMethodDisplay = new ConditionDisplayContentInFileContext();
            state1.Source = AddConditionState.ConditionSource.New;
            state1.SelectionUI = conditionsResourceSelectForm.MockInstance;

            IPolicyObjectCollection<IPolicyObject> selectedConditions = new PolicyObjectCollection<IPolicyObject>();
            ICondition condition1 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.ContentInFileContext);
            selectedConditions.Add(condition1);
            conditionsResourceSelectForm.ExpectAndReturn("get_SelectedConditions", selectedConditions, new object[0]);

            //test conditions group is empty
            Assert.AreEqual(0, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //add new condition
            IState showConditionsState = new ShowConditionsState();
            m_stateMachine.ExpectAndReturn("GetState", showConditionsState, StateTypeEnum.ShowConditions);
            m_stateMachine.Expect("SetState", showConditionsState);
            state1.Enter();

            //test condition group
            Assert.AreEqual(1, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //test condition
            ICondition condition = rootConditionGroup.Conditions[0] as ICondition;
            Assert.IsNotNull(condition, "unexpected object type in condition");
            Assert.AreSame(rootConditionGroup, condition.Parent, "Unexpected object in condition.Parent");
            Assert.AreEqual("", condition.Name.Value, "unexpected condition name");
            Assert.AreEqual(OperatorType.GreaterThan, condition.Operator, "unexpected name in condition");
            Assert.AreEqual("IDataLengthComparer", condition.Class, "unexpected class in condition");
            Assert.AreEqual(Guid.Empty, condition["Ignore"].Identifier, "unexpected identifier on Ignore attribute on condition");
            Assert.AreEqual(Boolean.FalseString, condition["Ignore"].Value, "unexpected value on Ignore attribute on condition");

            //condition.dataleft
            IDataElement dataElement = condition.DataLeft as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected display name in condition.dataleft");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft");
            Assert.AreEqual("contentInFileContext", dataElement.Name.Value, "unexpected name in condition.dataleft");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft");
            Assert.AreEqual(DataType.Object, dataElement.Type, "unexpected type in condition.dataleft");

            //condition.dataleft.data 
            IDataSource dataSource = dataElement.Data as IDataSource;
            Assert.IsNotNull(dataSource, "unexpected object type in condition.dataleft.data");
            Assert.AreEqual("Workshare.Policy.Condition.ContentAnalysis.dll", dataSource.Assembly, "unexpected assembly in condition.dataleft.data");
            Assert.AreEqual("Workshare.Policy.Condition.ContentAnalysis", dataSource.Class, "unexpected class in condition.dataleft.data");
            Assert.AreEqual(Guid.Empty, dataSource.Name.Identifier, "unexpected name identifier in condition.dataleft.data");
            Assert.AreEqual("Workshare.Policy.Condition.ContentAnalysis", dataSource.Name.Value, "unexpected name in condition.dataleft.data");

            //condition.dataleft.data.method 
            IDataMethod dataMethod = dataSource.Method as IDataMethod;
            Assert.IsNotNull(dataMethod, "unexpected object type in condition.dataleft.data.method");
            Assert.AreEqual(Guid.Empty, dataMethod.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method");
            Assert.AreEqual("TextLookupInFileType", dataMethod.Name.Value, "unexpected name in condition.dataleft.data.method");
            Assert.AreEqual(5, dataMethod.Parameters.Count, "unexpected number of parameters in condition.dataleft.data.method");

            //condition.dataleft.data.method.parameters[0]
            IParameter parameter = dataMethod.Parameters[0];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0]");
            Assert.AreEqual("file", parameter.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0]");

            //condition.dataleft.data.method.parameters[0].value
            dataElement = dataMethod.Parameters[0].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual("file", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[0].value");
            Assert.AreEqual(DataType.Object, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[0].value");

            //condition.dataleft.data.method.parameters[0].value.data
            dataSource = dataElement.Data as IDataSource;
            Assert.IsNotNull(dataSource, "unexpected object type in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual("this", dataSource.Assembly, "unexpected assembly in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual("this", dataSource.Class, "unexpected class in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual(Guid.Empty, dataSource.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0].value.data");
            Assert.AreEqual("this", dataSource.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0].value.data");

            //condition.dataleft.data.method.parameters[0].value.data.method
            IDataMethod fileDataMethod = dataSource.Method as IDataMethod;
            Assert.IsNotNull(fileDataMethod, "unexpected object type in condition.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual(Guid.Empty, fileDataMethod.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual("CurrentFile", fileDataMethod.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[0].value.data.method");
            Assert.AreEqual(0, fileDataMethod.Parameters.Count, "unexpected number of parameters in condition.dataleft.data.method.parameters[0].value.data.method");

            //condition1copy.dataleft.data.method.parameters[1]
            parameter = dataMethod.Parameters[1];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[1]");
            Assert.AreEqual("fileTypes", parameter.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1]");

            //condition1copy.dataleft.data.method.parameters[1].value
            dataElement = dataMethod.Parameters[1].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual("fileTypes", dataElement.Name.Value, "unexpected name in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition1copy.dataleft.data.method.parameters[1].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition1copy.dataleft.data.method.parameters[1].value");

            //condition.dataleft.data.method.parameters[1].value.data
            IPolicyObjectCollection<IDataItem> collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[1].value.data");
            Assert.AreEqual(5, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[1].value.data");

            //condition.dataleft.data.method.parameters[1].value.data[0]
            IDataItem dataItem = collection[0] as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[1].value");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[1].value.data[0]");
            Assert.AreEqual(Enum.GetName(typeof(Workshare.Policy.FileType), Workshare.Policy.FileType.WordDocument), dataItem.Value, "unexpected value in condition.dataleft.data.method.parameters[1].value.data[0]");

            //condition.dataleft.data.method.parameters[2]
            parameter = dataMethod.Parameters[2];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[2]");
            Assert.AreEqual("content", parameter.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[2]");

            //condition.dataleft.data.method.parameters[2].value
            dataElement = dataMethod.Parameters[2].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual("content", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual("word or phrase", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[2].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[2].value");

            //condition.dataleft.data.method.parameters[2].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[2].value.data");
            Assert.AreEqual(0, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[2].value.data");

            //condition.dataleft.data.method.parameters[3]
            parameter = dataMethod.Parameters[3];
            Assert.AreEqual(Guid.Empty, parameter.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[3]");
            Assert.AreEqual("context", parameter.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[3]");

            //condition.dataleft.data.method.parameters[3].value
            dataElement = dataMethod.Parameters[3].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual("context", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[3].value");
            Assert.AreEqual(DataType.StringArray, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[3].value");

            //condition.dataleft.data.method.parameters[3].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[3].value.data");
            Assert.AreEqual(1, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[3].value.data");

            //condition.dataleft.data.method.parameters[3].value.data[0]
            dataItem = collection[0] as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[3].value.data[0]");
            Assert.AreEqual("Paragraph", dataItem.Value, "unexpected value in condition.dataleft.data.method.parameters[3].value.data[0]");

            //condition.dataleft.data.method.parameters[4].value
            dataElement = dataMethod.Parameters[4].Value as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual("matchWholeWords", dataElement.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(Guid.Empty, dataElement.DisplayName.Identifier, "unexpected displayname identifier in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected displayname in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[4].value");
            Assert.AreEqual(DataType.BooleanArray, dataElement.Type, "unexpected datatype in condition.dataleft.data.method.parameters[4].value");

            //condition.dataleft.data.method.parameters[4].value.data
            collection = dataElement.Data as IPolicyObjectCollection<IDataItem>;
            Assert.IsNotNull(collection, "unexpected object type in condition.dataleft.data.method.parameters[4].value.data");
            Assert.AreEqual(1, collection.Count, "unexpected number of items in condition.dataleft.data.method.parameters[4].value.data");

            //condition.dataleft.data.method.parameters[4].value.data[0]
            dataItem = collection[0] as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected name identifier in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataleft.data.method.parameters[4].value.data[0]");
            Assert.AreEqual(true, dataItem.Value, "unexpected value in condition.dataleft.data.method.parameters[4].value.data[0]");

            //condition.dataright
            dataElement = condition.DataRight as IDataElement;
            Assert.IsNotNull(dataElement, "unexpected object type in condition.dataright");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataright");
            Assert.AreEqual("", dataElement.DisplayName.Value, "unexpected display name in condition.dataright");
            Assert.AreEqual(Guid.Empty, dataElement.Name.Identifier, "unexpected name identifier in condition.dataright");
            Assert.AreEqual("numberOfOccurrences", dataElement.Name.Value, "unexpected name in condition.dataright");
            Assert.AreEqual(false, dataElement.ReadOnly, "unexpected readonly in condition.dataright");
            Assert.AreEqual(DataType.Long, dataElement.Type, "unexpected type in condition.dataright");

            //condition.dataright.data
            dataItem = dataElement.Data as IDataItem;
            Assert.IsNotNull(dataItem, "unexpected object type in condition.dataright.data");
            Assert.AreEqual(Guid.Empty, dataItem.Name.Identifier, "unexpected name identifier in condition.dataright.data");
            Assert.AreEqual("", dataItem.Name.Value, "unexpected name in condition.dataright.data");
            Assert.AreEqual(false, dataItem.ReadOnly, "unexpected readonly in condition.dataright.data");
            Assert.AreEqual(0, dataItem.Value, "unexpected value in condition.dataright");

            //test state machine state
            m_stateMachine.Verify();
            conditionsResourceSelectForm.Verify();

            //set up another test object
            AddConditionState state2 = new AddConditionStateTester();
            state2.Policy = policy;
            state2.StateMachine = (IStateMachine)m_stateMachine.MockInstance;
            state2.ConditionGroup = rootConditionGroup;
            //state2.ConditionMethodDisplay = new ConditionDisplayFileSize();
            state2.SelectionUI = conditionsResourceSelectForm.MockInstance;
            state2.Source = AddConditionState.ConditionSource.New;

            condition1 = ConditionUnitFactory.CreateCondition(ConditionUnitFactory.PreDefinedConditionType.FileSize);
            selectedConditions.Add(condition1);
            conditionsResourceSelectForm.ExpectAndReturn("get_SelectedConditions", selectedConditions, new object[0]);

            //add another new condition
            m_stateMachine.ExpectAndReturn("GetState", showConditionsState, StateTypeEnum.ShowConditions);
            m_stateMachine.Expect("SetState", showConditionsState);
            state2.Enter();

            //test condition group
            Assert.AreEqual(2, rootConditionGroup.Conditions.Count, "Unexpected number of conditions in conditionGroup.Conditions");

            //test condition
            ICondition condition2 = rootConditionGroup.Conditions[1] as ICondition;
            Assert.IsNotNull(condition2, "Unexpected object type in condition");
            Assert.AreSame(rootConditionGroup, condition2.Parent, "Unexpected object in condition.Parent");

            //test state machine state
            m_stateMachine.Verify();
            conditionsResourceSelectForm.Verify();
        }
Ejemplo n.º 27
0
        public void TestWriteHttpOfflineNoActions()
        {
            string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);

            // Build the offline cell for the action matrix.
            IActionMatrix actions = new ObjectModel.ActionMatrix();

            OfflineActionMatrixCell offlineCell = actions.Offline as OfflineActionMatrixCell;
            Assert.IsNotNull(offlineCell);

            ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new NonTranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false);
            policy.Conditions.Add(conditionGroup);
            offlineCell.AddActionCondition(conditionGroup, BuildActionGroupNoActions(), false);

            channel.Actions = actions;
            channels.Add(channel);
            policy.Channels = channels;

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");
            writer.WritePolicySet(policySet);
            writer.WritePolicy(policySet, policy);
            writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels));
            writer.Close();

            string expectedPolicySetFile = m_testPath + "TestHttpOfflineNoActions.PolicySet.xml";
            TestHelpers.CompareXml(expectedPolicySetFile, store.StoreXML);

            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteCatalogue(policySet.MasterCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestHttpOfflineNoActions.Catalogue.xml";
            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
        public void TestConditionGroupCopyConstructors()
        {
            IConditionGroup conditionGroup = ReadConditionGroupAttributesHelper();
            Assert.AreEqual("This is my first custom property", conditionGroup["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroup["custom2"].Value);

            ConditionGroup conditionGroupCopy = new ConditionGroup(conditionGroup as ConditionGroup);
            Assert.AreEqual("This is my first custom property", conditionGroupCopy["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroupCopy["custom2"].Value);

            ConditionGroup conditionGroupCopy2 = new ConditionGroup(conditionGroup as ConditionGroup, false, false);
            Assert.AreEqual("This is my first custom property", conditionGroupCopy2["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroupCopy2["custom2"].Value);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            conditions.Add(new Condition(Guid.Empty, "Test condition", OperatorType.GreaterThan));
            ConditionGroup conditionGroupCopy3 = new ConditionGroup(conditionGroup as ConditionGroup, conditions);
            Assert.AreEqual("This is my first custom property", conditionGroupCopy3["custom1"].Value);
            Assert.AreEqual("This is my second custom property", conditionGroupCopy3["custom2"].Value);

            ConditionGroup conditionGroupCopy4 = new ConditionGroup(conditionGroup.Identifier, conditionGroup.Name, conditionGroup.Logic, conditionGroup.ExitOnFirstPass);
            Assert.AreEqual("", conditionGroupCopy4["custom1"].Value);
            Assert.AreEqual("", conditionGroupCopy4["custom2"].Value);
        }
        public void TestGetDisplayNameFromDataItems()
        {
            //nominal case
            IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "the race is on"));
            dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "we've got the fire! grrr!"));
            IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
            ConditionDisplayParameterContent contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual("the race is on, we've got the fire! grrr!", contentParam.GetDisplayNameFromDataItems(), "unexpected displayname");
            Assert.AreEqual("the race is on, we've got the fire! grrr!", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //no data items in collection
            dataItems = new PolicyObjectCollection<IDataItem>();
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
            Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
            contentParam = new ConditionDisplayParameterContent(dataElement, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT, contentParam.GetDisplayNameFromDataItems(), "unexpected displayname");
            Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_CONTENTPARAM_DEFAULT, dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

            //invalid format for data
            dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, "hello"));
            contentParam = new ConditionDisplayParameterContent(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            contentParam.Object = dataElement;
            try
            {
                string displayName = contentParam.GetDisplayNameFromDataItems();
                Assert.IsTrue(false, "didn't throw on invalid data format");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }

            //no data
            contentParam = new ConditionDisplayParameterContent(null, this.Callback, Workshare.Policy.PolicyType.ClientEmail);
            try
            {
                string displayName = contentParam.GetDisplayNameFromDataItems();
                Assert.IsTrue(false, "didn't throw on empty data");
            }
            catch (PolicyDesignerException)
            {
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false, "Unexpected exception");
            }
        }
		public void TestGetDisplayNameFromDataItems()
		{
			//nominal case
			IPolicyObjectCollection<IDataItem> dataItems = new PolicyObjectCollection<IDataItem>();
			dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Properties)));
			dataItems.Add(DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Attachments)));
			IDataElement dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
			Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected dataelement.displayname.value");
			ConditionDisplayParameterHiddenDataInPDF hiddenDataParam = new ConditionDisplayParameterHiddenDataInPDF(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
			Assert.AreEqual("Properties, Attachments", hiddenDataParam.GetDisplayNameFromDataItems(), "unexpected displayname");
			Assert.AreEqual("Properties, Attachments", dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

			//no data items in collection
			dataItems = new PolicyObjectCollection<IDataItem>();
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.StringArray, dataItems);
			Assert.AreEqual(0, dataElement.DisplayName.Value.Length, "unexpected length on dataelement.displayname.value");
			hiddenDataParam = new ConditionDisplayParameterHiddenDataInPDF(dataElement, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
			Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_DEFAULT, hiddenDataParam.GetDisplayNameFromDataItems(), "unexpected displayname");
			Assert.AreEqual(Properties.Resources.IDS_EXPRESSION_PARAM_HIDDENDATA_DEFAULT, dataElement.DisplayName.Value, "unexpected dataelement.displayname.value");

			//invalid format for data
			dataElement = new DataElement(Guid.NewGuid(), new NonTranslateableLanguageItem("name"), new NonTranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new NonTranslateableLanguageItem(""), DataType.String, Enum.GetName(typeof(ConditionUnitFactory.FileHiddenDataType), ConditionUnitFactory.FileHiddenDataType.Field)));
			hiddenDataParam = new ConditionDisplayParameterHiddenDataInPDF(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
			hiddenDataParam.Object = dataElement;
			try
			{
				string displayName = hiddenDataParam.GetDisplayNameFromDataItems();
				Assert.IsTrue(false, "didn't throw on invalid data format");
			}
			catch (PolicyDesignerException)
			{
				Assert.IsTrue(true);
			}
			catch
			{
				Assert.IsTrue(false, "Unexpected exception");
			}

			//no data
			hiddenDataParam = new ConditionDisplayParameterHiddenDataInPDF(null, this.Callback, null, Workshare.Policy.PolicyType.ClientEmail);
			try
			{
				string displayName = hiddenDataParam.GetDisplayNameFromDataItems();
				Assert.IsTrue(false, "didn't throw on empty data");
			}
			catch (PolicyDesignerException)
			{
				Assert.IsTrue(true);
			}
			catch
			{
				Assert.IsTrue(false, "Unexpected exception");
			}
		}