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 TestDetectDeletedAndOutOfDate_RemoveAndAddFile()
        {
            PollingInterval.Interval = new TimeSpan(0, 0, 0);
            using (TempPolicyFolder folder = new TempPolicyFolder(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\Policies\p5default.runtimepolicy")))
            {
                Assert.AreEqual(1, folder.Files.Length, "We have only put the p5 default policy there.");
                string policyFile = folder.Files[0];
                LocalPolicyCache lpc = new LocalPolicyCache(folder.Path, true);
                Assert.AreEqual(1, lpc.PolicySets.Count, "We have only put the p5 default policy there so the cache should only load one.");
                File.Delete(policyFile);
                Assert.AreEqual(1, lpc.PolicySets.Count, "The update should not happen yet.");
                lpc.AttemptRefresh();
                Assert.AreEqual(0, lpc.PolicySets.Count, "We killed the file, the policy set should not be there anymore.");
                File.Copy(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\Policies\p5default.runtimepolicy"), policyFile);
                lpc.AttemptRefresh();
                Assert.AreEqual(1, lpc.PolicySets.Count, "We replaced the file so this should be good again.");
            }

            PollingInterval.Interval = new TimeSpan(0, 0, 10);
        }