public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); deploymentJournal = Substitute.For<IDeploymentJournal>(); clock = Substitute.For<IClock>(); retentionPolicy = new RetentionPolicy(fileSystem, deploymentJournal, clock); now = new DateTimeOffset(new DateTime(2015, 01, 15), new TimeSpan(0, 0, 0)); clock.GetUtcTime().Returns(now); // Deployed 4 days prior to 'now' fourDayOldDeployment = new JournalEntry("fourDayOld", "blah", "blah", "blah", "blah", policySet1, now.AddDays(-4).LocalDateTime, "C:\\packages\\Acme.1.0.0.nupkg", "C:\\Applications\\Acme.1.0.0", null, true); // Deployed 4 days prior to 'now' but to the same location as the latest successful deployment fourDayOldSameLocationDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", "blah", policySet1, now.AddDays(-4).LocalDateTime, "C:\\packages\\Acme.1.2.0.nupkg", "C:\\Applications\\Acme.1.2.0", null, true); // Deployed 3 days prior to 'now' threeDayOldDeployment = new JournalEntry("threeDayOld", "blah", "blah", "blah", "blah", policySet1, now.AddDays(-3).LocalDateTime, "C:\\packages\\Acme.1.1.0.nupkg", "C:\\Applications\\Acme.1.1.0", null, true); // Deployed 2 days prior to 'now' twoDayOldDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", "blah", policySet1, now.AddDays(-2).LocalDateTime, "C:\\packages\\Acme.1.2.0.nupkg", "C:\\Applications\\Acme.1.2.0", null, true); // Deployed (unsuccessfully) 1 day prior to 'now' oneDayOldUnsuccessfulDeployment = new JournalEntry("oneDayOldUnsuccessful", "blah", "blah", "blah", "blah", policySet1, now.AddDays(-1).LocalDateTime, "C:\\packages\\Acme.1.3.0.nupkg", "C:\\Applications\\Acme.1.3.0", null, false); // Deployed 5 days prior to 'now', but has a different policy-set fiveDayOldNonMatchingDeployment = new JournalEntry("fiveDayOld", "blah", "blah", "blah", "blah", policySet2, now.AddDays(-5).LocalDateTime, "C:\\packages\\Beta.1.0.0.nupkg", "C:\\Applications\\Beta.1.0.0", null, true); var journalEntries = new List<JournalEntry> { fiveDayOldNonMatchingDeployment, fourDayOldDeployment, threeDayOldDeployment, twoDayOldDeployment, oneDayOldUnsuccessfulDeployment }; deploymentJournal.GetAllJournalEntries().Returns(journalEntries); foreach (var journalEntry in journalEntries) { fileSystem.FileExists(journalEntry.ExtractedFrom).Returns(true); fileSystem.DirectoryExists(journalEntry.ExtractedTo).Returns(true); } }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(retentionPolicySet, "No retention-policy-set was specified. Please pass --retentionPolicySet \"Environments-2/projects-161/Step-Package B/machines-65/<default>\""); if (days <=0 && releases <= 0) throw new CommandException("A value must be provided for either --days or --releases"); var variables = new CalamariVariableDictionary(); variables.EnrichWithEnvironmentVariables(); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var deploymentJournal = new DeploymentJournal(fileSystem, new SystemSemaphore(), variables); var clock = new SystemClock(); var retentionPolicy = new RetentionPolicy(fileSystem, deploymentJournal, clock); retentionPolicy.ApplyRetentionPolicy(retentionPolicySet, days, releases); return 0; }