Ejemplo n.º 1
0
		public void Test_IsValid_OnDelete()
		{
            PollingInterval.Interval = new TimeSpan(0, 0, 0);
			using (TempPolicyFolder folder = new TempPolicyFolder(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\Policies\p5default.runtimepolicy")))
			{
				LocalPolicySetCache cache = new LocalPolicySetCache(folder.Files[0]);
				Assert.AreEqual(CacheValidState.Current, cache.ValidState, "We haven't done anything to the file yet so it should be up to date.");
				File.Delete(folder.Files[0]);
				Assert.AreEqual(CacheValidState.FileNotFound, cache.ValidState, "We deleted the policy file so it should no longer exist on disk.");
			}
            PollingInterval.Interval = new TimeSpan(0, 0, 10);
        }
Ejemplo n.º 2
0
		public void Test_IsValid_OnChange()
		{
            PollingInterval.Interval = new TimeSpan(0, 0, 0);
            using (TempPolicyFolder folder = new TempPolicyFolder(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\Policies\p5default.runtimepolicy")))
			{
				string filename = folder.Files[0];
				LocalPolicySetCache cache = new LocalPolicySetCache(filename);
				Assert.AreEqual(CacheValidState.Current, cache.ValidState, "We haven't done anything to the file yet so it should be up to date.");
				System.Threading.Thread.Sleep(100);
				File.SetLastWriteTimeUtc(filename, DateTime.Now.ToUniversalTime());
				Assert.AreEqual(CacheValidState.OutOfDate, cache.ValidState, "We deleted the policy file so it should no longer exist on disk.");
			}
            PollingInterval.Interval = new TimeSpan(0, 0, 10);
        }
Ejemplo n.º 3
0
		public void Test_Refresh()
		{
            PollingInterval.Interval = new TimeSpan(0, 0, 0);
            using (TempPolicyFolder folder = new TempPolicyFolder(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\Policies\p5default.runtimepolicy")))
			{
				string filename = folder.Files[0];
				LocalPolicySetCache cache = new LocalPolicySetCache(filename);
				Assert.AreEqual(1, cache.PolicySetVersions.Count, "The policy set only has one version in it (or did at the time of writing this test)");
				Assert.AreEqual(CacheValidState.Current, cache.ValidState, "We haven't done anything to the file yet so it should be up to date.");
				System.Threading.Thread.Sleep(100);
				DateTime newTime = DateTime.Now.ToUniversalTime();
				File.SetLastWriteTimeUtc(filename, newTime);
				Assert.AreEqual(CacheValidState.OutOfDate, cache.ValidState, "We deleted the policy file so it should no longer exist on disk.");
				cache.Refresh();
				Assert.AreEqual(CacheValidState.Current, cache.ValidState, "The policy should now be reloaded.");
				Assert.AreEqual(1, cache.PolicySetVersions.Count, "The policy set failed to reload on the refresh!");
				Assert.AreEqual(newTime, cache.TimeStamp, "Check no blatant cheating is going on behind the scenes");
			}
            PollingInterval.Interval = new TimeSpan(0, 0, 10);
        }
Ejemplo n.º 4
0
		public void TestExportPolicySetToFile()
		{
			string originalsetname = Guid.NewGuid().ToString();
			string originalsetfilename = originalsetname + Definitions.PolicyFileExtension;
			System.IO.File.Copy(m_testFiles.RootPath + "policyset1" + Definitions.PolicyFileExtension, m_testFiles.RootPath + originalsetfilename, true);

			LocalPolicyCache cache = new LocalPolicyCache(m_testFiles.RootPath, false);
			LocalPolicySetCache set = cache.GetPolicySet(originalsetname) as LocalPolicySetCache;

			string tempfile = System.IO.Path.GetTempFileName();
			set.ExportCompiledPolicySet(tempfile);

			Assert.AreEqual(set.LatestVersion.Status, PolicySetVersionStatus.Enabled);

			LocalPolicySetCache exportset = new LocalPolicySetCache(tempfile);
			Assert.IsNotNull(exportset);
            Assert.AreEqual(exportset.LatestVersion.Status, PolicySetVersionStatus.Enabled);

            System.IO.File.Delete(cache.LocalBasePath + originalsetfilename);
			System.IO.File.Delete(tempfile);
		}
Ejemplo n.º 5
0
		public void TestCreateNewCompiledPolicySetLanguages()
		{
			LocalPolicyCache lpc = new LocalPolicyCache(m_testFiles.RootPath, false);
			Assert.IsNotNull(lpc);

			IPolicySetCache lps = lpc.NewPolicySet("policyset4");
			Assert.IsNotNull(lps);

			IPolicySetVersionCache lpsv = lps.NewVersion("<policysetxml>this is the content of the policy set for v1.0</policysetxml>");
			Assert.IsNotNull(lpsv);

			ICompiledPolicySetCache cpsc = lpsv.NewCompiledPolicySet("SMTP", "Client", "<Policy>this is the compiled policy</Policy>", "<Objects>the is the compiled policy objects</Objects>");
			Assert.IsNotNull(cpsc);

			IPolicyLanguageTableCache cpsc_eng = cpsc.NewLanguage("en", "<language>this is the language content for english for compiled policy set</language>", true);
			Assert.IsNotNull(cpsc_eng);

			IPolicyLanguageTableCache cpsc_jp = cpsc.NewLanguage("jp", "<language>this is the language content for japanese for compiled policy set</language>", false);
			Assert.IsNotNull(cpsc_jp);

            lps.Save(SaveOption.SaveOnly);


			IPolicySetCache lps2 = new LocalPolicySetCache(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
			Assert.IsNotNull(lps2);
			Assert.AreEqual(1, lps2.PolicySetVersions.Count);

			IPolicySetVersionCache lpsv2 = lps2.PolicySetVersions[0];
			Assert.IsNotNull(lpsv2);

			ICompiledPolicySetCache cps = lpsv2.GetCompiledPolicySet("SMTP", "Client");
			Assert.IsNotNull(cps);

			IPolicyLanguageTableCache pl_eng = cps.Languages[0];
			Assert.IsNotNull(pl_eng);
			Assert.AreEqual(pl_eng.Content, "<language>this is the language content for english for compiled policy set</language>");
			Assert.AreEqual(pl_eng.Language.Code, "en");

			IPolicyLanguageTableCache pl_jp = cps.Languages[1];
			Assert.IsNotNull(pl_jp);
			Assert.AreEqual(pl_jp.Content, "<language>this is the language content for japanese for compiled policy set</language>");
			Assert.AreEqual(pl_jp.Language.Code, "jp");

			System.IO.File.Delete(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
		}
Ejemplo n.º 6
0
		public void TestCreateNewCompiledPolicySets()
		{
			LocalPolicyCache lpc = new LocalPolicyCache(m_testFiles.RootPath, false);
			Assert.IsNotNull(lpc);

			IPolicySetCache lps = lpc.NewPolicySet("policyset4");
			Assert.IsNotNull(lps);

			IPolicySetVersionCache lpsv = lps.NewVersion("<policysetxml>this is the content of the policy set for v1.0</policysetxml>");
			Assert.IsNotNull(lpsv);

			ICompiledPolicySetCache cpsc = lpsv.NewCompiledPolicySet("SMTP", "Client", "<Policy>this is the compiled policy</Policy>", "<Objects>the is the compiled policy objects</Objects>");
			Assert.IsNotNull(cpsc);

            lps.Save(SaveOption.SaveOnly);


			IPolicySetCache lps2 = new LocalPolicySetCache(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
			Assert.IsNotNull(lps2);
			Assert.AreEqual(1, lps2.PolicySetVersions.Count);

			IPolicySetVersionCache lpsv2 = lps2.PolicySetVersions[0];
			Assert.IsNotNull(lpsv2);


			ICompiledPolicySetCache cps = lpsv2.GetCompiledPolicySet("SMTP", "Client");
			Assert.IsNotNull(cps);
			Assert.AreEqual(cps.Channel, "SMTP");
			Assert.AreEqual(cps.Target, "Client");
			Assert.AreEqual(cps.Content, "<Policy>this is the compiled policy</Policy>");
			Assert.AreEqual(cps.ObjectReferences, "<Objects>the is the compiled policy objects</Objects>");


			System.IO.File.Delete(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
		}
Ejemplo n.º 7
0
		public void TestCreateNewCatalogueLanguages()
		{
			LocalPolicyCache lpc = new LocalPolicyCache(m_testFiles.RootPath, false);
			Assert.IsNotNull(lpc);

			IPolicySetCache lps = lpc.NewPolicySet("policyset4");
			Assert.IsNotNull(lps);

			IPolicySetVersionCache lpsv = lps.NewVersion("<policysetxml>this is the content of the policy set for v1.0</policysetxml>");
			Assert.IsNotNull(lpsv);

			IPolicyCatalogueCache mastercat = lpsv.NewMasterCatalogue("<mastercatalogue>this is the conent of the master catalogue</mastercatalogue>");
			Assert.IsNotNull(mastercat);

			IPolicyLanguageTableCache engLang = mastercat.NewLanguage("en", "<language>this is the language content for english for master cat</language>", true);
			Assert.IsNotNull(engLang);

			IPolicyLanguageTableCache jpLang = mastercat.NewLanguage("jp", "<language>this is the language content for japanese for master cat</language>", false);
			Assert.IsNotNull(jpLang);


            lps.Save(SaveOption.SaveOnly);


			IPolicySetCache lps2 = new LocalPolicySetCache(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
			Assert.IsNotNull(lps2);
			Assert.AreEqual(1, lps2.PolicySetVersions.Count);

			IPolicySetVersionCache lpsv2 = lps2.PolicySetVersions[0];
			Assert.IsNotNull(lpsv2);

			IPolicyCatalogueCache pcm = lpsv2.MasterCatalogue;
			Assert.IsNotNull(pcm);

			IPolicyLanguageTableCache pl_eng = pcm.Languages[0];
			Assert.IsNotNull(pl_eng);
			Assert.AreEqual(pl_eng.Content, "<language>this is the language content for english for master cat</language>");
			Assert.AreEqual(pl_eng.Language.Code, "en");

			IPolicyLanguageTableCache pl_jp = pcm.Languages[1];
			Assert.IsNotNull(pl_jp);
			Assert.AreEqual(pl_jp.Content, "<language>this is the language content for japanese for master cat</language>");
			Assert.AreEqual(pl_jp.Language.Code, "jp");

			System.IO.File.Delete(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
		}
Ejemplo n.º 8
0
		public void TestCreateNewCatalogues()
		{
			LocalPolicyCache lpc = new LocalPolicyCache(m_testFiles.RootPath, false);
			Assert.IsNotNull(lpc);

			IPolicySetCache lps = lpc.NewPolicySet("policyset4");
			Assert.IsNotNull(lps);

			IPolicySetVersionCache lpsv = lps.NewVersion("<policysetxml>this is the content of the policy set for v1.0</policysetxml>");
			Assert.IsNotNull(lpsv);

			IPolicyCatalogueCache mastercat = lpsv.NewMasterCatalogue("<mastercatalogue>this is the conent of the master catalogue</mastercatalogue>");
			Assert.IsNotNull(mastercat);

			IPolicyCatalogueCache refcat = lpsv.NewReferenceCatalgue("<refcatalogue>this is the conent of the reference catalogue</refcatalogue>");
			Assert.IsNotNull(refcat);

            lps.Save(SaveOption.SaveOnly);


			IPolicySetCache lps2 = new LocalPolicySetCache(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
			Assert.IsNotNull(lps2);
			Assert.AreEqual(1, lps2.PolicySetVersions.Count);

			IPolicySetVersionCache lpsv2 = lps2.PolicySetVersions[0];
			Assert.IsNotNull(lpsv2);

			IPolicyCatalogueCache pcm = lpsv2.MasterCatalogue;
			Assert.IsNotNull(pcm);
			Assert.AreEqual(pcm.Content, "<mastercatalogue>this is the conent of the master catalogue</mastercatalogue>");

			IPolicyCatalogueCache pcr = lpsv2.ReferenceCatalogues[0];
			Assert.IsNotNull(pcr);
			Assert.AreEqual(pcr.Content, "<refcatalogue>this is the conent of the reference catalogue</refcatalogue>");


			System.IO.File.Delete(m_testFiles.RootPath + "\\policyset4" + Definitions.PolicyFileExtension);
		}
Ejemplo n.º 9
0
		public void TestAddSuperSetAndSave()
		{
			string policySet3 = m_testFiles.RootPath + "policyset3" + Definitions.PolicyFileExtension;
			System.IO.File.Copy(m_testFiles.PolicySet1, policySet3, true);

			LocalPolicyCache cache = new LocalPolicyCache(m_testFiles.RootPath, false);
			LocalPolicySetCache lps = cache.GetPolicySet("policyset3") as LocalPolicySetCache;
			IPolicySetVersionCache lpsv_old = lps.LatestVersion;

			string policyset1_v4 = m_testFiles.GetXmlFromResource(this.GetType(), "Workshare.Policy.ClientCache.Tests.TestFiles.TestPolicySet_1.4.0.version");

			IPolicySetVersionCache lpsv_new = lps.NewSuperSet(policyset1_v4, PolicySetVersionStatus.InProgress);

			Assert.IsFalse(lpsv_old.Latest);
			Assert.IsTrue(lpsv_new.Latest);
			Assert.AreEqual(lpsv_new.Version, "4.0");

            lps.Save(SaveOption.SaveOnly);

            IPolicySetCache lps_new = new LocalPolicySetCache(policySet3);
			IPolicySetVersionCache lpsv_new_new = lps_new.LatestVersion;

			Assert.AreEqual(lpsv_new_new.Version, "4.0");
	
			System.IO.File.Delete(policySet3);
		}
Ejemplo n.º 10
0
		public void TestGetCompiledPolicySet()
		{
            IPolicySetCache lps = new LocalPolicySetCache(m_testFiles.PolicySet1);
			IPolicySetVersionCache lpsv = lps.LatestVersion;


			ICompiledPolicySetCache comp = lpsv.GetCompiledPolicySet("SMTP", "client");
			Assert.IsNotNull(comp);

			ICompiledPolicySetCache comp2 = lpsv.GetCompiledPolicySet("HTTP", "server");
			Assert.IsNull(comp2);
		}
Ejemplo n.º 11
0
		public void TestLocalPolicySetVersionLoading()
		{
            IPolicySetCache lps = new LocalPolicySetCache(m_testFiles.PolicySet1);
			IPolicySetVersionCache lpsv = lps.GetVersion("2.0");

			Assert.AreEqual(lpsv.GetName("en"), "general policy set ver v2");
			Assert.AreEqual(lpsv.Version, "2.0");
			Assert.IsFalse(lpsv.Latest);
		}
Ejemplo n.º 12
0
		public void TestLocalPolicySetLoading()
		{
            IPolicySetCache lps = new LocalPolicySetCache(m_testFiles.PolicySet1);
			IPolicySetVersionCache lpsv = lps.LatestVersion;

			Assert.AreEqual(lpsv.GetName("en"), "general policy set ver v3");

			Assert.AreEqual(lpsv.Content, "this is the content of the policyset xml");
			Assert.AreEqual(lpsv.ReferenceCatalogues.Count, 1);

			IPolicyCatalogueCache masterCat = lpsv.MasterCatalogue;
			Assert.AreEqual(masterCat.Content, "this is the content of the master catalogue of the general policy set");

			IPolicyCatalogueCache refCat = lpsv.ReferenceCatalogues[0];
			Assert.AreEqual(refCat.Content, "this is the content of a reference catalogue of the general policy set");

			Assert.AreEqual(masterCat.Languages.Count, 2);
			Assert.AreEqual(refCat.Languages.Count, 2);

			IPolicyLanguageTableCache masterEng = null;
			IPolicyLanguageTableCache masterJP = null;
			IPolicyLanguageTableCache refEng = null;
			IPolicyLanguageTableCache refJP = null;

			foreach (IPolicyLanguageTableCache lang in masterCat.Languages)
			{
				if (lang.Language.Code == "en")
					masterEng = lang;
				else if (lang.Language.Code == "jp")
					masterJP = lang;
			}

			foreach (IPolicyLanguageTableCache lang in refCat.Languages)
			{
				if (lang.Language.Code == "en")
					refEng = lang;
				else if (lang.Language.Code == "jp")
					refJP = lang;
			}

			Assert.AreEqual(masterEng.Content, "this is the content of the english language for the master cat of the general policy set");
			Assert.AreEqual(masterJP.Content, "this is the content of the japanese language for the master cat of the general policy set");
			Assert.AreEqual(refEng.Content, "this is the content of the english language for the ref cat of the general policy set");
			Assert.AreEqual(refJP.Content, "this is the content of the japanese language for the ref cat of the general policy set");

			Assert.AreEqual(lpsv.CompiledPolicySets.Count, 1);
			ICompiledPolicySetCache compiledSet = lpsv.CompiledPolicySets[0];

			Assert.AreEqual(compiledSet.Content, "This is the content of the compiled policy set for the general policy");
			Assert.AreEqual(compiledSet.ObjectReferences, "This is the content of the objects for the compiled policy set for the general policy");
			Assert.AreEqual(compiledSet.Target, "client");
			Assert.AreEqual(compiledSet.Channel, "SMTP");

			Assert.AreEqual(compiledSet.Languages.Count, 2);

			IPolicyLanguageTableCache compEng = null;
			IPolicyLanguageTableCache compJP = null;

			foreach (IPolicyLanguageTableCache lang in compiledSet.Languages)
			{
				if (lang.Language.Code == "en")
					compEng = lang;
				else if (lang.Language.Code == "jp")
					compJP = lang;
			}

			Assert.AreEqual(compEng.Content, "this is the content of the english language for the compiled policyset");
			Assert.AreEqual(compJP.Content, "this is the content of the japanese language for the compiled policyset");
		}