public async Task DoesNotSendValidatingTooLongMessageOnRevalidations() { const int postponeMinutes = 1; AddValidation("validation1", ValidationStatus.Incomplete); Configuration.TimeoutValidationSetAfter = TimeSpan.FromDays(1); Configuration.ValidationSetNotificationTimeout = TimeSpan.FromMinutes(20); Configuration.ValidationMessageRecheckPeriod = TimeSpan.FromMinutes(postponeMinutes); ValidationSet.Created = DateTime.UtcNow - TimeSpan.FromMinutes(21); ValidationSet.Updated = DateTime.UtcNow - TimeSpan.FromMinutes(15); ValidationStorageServiceMock .Setup(s => s.UpdateValidationSetAsync(It.IsAny <PackageValidationSet>())) .Callback <PackageValidationSet>(s => s.Updated = DateTime.UtcNow) .Returns(Task.FromResult(0)); ValidationStorageServiceMock .Setup(s => s.GetValidationSetCountAsync(PackageValidatingEntity)) .Returns(Task.FromResult(2)); // Process the outcome once - the "too long to validate" message should NOT be sent. var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); TelemetryServiceMock .Verify(t => t.TrackSentValidationTakingTooLongMessage(Package.PackageRegistration.Id, Package.NormalizedVersion, ValidationSet.ValidationTrackingId), Times.Never); MessageServiceMock .Verify(m => m.SendValidationTakingTooLongMessageAsync(Package), Times.Never); ValidationEnqueuerMock .Verify(ve => ve.StartValidationAsync(It.IsAny <PackageValidationMessageData>(), It.IsAny <DateTimeOffset>()), Times.Once); PackageFileServiceMock .Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny <PackageValidationSet>()), Times.Never); }
public async Task CopiesPackageToPublicStorageAndSendsEmailUponSuccess() { AddValidation("validation1", ValidationStatus.Succeeded); Package.PackageStatusKey = PackageStatus.Validating; var stream = new MemoryStream(); PackageFileServiceMock .Setup(pfs => pfs.DownloadValidationPackageFileAsync(Package)) .ReturnsAsync(stream) .Verifiable(); PackageFileServiceMock .Setup(pfs => pfs.SavePackageFileAsync(Package, stream)) .Returns(Task.FromResult(0)) .Verifiable(); var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, Package); PackageFileServiceMock .Verify(pfs => pfs.DownloadValidationPackageFileAsync(Package), Times.Once()); PackageFileServiceMock .Verify(pfs => pfs.DownloadValidationPackageFileAsync(It.IsAny <Package>()), Times.Once()); PackageFileServiceMock .Verify(pfs => pfs.SavePackageFileAsync(Package, stream), Times.Once()); PackageFileServiceMock .Verify(pfs => pfs.SavePackageFileAsync(It.IsAny <Package>(), It.IsAny <Stream>()), Times.Once()); MessageServiceMock .Verify(ms => ms.SendPackagePublishedMessage(Package), Times.Once()); MessageServiceMock .Verify(ms => ms.SendPackagePublishedMessage(It.IsAny <Package>()), Times.Once()); }
public async Task DoesNotSendSuccessEmailIfPackageIsAlreadyAvailable() { AddValidation("validation1", ValidationStatus.Succeeded); Package.PackageStatusKey = PackageStatus.Available; var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); MessageServiceMock.Verify( x => x.SendPublishedMessageAsync(It.IsAny <Package>()), Times.Never); }
public async Task SendsFailureEmailOnFailedValidation(ValidationIssueCode[] issueCodes) { AddValidation("validation1", ValidationStatus.Failed); ValidationSet.PackageValidations.First().PackageValidationIssues = issueCodes .Select(ic => new PackageValidationIssue { IssueCode = ic }) .ToList(); var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); MessageServiceMock .Verify(ms => ms.SendValidationFailedMessageAsync(Package, ValidationSet), Times.Once()); MessageServiceMock .Verify(ms => ms.SendValidationFailedMessageAsync(It.IsAny <Package>(), It.IsAny <PackageValidationSet>()), Times.Once()); }
public async Task DoesNotTakeDownAvailablePackages() { AddValidation("validation1", ValidationStatus.Failed); Package.PackageStatusKey = PackageStatus.Available; var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); PackageFileServiceMock.Verify( x => x.DeletePackageForValidationSetAsync(ValidationSet), Times.Once); PackageStateProcessorMock.Verify( x => x.SetStatusAsync(It.IsAny <PackageValidatingEntity>(), It.IsAny <PackageValidationSet>(), It.IsAny <PackageStatus>()), Times.Never); MessageServiceMock.Verify( x => x.SendValidationFailedMessageAsync(It.IsAny <Package>(), It.IsAny <PackageValidationSet>()), Times.Never); MessageServiceMock.Verify( x => x.SendPublishedMessageAsync(It.IsAny <Package>()), Times.Never); }
public async Task MakesPackageAvailableAndSendsEmailUponSuccess() { AddValidation("validation1", ValidationStatus.Succeeded); Package.PackageStatusKey = PackageStatus.Validating; var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); PackageStateProcessorMock.Verify( x => x.SetStatusAsync(PackageValidatingEntity, ValidationSet, PackageStatus.Available), Times.Once); PackageFileServiceMock.Verify( x => x.DeletePackageForValidationSetAsync(ValidationSet), Times.Once); MessageServiceMock .Verify(ms => ms.SendPublishedMessageAsync(Package), Times.Once()); MessageServiceMock .Verify(ms => ms.SendPublishedMessageAsync(It.IsAny <Package>()), Times.Once()); }
public async Task SendsTooLongNotificationOnlyWhenItConcernsRequiredValidation( ValidationStatus requiredValidationState, ValidationStatus optionalValidationState, bool requiredValidationSucceeded) { bool expectedNotification = requiredValidationState == ValidationStatus.Incomplete || requiredValidationState == ValidationStatus.NotStarted; AddValidation("requiredValidation", requiredValidationState, ValidationFailureBehavior.MustSucceed); AddValidation("optionalValidaiton", optionalValidationState, ValidationFailureBehavior.AllowedToFail); ProcessorStats.AnyRequiredValidationSucceeded = requiredValidationSucceeded; Configuration.TimeoutValidationSetAfter = TimeSpan.FromDays(1); Configuration.ValidationSetNotificationTimeout = TimeSpan.FromMinutes(20); Configuration.ValidationMessageRecheckPeriod = TimeSpan.FromMinutes(1); ValidationSet.Created = DateTime.UtcNow - Configuration.ValidationSetNotificationTimeout - TimeSpan.FromMinutes(1); ValidationSet.Updated = DateTime.UtcNow - TimeSpan.FromMinutes(15); ValidationStorageServiceMock .Setup(s => s.UpdateValidationSetAsync(It.IsAny <PackageValidationSet>())) .Callback <PackageValidationSet>(s => s.Updated = DateTime.UtcNow) .Returns(Task.CompletedTask); ValidationStorageServiceMock .Setup(s => s.GetValidationSetCountAsync(PackageValidatingEntity)) .Returns(Task.FromResult(1)); var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); if (expectedNotification) { MessageServiceMock .Verify(m => m.SendValidationTakingTooLongMessageAsync(Package), Times.Once()); } else { MessageServiceMock .Verify(m => m.SendValidationTakingTooLongMessageAsync(Package), Times.Never()); } }
public async Task MarksPackageAsFailedAndSendsEmailOnFailedValidation() { AddValidation("validation1", ValidationStatus.Failed); PackageServiceMock .Setup(ps => ps.UpdatePackageStatusAsync(Package, PackageStatus.FailedValidation, true)) .Returns(Task.FromResult(0)) .Verifiable(); var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, Package); PackageServiceMock .Verify(ps => ps.UpdatePackageStatusAsync(Package, PackageStatus.FailedValidation, true), Times.Once()); PackageServiceMock .Verify(ps => ps.UpdatePackageStatusAsync(It.IsAny <Package>(), It.IsAny <PackageStatus>(), It.IsAny <bool>()), Times.Once()); MessageServiceMock .Verify(ms => ms.SendPackageValidationFailedMessage(Package), Times.Once()); MessageServiceMock .Verify(ms => ms.SendPackageValidationFailedMessage(It.IsAny <Package>()), Times.Once()); }