Example #1
0
        public void UpdateFromExistingUpdatesExistingStatus(PackageState previousState, AccessCondition accessCondition, PackageState newState)
        {
            // Arrange
            var feedPackageIdentity = new FeedPackageIdentity("howdy", "3.4.6");

            var existingStatus = PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                feedPackageIdentity.Id,
                feedPackageIdentity.Version,
                PackageMonitoringStatusTestUtility.GetTestResultFromPackageState(previousState));

            existingStatus.AccessCondition = accessCondition;

            var newStatus = PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                feedPackageIdentity.Id,
                feedPackageIdentity.Version,
                PackageMonitoringStatusTestUtility.GetTestResultFromPackageState(newState));

            // Act
            PackageMonitoringStatusAccessConditionHelper.UpdateFromExisting(newStatus, existingStatus);

            // Assert
            foreach (var state in Enum.GetValues(typeof(PackageState)).Cast <PackageState>())
            {
                PackageMonitoringStatusTestUtility.AssertAccessCondition(
                    state == previousState ? accessCondition : AccessCondition.GenerateIfNotExistsCondition(),
                    newStatus.ExistingState[state]);
            }
        }
        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));
        }