public void WhenPackageUsageIsRegistered_ThenALockExists()
        {
            var thePackage    = CreatePackageIdentity("Package", "1.0");
            var theDeployment = new ServerTaskId("Deployment-1");

            packageJournal.RegisterPackageUse(thePackage, theDeployment, 1);

            Assert.IsTrue(journalRepository.HasLock(thePackage));
        }
        public void OnlyStaleLocksAreExpired()
        {
            var packageOne = CreatePackageIdentity("PackageOne", "1.0");
            var packageTwo = CreatePackageIdentity("PackageTwo", "1.0");

            var packageOneLocks = new PackageLocks
            {
                new UsageDetails(new ServerTaskId("Deployment-1"), new CacheAge(1), new DateTime(2021, 1, 1)),
            };

            var packageTwoLocks = new PackageLocks
            {
                new UsageDetails(new ServerTaskId("Deployment-2"), new CacheAge(1), DateTime.Now),
            };

            var packageOneJournalEntry = new JournalEntry(packageOne, 1, packageOneLocks);
            var packageTwoJournalEntry = new JournalEntry(packageTwo, 1, packageTwoLocks);

            var journalEntries = new Dictionary <PackageIdentity, JournalEntry>()
            {
                { packageOne, packageOneJournalEntry },
                { packageTwo, packageTwoJournalEntry }
            };

            var testJournalRepository = new InMemoryJournalRepository(journalEntries);
            var testJournal           = new PackageJournal(testJournalRepository,
                                                           Substitute.For <ILog>(),
                                                           Substitute.For <ICalamariFileSystem>(),
                                                           Substitute.For <IRetentionAlgorithm>(),
                                                           Substitute.For <ISemaphoreFactory>());

            testJournal.ExpireStaleLocks(TimeSpan.FromDays(14));

            Assert.IsFalse(testJournalRepository.HasLock(packageOne));
            Assert.IsTrue(testJournalRepository.HasLock(packageTwo));
        }