Exemplo n.º 1
0
        public async Task WaitsForPackageAvailabilityInGalleryDBWithCheckValidator()
        {
            var messageData             = PackageValidationMessageData.NewCheckValidator(Guid.NewGuid());
            var validationConfiguration = new ValidationConfiguration();
            var validationSet           = new PackageValidationSet {
                PackageKey = 42, ValidatingType = ValidatingType.Package
            };

            ValidationSetProviderMock
            .Setup(ps => ps.TryGetParentValidationSetAsync(messageData.CheckValidator.ValidationId))
            .ReturnsAsync(validationSet)
            .Verifiable();
            CorePackageServiceMock
            .Setup(ps => ps.FindPackageByKey(validationSet.PackageKey))
            .Returns <SymbolPackage>(null)
            .Verifiable();

            var handler = CreateHandler();

            var result = await handler.HandleAsync(messageData);

            ValidationSetProviderMock.Verify(
                ps => ps.TryGetParentValidationSetAsync(messageData.CheckValidator.ValidationId),
                Times.Once);
            CorePackageServiceMock.Verify(
                ps => ps.FindPackageByKey(validationSet.PackageKey),
                Times.Once);

            Assert.False(result, "The handler should not have succeeded.");
        }
        public async Task DropsMessageOnDuplicateValidationRequest()
        {
            var messageData             = new PackageValidationMessageData("packageId", "1.2.3", Guid.NewGuid());
            var validationConfiguration = new ValidationConfiguration();
            var package = new Package();
            var packageValidatingEntity = new PackageValidatingEntity(package);

            CorePackageServiceMock
            .Setup(ps => ps.FindPackageByIdAndVersionStrict(messageData.PackageId, messageData.PackageVersion))
            .Returns(packageValidatingEntity)
            .Verifiable();

            ValidationSetProviderMock
            .Setup(vsp => vsp.TryGetOrCreateValidationSetAsync(messageData, packageValidatingEntity))
            .ReturnsAsync((PackageValidationSet)null)
            .Verifiable();

            var handler = CreateHandler();

            var result = await handler.HandleAsync(messageData);

            Assert.True(result);
            CorePackageServiceMock
            .Verify(ps => ps.FindPackageByIdAndVersionStrict(messageData.PackageId, messageData.PackageVersion), Times.Once());
            ValidationSetProviderMock
            .Verify(vsp => vsp.TryGetOrCreateValidationSetAsync(messageData, packageValidatingEntity), Times.Once());
        }
Exemplo n.º 3
0
        public async Task DropsMessageIfPackageIsSoftDeletedForCheckValidator()
        {
            var messageData             = PackageValidationMessageData.NewCheckValidator(Guid.NewGuid());
            var validationConfiguration = new ValidationConfiguration();
            var package = new Package {
                Key = 42, PackageStatusKey = PackageStatus.Deleted
            };
            var packageValidatingEntity = new PackageValidatingEntity(package);
            var validationSet           = new PackageValidationSet {
                PackageKey = package.Key, ValidatingType = ValidatingType.Package
            };

            ValidationSetProviderMock
            .Setup(ps => ps.TryGetParentValidationSetAsync(messageData.CheckValidator.ValidationId))
            .ReturnsAsync(validationSet)
            .Verifiable();
            CorePackageServiceMock
            .Setup(ps => ps.FindPackageByKey(package.Key))
            .Returns(packageValidatingEntity);

            var handler = CreateHandler();

            var result = await handler.HandleAsync(messageData);

            Assert.True(result);
            ValidationSetProviderMock.Verify(
                vsp => vsp.TryGetParentValidationSetAsync(messageData.CheckValidator.ValidationId),
                Times.Once);
            CorePackageServiceMock.Verify(
                ps => ps.FindPackageByKey(package.Key),
                Times.Once);
        }
