示例#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));
        }
        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);
        }
        public async Task GetByState()
        {
            // Arrange
            var statusService = new PackageMonitoringStatusService(
                new MemoryStorageFactory(),
                new Mock <ILogger <PackageMonitoringStatusService> >().Object);

            var expectedValidStatuses = new PackageMonitoringStatus[]
            {
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "newtonsoft.json", "9.0.2", TestResult.Pass),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "a.b", "1.2.3", TestResult.Pass),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "newtonsoft.json", "6.0.8", TestResult.Skip),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "a.b", "0.8.9", TestResult.Skip)
            };

            var expectedInvalidStatuses = new PackageMonitoringStatus[]
            {
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "jQuery",
                    "3.1.2",
                    new ValidationResult[]
                {
                    PackageMonitoringStatusTestUtility.CreateValidationResult(
                        TestResult.Fail,
                        new ValidationException("malarky!"))
                }),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "EntityFramework",
                    "6.1.2",
                    new ValidationResult[]
                {
                    PackageMonitoringStatusTestUtility.CreateValidationResult(
                        TestResult.Fail,
                        new ValidationException("absurd!"))
                }),
                PackageMonitoringStatusTestUtility.CreateStatusWithException(
                    "NUnit",
                    "3.6.1")
            };

            var expectedUnknownStatuses = new PackageMonitoringStatus[]
            {
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "xunit", "2.4.1", TestResult.Pending),
                PackageMonitoringStatusTestUtility.CreateStatusWithPackageValidationResult(
                    "a.b", "99.9.99", TestResult.Pending)
            };

            foreach (var expectedValidStatus in expectedValidStatuses)
            {
                await statusService.UpdateAsync(expectedValidStatus, CancellationToken.None);
            }

            foreach (var expectedInvalidStatus in expectedInvalidStatuses)
            {
                await statusService.UpdateAsync(expectedInvalidStatus, CancellationToken.None);
            }

            foreach (var expectedSkippedStatus in expectedUnknownStatuses)
            {
                await statusService.UpdateAsync(expectedSkippedStatus, CancellationToken.None);
            }

            // Act
            var validStatuses = await statusService.GetAsync(PackageState.Valid, CancellationToken.None);

            var invalidStatuses = await statusService.GetAsync(PackageState.Invalid, CancellationToken.None);

            var unknownStatuses = await statusService.GetAsync(PackageState.Unknown, CancellationToken.None);

            // Assert
            PackageMonitoringStatusTestUtility.AssertAll(
                expectedValidStatuses.OrderBy(s => s.Package.Id).ThenBy(s => s.Package.Version),
                validStatuses.OrderBy(s => s.Package.Id).ThenBy(s => s.Package.Version),
                PackageMonitoringStatusTestUtility.AssertStatus);

            PackageMonitoringStatusTestUtility.AssertAll(
                expectedInvalidStatuses.OrderBy(s => s.Package.Id).ThenBy(s => s.Package.Version),
                invalidStatuses.OrderBy(s => s.Package.Id).ThenBy(s => s.Package.Version),
                PackageMonitoringStatusTestUtility.AssertStatus);

            PackageMonitoringStatusTestUtility.AssertAll(
                expectedUnknownStatuses.OrderBy(s => s.Package.Id).ThenBy(s => s.Package.Version),
                unknownStatuses.OrderBy(s => s.Package.Id).ThenBy(s => s.Package.Version),
                PackageMonitoringStatusTestUtility.AssertStatus);
        }