Esempio n. 1
0
        public void ShouldNotDeleteDirectoryWhereRetainedDeployedToSame()
        {
            var journalEntries = new List <JournalEntry>
            {
                fourDayOldDeployment,
                fourDayOldSameLocationDeployment,
                twoDayOldDeployment,
            };

            deploymentJournal.GetAllJournalEntries().Returns(journalEntries);
            fileSystem.FileExists(fourDayOldSameLocationDeployment.Package.DeployedFrom).Returns(true);
            fileSystem.DirectoryExists(fourDayOldSameLocationDeployment.ExtractedTo).Returns(true);

            const int days = 3;

            retentionPolicy.ApplyRetentionPolicy(policySet1, days, null);

            // Ensure the directories are the same
            Assert.AreEqual(twoDayOldDeployment.ExtractedTo, fourDayOldSameLocationDeployment.ExtractedTo);

            // The old directory was not removed...
            fileSystem.DidNotReceive().DeleteDirectory(Arg.Is <string>(s => s.Equals(fourDayOldSameLocationDeployment.ExtractedTo)));

            // ...despite being removed from the journal
            deploymentJournal.Received().RemoveJournalEntries(Arg.Is <IEnumerable <string> >(ids => ids.Contains(fourDayOldSameLocationDeployment.Id)));

            // and unique directory still removed
            fileSystem.Received().DeleteDirectory(Arg.Is <string>(s => s.Equals(fourDayOldDeployment.ExtractedTo)));
        }
Esempio n. 2
0
        public void ShouldKeepDeploymentsForSpecifiedDays()
        {
            const int days = 3;

            retentionPolicy.ApplyRetentionPolicy(policySet1, days, null);

            // The older artifacts should have been removed
            fileSystem.Received().DeleteDirectory(fourDayOldDeployment.ExtractedTo);
            fileSystem.Received().DeleteFile(fourDayOldDeployment.ExtractedFrom, Arg.Any <DeletionOptions>());

            // The newer artifacts, and those from the non-matching policy-set, should have been kept
            // In other words, nothing but the matching deployment should have been removed
            fileSystem.DidNotReceive().DeleteDirectory(Arg.Is <string>(s => !s.Equals(fourDayOldDeployment.ExtractedTo)));
            fileSystem.DidNotReceive().DeleteFile(Arg.Is <string>(s => !s.Equals(fourDayOldDeployment.ExtractedFrom)), Arg.Any <DeletionOptions>());

            // The older entry should have been removed from the journal
            deploymentJournal.Received().RemoveJournalEntries(Arg.Is <IEnumerable <string> >(ids => ids.Count() == 1 && ids.Contains(fourDayOldDeployment.Id)));
        }