public async Task SendsMessage() { var request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "someversion", "https://example.com/testpackage.nupkg"); await _target.EnqueueScanAsync(request.ValidationId, request.NupkgUrl); Assert.Same(_serializedMessage, _capturedBrokeredMessage); }
public async Task ForwardsCallToValidatorStateService() { var request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "somversion", "https://example.com/package.nupkg"); var status = new ValidatorStatus { State = ValidationStatus.Incomplete, NupkgUrl = null, ValidatorIssues = new List <ValidatorIssue>() }; _validatorStateServiceMock .Setup(vss => vss.GetStatusAsync(request)) .ReturnsAsync(status); var result = await _target.GetResponseAsync(request); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(request), Times.Once); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(It.IsAny <NuGetValidationRequest>()), Times.Once); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(It.IsAny <Guid>()), Times.Never); Assert.Empty(result.Issues); Assert.Equal(status.State, result.Status); Assert.Equal(status.NupkgUrl, result.NupkgUrl); }
public async Task DoesNotSkipCheckWhenPackageFitsCriteria() { var request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "somversion", "https://example.com/package.nupkg"); var status = new ValidatorStatus { State = ValidationStatus.NotStarted, NupkgUrl = null, ValidatorIssues = new List <ValidatorIssue>() }; _criteriaEvaluatorMock .Setup(ce => ce.IsMatch(It.IsAny <ICriteria>(), It.IsAny <SymbolPackage>())) .Returns(false); _validatorStateServiceMock .Setup(vss => vss.GetStatusAsync(request)) .ReturnsAsync(status); var result = await _target.GetResponseAsync(request); Assert.Equal(ValidationStatus.NotStarted, result.Status); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(It.IsAny <NuGetValidationRequest>()), Times.Once); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(It.IsAny <Guid>()), Times.Never); }
public async Task WhenRepositorySigningIsDisabled_SuppressesNupkgUrl() { _config.RepositorySigningEnabled = false; var request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "somversion", "https://example.com/package.nupkg"); var status = new ValidatorStatus { State = ValidationStatus.Incomplete, NupkgUrl = "https://nuget.test/package.nupkg", ValidatorIssues = new List <ValidatorIssue>() }; _validatorStateServiceMock .Setup(vss => vss.GetStatusAsync(request)) .ReturnsAsync(status); var result = await _target.GetResponseAsync(request); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(request), Times.Once); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(It.IsAny <NuGetValidationRequest>()), Times.Once); _validatorStateServiceMock .Verify(vss => vss.GetStatusAsync(It.IsAny <Guid>()), Times.Never); Assert.Empty(result.Issues); Assert.Equal(status.State, result.Status); Assert.Null(result.NupkgUrl); }
public void CreateRequestName() { // Arrange var id = Guid.NewGuid(); var vRequest = new NuGetValidationRequest(id, 10, "pId", "1.1.1", "url"); // Act var requestName = SymbolsValidationEntitiesService.CreateSymbolServerRequestNameFromValidationRequest(vRequest); // Assert Assert.Equal($"{vRequest.PackageKey}_{vRequest.ValidationId}", requestName); }
public void CreateFromValidationRequestValidRequest() { // Arrange var request = new NuGetValidationRequest(Guid.NewGuid(), PackageKey, PackageId, PackageVersion, ""); var requestName = "DummyRequestName"; // Act var result = SymbolsValidationEntitiesService.CreateFromValidationRequest(request, SymbolsPackageIngestRequestStatus.FailedIngestion, requestName); // Assert Assert.Equal(PackageKey, result.SymbolsKey); Assert.Equal(requestName, result.RequestName); Assert.Equal(SymbolsPackageIngestRequestStatus.FailedIngestion, result.RequestStatusKey); }
public TheStartAsyncMethod() { _request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "somversion", "https://example.com/package.nupkg"); _status = new ValidatorStatus { State = ValidationStatus.NotStarted, NupkgUrl = null, ValidatorIssues = new List <ValidatorIssue>() }; _validatorStateServiceMock .Setup(vss => vss.GetStatusAsync(_request)) .ReturnsAsync(_status); _validatorStateServiceMock .Setup(vss => vss.TryAddValidatorStatusAsync(It.IsAny <INuGetValidationRequest>(), It.IsAny <ValidatorStatus>(), It.IsAny <ValidationStatus>())) .ReturnsAsync(_status); }
private async Task <INuGetValidationRequest> CreateNuGetValidationRequest( PackageValidationSet packageValidationSet, PackageValidation packageValidation) { var nupkgUrl = await _packageFileService.GetPackageForValidationSetReadUriAsync( packageValidationSet, DateTimeOffset.UtcNow.Add(_validationConfiguration.TimeoutValidationSetAfter)); var validationRequest = new NuGetValidationRequest( validationId: packageValidation.Key, packageKey: packageValidationSet.PackageKey, packageId: packageValidationSet.PackageId, packageVersion: packageValidationSet.PackageNormalizedVersion, nupkgUrl: nupkgUrl.AbsoluteUri); return(validationRequest); }
public async Task DeletesNothingWhenThereIsNoNupkgUrl() { var request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "somversion", "https://nuget.test/package.nupkg"); var status = new ValidatorStatus { State = ValidationStatus.Incomplete, NupkgUrl = null, ValidatorIssues = new List <ValidatorIssue>() }; _validatorStateServiceMock .Setup(v => v.GetStatusAsync(request)) .ReturnsAsync(status); await _target.CleanUpAsync(request); _validatorStateServiceMock.Verify(x => x.GetStatusAsync(request), Times.Once); _blobProvider.Verify(x => x.GetBlobFromUrl(It.IsAny <string>()), Times.Never); }
public async Task WhenThereIsNupkgUrl_DeletesTheBlobIfRepositorySigningIsEnabled(bool repositorySigningEnabled, bool expectsBlobDeleted) { // Arrange _config.RepositorySigningEnabled = repositorySigningEnabled; var request = new NuGetValidationRequest(Guid.NewGuid(), 42, "somepackage", "somversion", "https://nuget.test/package.nupkg"); var nupkgUrl = "http://example/packages/nuget.versioning.4.6.0.nupkg"; var status = new ValidatorStatus { State = ValidationStatus.Incomplete, NupkgUrl = nupkgUrl, ValidatorIssues = new List <ValidatorIssue>() }; _validatorStateServiceMock .Setup(v => v.GetStatusAsync(request)) .ReturnsAsync(status); var blob = new Mock <ISimpleCloudBlob>(); _blobProvider .Setup(x => x.GetBlobFromUrl(nupkgUrl)) .Returns(blob.Object); // Act await _target.CleanUpAsync(request); // Assert _validatorStateServiceMock.Verify(x => x.GetStatusAsync(request), Times.Once); if (expectsBlobDeleted) { _blobProvider.Verify(x => x.GetBlobFromUrl(nupkgUrl), Times.Once); blob.Verify(x => x.DeleteIfExistsAsync(), Times.Once); } else { _blobProvider.Verify(x => x.GetBlobFromUrl(nupkgUrl), Times.Never); blob.Verify(x => x.DeleteIfExistsAsync(), Times.Never); } }