Exemplo n.º 4
0
        public async Task DropsMessageIfPackageIsSoftDeletedForProcessValidationSet()
        {
            var messageData = PackageValidationMessageData.NewProcessValidationSet(
                "packageId",
                "1.2.3",
                Guid.NewGuid(),
                ValidatingType.Package,
                entityKey: null);
            var validationConfiguration = new ValidationConfiguration();
            var package = new Package {
                PackageStatusKey = PackageStatus.Deleted
            };
            var packageValidatingEntity = new PackageValidatingEntity(package);

            CorePackageServiceMock
            .Setup(ps => ps.FindPackageByIdAndVersionStrict(
                       messageData.ProcessValidationSet.PackageId,
                       messageData.ProcessValidationSet.PackageVersion))
            .Returns(packageValidatingEntity);

            var handler = CreateHandler();

            var result = await handler.HandleAsync(messageData);

            Assert.True(result);
            CorePackageServiceMock.Verify(
                ps => ps.FindPackageByIdAndVersionStrict(
                    messageData.ProcessValidationSet.PackageId,
                    messageData.ProcessValidationSet.PackageVersion),
                Times.Once);
        }
Exemplo n.º 5
0
        public async Task DropsMessageAfterMissingPackageRetryCountIsReached()
        {
            var validationTrackingId = Guid.NewGuid();
            var messageData          = PackageValidationMessageData.NewProcessValidationSet(
                "packageId",
                "1.2.3",
                validationTrackingId,
                ValidatingType.Package,
                entityKey: null);

            CorePackageServiceMock
            .Setup(ps => ps.FindPackageByIdAndVersionStrict("packageId", "1.2.3"))
            .Returns <Package>(null)
            .Verifiable();

            TelemetryServiceMock
            .Setup(t => t.TrackMissingPackageForValidationMessage("packageId", "1.2.3", validationTrackingId.ToString()))
            .Verifiable();

            var handler = CreateHandler();

            Assert.False(await handler.HandleAsync(OverrideDeliveryCount(messageData, deliveryCount: 1)));
            Assert.False(await handler.HandleAsync(OverrideDeliveryCount(messageData, deliveryCount: 2)));
            Assert.True(await handler.HandleAsync(OverrideDeliveryCount(messageData, deliveryCount: 3)));

            CorePackageServiceMock.Verify(ps => ps.FindPackageByIdAndVersionStrict("packageId", "1.2.3"), Times.Exactly(3));
            TelemetryServiceMock.Verify(t => t.TrackMissingPackageForValidationMessage("packageId", "1.2.3", validationTrackingId.ToString()), Times.Once);
        }
Exemplo n.º 6
0
        public async Task WaitsForPackageAvailabilityInGalleryDBWithProcessValidationSet()
        {
            var messageData = PackageValidationMessageData.NewProcessValidationSet(
                "packageId",
                "1.2.3",
                Guid.NewGuid(),
                ValidatingType.Package,
                entityKey: null);
            var validationConfiguration = new ValidationConfiguration();

            CorePackageServiceMock
            .Setup(ps => ps.FindPackageByIdAndVersionStrict(
                       messageData.ProcessValidationSet.PackageId,
                       messageData.ProcessValidationSet.PackageVersion))
            .Returns <Package>(null)
            .Verifiable();

            var handler = CreateHandler();

            await handler.HandleAsync(messageData);

            CorePackageServiceMock.Verify(
                ps => ps.FindPackageByIdAndVersionStrict(
                    messageData.ProcessValidationSet.PackageId,
                    messageData.ProcessValidationSet.PackageVersion),
                Times.Once);
        }
Exemplo n.º 7
0
        public async Task AbandonsMessageProcessingIfShutdownIsInProgress()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            ShutdownNotificationTokenProviderMock
            .SetupGet(x => x.Token)
            .Returns(cancellationTokenSource.Token);
            cancellationTokenSource.Cancel();

            var handler = CreateHandler();
            var result  = await handler.HandleAsync(MessageData);

            Assert.False(result);
            CorePackageServiceMock
            .Verify(cps => cps.FindPackageByIdAndVersionStrict(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
            ValidationSetProviderMock
            .Verify(vsp => vsp.GetOrCreateValidationSetAsync(It.IsAny <Guid>(), It.IsAny <Package>()), Times.Never());
            ValidationSetProcessorMock
            .Verify(vsp => vsp.ProcessValidationsAsync(It.IsAny <PackageValidationSet>(), It.IsAny <Package>()), Times.Never());
            ValidationOutcomeProcessorMock
            .Verify(vop => vop.ProcessValidationOutcomeAsync(It.IsAny <PackageValidationSet>(), It.IsAny <Package>()), Times.Never());
        }