public async Task GetByPackageDeletesOutdatedStatuses(PackageState latest, PackageState outdated)
        {
            // Arrange
            var storageFactory = new MemoryStorageFactory();
            var statusService  = new PackageMonitoringStatusService(
                storageFactory,
                new Mock <ILogger <PackageMonitoringStatusService> >().Object);

            var id             = "howdyFriend";
            var version        = "5.5.5";
            var package        = new FeedPackageIdentity(id, version);
            var outdatedStatus = PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                id,
                version,
                PackageMonitoringStatusTestUtility.GetTestResultFromPackageState(latest),
                new DateTime(2019, 6, 10));

            var latestStatus = PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                id,
                version,
                PackageMonitoringStatusTestUtility.GetTestResultFromPackageState(outdated),
                new DateTime(2019, 6, 11));

            await SaveToStorage(storageFactory, outdatedStatus);
            await SaveToStorage(storageFactory, latestStatus);

            // Act
            var status = await statusService.GetAsync(package, CancellationToken.None);

            // Assert
            PackageMonitoringStatusTestUtility.AssertStatus(latestStatus, status);
            Assert.Equal(latest == outdated, DoesPackageExists(storageFactory, outdatedStatus.State, package));
            Assert.True(DoesPackageExists(storageFactory, latestStatus.State, package));
        }
        public async Task UpdateDeletesOldStatuses(PackageState?previousState)
        {
            // Arrange
            var feedPackageIdentity = new FeedPackageIdentity("howdy", "3.4.6");

            var packageValidationResult = new PackageValidationResult(
                new PackageIdentity(feedPackageIdentity.Id, new NuGetVersion(feedPackageIdentity.Version)),
                null,
                null,
                Enumerable.Empty <AggregateValidationResult>());
            var status = new PackageMonitoringStatus(packageValidationResult);

            var storageFactory = new MemoryStorageFactory();

            var statusService = new PackageMonitoringStatusService(
                storageFactory,
                new Mock <ILogger <PackageMonitoringStatusService> >().Object);

            var etag = "theETag";

            foreach (var state in Enum.GetValues(typeof(PackageState)).Cast <PackageState>())
            {
                if (previousState != state)
                {
                    status.ExistingState[state] = AccessCondition.GenerateIfNotExistsCondition();
                    continue;
                }

                var content = new StringStorageContentWithETag("{}", etag);
                await SaveToStorage(storageFactory, state, feedPackageIdentity, content);

                status.ExistingState[state] = AccessCondition.GenerateIfMatchCondition(etag);
            }

            // Act
            await statusService.UpdateAsync(status, CancellationToken.None);

            // Assert
            foreach (var state in Enum.GetValues(typeof(PackageState)).Cast <PackageState>())
            {
                Assert.Equal(
                    state == status.State,
                    DoesPackageExists(storageFactory, state, feedPackageIdentity));
            }

            PackageMonitoringStatusTestUtility.AssertStatus(
                status,
                await statusService.GetAsync(feedPackageIdentity, CancellationToken.None));
        }
        public async Task GetByPackageWithPackageValidationResult()
        {
            // Arrange
            var statusService = new PackageMonitoringStatusService(
                new MemoryStorageFactory(),
                new Mock <ILogger <PackageMonitoringStatusService> >().Object);

            var undesiredStatuses = new PackageMonitoringStatus[]
            {
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "json.newtonsoft",
                    "1.0.9",
                    TestResult.Pass),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "json.newtonsoft.json",
                    "1.0.9.1",
                    TestResult.Fail),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "j.n.j",
                    "1.9.1",
                    TestResult.Skip),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "newtonsoft.json",
                    "9.0.2",
                    TestResult.Pass)
            };

            var desiredPackageId      = "newtonsoft.json";
            var desiredPackageVersion = "9.0.1";
            var desiredStatus         = PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                desiredPackageId,
                desiredPackageVersion,
                TestResult.Pass);

            await statusService.UpdateAsync(desiredStatus, CancellationToken.None);

            await Task.WhenAll(undesiredStatuses.Select(s => statusService.UpdateAsync(s, CancellationToken.None)));

            // Act
            var status = await statusService.GetAsync(new FeedPackageIdentity(desiredPackageId, desiredPackageVersion), CancellationToken.None);

            // Assert
            PackageMonitoringStatusTestUtility.AssertStatus(desiredStatus, status);
        }