public void TestGetPolicySetVersionNullPolicySet()
		{
			LocalPolicyCache localPolicyCache = new LocalPolicyCache(m_testPath, false);
			IPolicySetCache policySetCache = localPolicyCache.NewPolicySet("Test policy set");
			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);
			policySetConverter.GetPolicySetVersion();
		}
		public void TestGetPolicySetVersionWithVersion()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test policy with versioning.policy");

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual("1.0", policySetConverter.GetPolicySetVersion());
		}
		public void TestUpgradeLDAPVersion_1_1_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set based on version 1.1 format for LDAP.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			System.Xml.XmlDocument originalCatalogue = new System.Xml.XmlDocument();
			originalCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			string[] searchTokens = new string[] { "Addresses", "Address", "AddressGroup", "AddressCollection", "SenderAddressCollectionId", "RecipientAddressCollectionId" };
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			PolicyConverterBase converter = new PolicySetVersionConverter_2_1(policySetCache, AddConversionMessage);
			converter.Convert();
			converter.ConvertCompiledPolicySets();

			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");

			XmlDocument convertedCatalogue = new XmlDocument();
			convertedCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);


			Dictionary<string, int> expectedRoutingTableAttributes = new Dictionary<string, int>();
			expectedRoutingTableAttributes["{40AD6174-72D2-4C97-8CF6-FC67FE786302}"] = 3;
			expectedRoutingTableAttributes["{BC39CB1E-D597-4675-BE38-27752FD42A99}"] = 3;
			expectedRoutingTableAttributes["{A4CFB401-4F07-4D87-96AB-D557ED8A26CB}"] = 3;
			expectedRoutingTableAttributes["{9D86AC33-1754-4EB4-B6E0-3C283B52B414}"] = 3;
			CheckConvertedRoutingTableData(originalCatalogue, convertedCatalogue, expectedRoutingTableAttributes);
			CheckRoutingItemCollections(convertedCatalogue, "Workshare.DirectorySearcher.dll", "Workshare.Policy.Routing.LDAPRouter");

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("SenderAddressCollectionId"));
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("RecipientAddressCollectionId"));
			Assert.AreEqual(2, policySetCache.LatestVersion.CompiledPolicySets.Count, "Expected the same amount of compiled policy sets after a conversion");

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual("2.1", policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestUpgradeBinaryCleanUserAction_1_4_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set Containing BinaryCleanUserAction assembly.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			string[] searchTokens = new string[] { "Workshare.Policy.Actions.BinaryCleanUserAction.dll", "Workshare.Policy.Actions.BinaryCleanUserAction"};
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			PolicyConverterBase converter = new PolicySetVersionConverter_2_1(policySetCache, AddConversionMessage);
			converter.Convert();
			converter.ConvertCompiledPolicySets();

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
			Assert.IsTrue(policySetCache.LatestVersion.MasterCatalogue.Content.Contains("Workshare.Policy.Actions.LightSpeedCleanUserAction.dll"));
			Assert.IsTrue(policySetCache.LatestVersion.MasterCatalogue.Content.Contains("Workshare.Policy.Actions.LightSpeedCleanUserAction"));
			Assert.IsTrue(policySetCache.LatestVersion.MasterCatalogue.Content.Contains("LightSpeed Clean Action"));

			//Check nothing else broken \ changed in this upgrade
			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");
			Assert.AreEqual(2, policySetCache.LatestVersion.CompiledPolicySets.Count, "Expected the same amount of compiled policy sets after a conversion");

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestUpgradeInternalExternalVersion_1_1_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set based on version 1.1 format for internal external.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			System.Xml.XmlDocument originalCatalogue = new System.Xml.XmlDocument();
			originalCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			string[] searchTokens = new string[] { "Addresses", "Address", "AddressGroup", "AddressCollection", "SenderAddressCollectionId", "RecipientAddressCollectionId" };
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			m_conversionMessages.Clear();
			PolicyConverterBase converter = new PolicySetVersionConverter_2_1(policySetCache, AddConversionMessage);
			converter.Convert();
			converter.ConvertCompiledPolicySets();

			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");
			Assert.AreEqual(1, m_conversionMessages.Count, "Incorrect number of conversion messages for conversion to 2.0");

			XmlDocument convertedCatalogue = new XmlDocument();
			convertedCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			Dictionary<string, int> expectedRoutingTableAttributes = new Dictionary<string, int>();
			expectedRoutingTableAttributes["{76F28B5E-E458-45C4-BF68-42B075EE83C5}"] = 4;
			expectedRoutingTableAttributes["{79171CB4-014C-46EE-9CCA-B7D9418E6529}"] = 3;
			expectedRoutingTableAttributes["{C4E8D1C2-1E49-4BFD-8D8E-378A0C1D305E}"] = 3;
			expectedRoutingTableAttributes["{405E9F94-F72D-4AEE-9C0C-7BB3A4C090D9}"] = 3;
			CheckConvertedRoutingTableData(originalCatalogue, convertedCatalogue, expectedRoutingTableAttributes);
			CheckRoutingItemCollections(convertedCatalogue, "Workshare.InternalExternalResolver.dll", "Workshare.Policy.Routing.InternalExternalRouter");

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("SenderAddressCollectionId"));
			Assert.IsFalse(policySetCache.LatestVersion.Content.Contains("RecipientAddressCollectionId"));
			Assert.AreEqual(2, policySetCache.LatestVersion.CompiledPolicySets.Count, "Expected the same amount of compiled policy sets after a conversion");

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual("2.1", policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestUpgradeVersion_1_0_ToLatest()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test Policy Set based on version 1.0 format.policy");

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			int compiledPolicySetsCount = policySetCache.LatestVersion.CompiledPolicySets.Count;
			PolicySetVersionStatus policySetVersionStatus = policySetCache.LatestVersion.Status;

			System.Xml.XmlDocument originalCatalogue = new System.Xml.XmlDocument();
			originalCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			string[] searchTokens = new string[] { "SmtpRoutingTable", "HttpRoutingTable", "ActiveContentRoutingTable" };
			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, true, searchTokens);

			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);
			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(policySetVersionStatus, policySetCache.LatestVersion.Status, "Expected the status to be unchanged");

			XmlDocument convertedCatalogue = new XmlDocument();
			convertedCatalogue.LoadXml(policySetCache.LatestVersion.MasterCatalogue.Content);

			Dictionary<string, int> expectedRoutingTableAttributes = new Dictionary<string, int>();
			expectedRoutingTableAttributes["{76ABAAA1-08F9-4157-9B72-101F50954086}"] = 4;
			expectedRoutingTableAttributes["{32035E05-814B-4834-A7AF-36264E01B36F}"] = 3;
			expectedRoutingTableAttributes["{F5F9F02D-456B-4877-B4D4-C8B8E9026D75}"] = 3;
			CheckConvertedRoutingTableData(originalCatalogue, convertedCatalogue, expectedRoutingTableAttributes);
			CheckRoutingItemCollections(convertedCatalogue, "Workshare.InternalExternalResolver.dll", "Workshare.Policy.Routing.InternalExternalRouter");

			CheckCatalogueTokens(policySetCache.LatestVersion.MasterCatalogue, false, searchTokens);
					   
			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}
		public void TestConvertPolicySetWithVersion()
		{
			IPolicySetCache policySetCache = ReadPolicySetCache(m_testPath + "Test policy with versioning.policy");
			PolicyConverterFactory policySetConverter = new PolicyConverterFactory(policySetCache);

			Assert.AreEqual(1, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual("1.0", policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());

			policySetConverter.ConvertPolicySet(AddConversionMessage);

			Assert.AreEqual(2, policySetCache.PolicySetVersions.Count);
			Assert.AreEqual(m_latestVersion, policySetConverter.GetPolicySetVersion());
		}