public async Task ReturnsPersistedStatusesIfValidationAlreadyStarted(ValidationStatus status) { // Arrange _symbolsValidationEntitiesService .Setup(x => x.GetSymbolsServerRequestAsync(It.IsAny <INuGetValidationRequest>())) .ReturnsAsync(new SymbolsServerRequest { Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, RequestName = PackageKey.ToString(), RequestStatusKey = ConvertToSymbolsPackageIngestRequestStatus(status), SymbolsKey = PackageKey }); // Act & Assert await _target.StartAsync(_validationRequest.Object); _symbolMessageEnqueuer .Verify(x => x.EnqueueSymbolsIngestionMessageAsync(It.IsAny <INuGetValidationRequest>()), Times.Never); _symbolsValidationEntitiesService .Verify(x => x.AddSymbolsServerRequestAsync(It.IsAny <SymbolsServerRequest>()), Times.Never); _telemetryService.Verify( x => x.TrackSymbolsMessageEnqueued(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()), Times.Never); }
public async Task TryAddReturnsAnExistentRequestIfAlreadyExistsInDatabase() { // Arrange SymbolsServerRequest request1 = new SymbolsServerRequest() { Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, RequestName = PackageKey.ToString(), RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingested, SymbolsKey = PackageKey }; SymbolsServerRequest request2 = new SymbolsServerRequest() { Created = new DateTime(2018, 4, 5), LastUpdated = DateTime.UtcNow, RequestName = PackageKey.ToString(), RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingested, SymbolsKey = PackageKey }; _validationEntitiesContext .Setup(x => x.SymbolsServerRequests) .Returns(DbSetMockFactory.Create(request1)); // Act var result = await _target.AddSymbolsServerRequestAsync(request2); // Assert Assert.Equal(request1.Created, result.Created); }
public async Task TryUpdateSymbolsServerRequestAsyncUpdateRequestIfInDatabase() { // Arrange SymbolsServerRequest request = new SymbolsServerRequest() { Created = new DateTime(2000, 4, 5), LastUpdated = new DateTime(2000, 4, 5), RequestName = PackageKey.ToString(), RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingesting, SymbolsKey = PackageKey }; _validationEntitiesContext .Setup(x => x.SymbolsServerRequests) .Returns(DbSetMockFactory.Create(request)); _validationEntitiesContext .Setup(x => x.SaveChangesAsync()) .ReturnsAsync(7); // Act var result = await _target.TryUpdateSymbolsServerRequestAsync(request, SymbolsPackageIngestRequestStatus.Ingested); // Assert Assert.True(result); Assert.Equal(DateTime.UtcNow.Year, request.LastUpdated.Year); }
public async Task TryUpdateSymbolsServerRequestAsyncReturnsFalseIfRequestNotInDatabase() { // Arrange SymbolsServerRequest request1 = new SymbolsServerRequest() { Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, RequestName = PackageKey.ToString(), RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingesting, SymbolsKey = PackageKey }; SymbolsServerRequest request2 = new SymbolsServerRequest() { Created = new DateTime(2018, 4, 5), LastUpdated = DateTime.UtcNow, RequestName = "Some Name", RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingesting, SymbolsKey = PackageKey }; _validationEntitiesContext .Setup(x => x.SymbolsServerRequests) .Returns(DbSetMockFactory.Create(request1)); // Act var result = await _target.TryUpdateSymbolsServerRequestAsync(request2, SymbolsPackageIngestRequestStatus.Ingested); // Assert Assert.False(result); }
public async Task <PackageStatus> Status(PackageKey packageKey) { var response = await innerClient.StatusAsync(new StatusRequest { PackageId = packageKey.ToString(), Target = 0 }); return((PackageStatus)response.Value); }
public async Task StartsValidationIfNotStarted() { // Arrange // The order of operations is important! The state MUST be persisted AFTER verification has been queued. var statePersisted = false; bool verificationQueuedBeforeStatePersisted = false; var ingestingRequest = new SymbolsServerRequest { Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, RequestName = PackageKey.ToString(), RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingesting, SymbolsKey = PackageKey }; var symbolsIngesterMessage = new SymbolsIngesterMessage(ValidationId, PackageKey, PackageId, PackageVersion, SnupkgUrl, "DummyRequestName"); _symbolsValidationEntitiesService .Setup(x => x.GetSymbolsServerRequestAsync(It.IsAny <INuGetValidationRequest>())) .ReturnsAsync((SymbolsServerRequest)null); _symbolMessageEnqueuer .Setup(x => x.EnqueueSymbolsIngestionMessageAsync(It.IsAny <INuGetValidationRequest>())) .Callback(() => { verificationQueuedBeforeStatePersisted = !statePersisted; }) .Returns(Task.FromResult(symbolsIngesterMessage)); _symbolsValidationEntitiesService .Setup(x => x.AddSymbolsServerRequestAsync(It.IsAny <SymbolsServerRequest>())) .Callback(() => { statePersisted = true; }) .ReturnsAsync(ingestingRequest); // Act await _target.StartAsync(_validationRequest.Object); // Assert _symbolMessageEnqueuer .Verify(x => x.EnqueueSymbolsIngestionMessageAsync(It.IsAny <INuGetValidationRequest>()), Times.Once); _symbolsValidationEntitiesService .Verify( x => x.AddSymbolsServerRequestAsync(It.IsAny <SymbolsServerRequest>()), Times.Once); _telemetryService.Verify( x => x.TrackSymbolsMessageEnqueued(_validationRequest.Object.PackageId, _validationRequest.Object.PackageVersion, ValidatorName.SymbolsIngester, _validationRequest.Object.ValidationId), Times.Once); Assert.True(verificationQueuedBeforeStatePersisted); }
public async Task ReturnsPersistedStatus(ValidationStatus status) { // Arrange _symbolsValidationEntitiesService .Setup(x => x.GetSymbolsServerRequestAsync(It.IsAny <INuGetValidationRequest>())) .ReturnsAsync(new SymbolsServerRequest { Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, RequestName = PackageKey.ToString(), RequestStatusKey = ConvertToSymbolsPackageIngestRequestStatus(status), SymbolsKey = PackageKey }); // Act & Assert var actual = await _target.GetResponseAsync(_validationRequest.Object); Assert.Equal(status, actual.Status); }
private void SetProgress(PackageKey packageKey, long current, long total) { if (LvPrimary.ItemsSource == null) { return; } var source = (ObservableCollection <DownloadListItem>)LvPrimary.ItemsSource; if (source.IsNullOrEmpty()) { return; } var item = source.First(x => x.Key.Equals(packageKey)); if (item != null) { Log.Verbose("{hash}: Setting progress for {package}: {current}/{total}", GetHashCode(), packageKey.ToString(), current, total); item.FileSize = total; item.Downloaded = current; } }