Exemplo n.º 1
0
            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 <SymbolsServerRequest> AddSymbolsServerRequestAsync(SymbolsServerRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var currentRequest = await GetSymbolsServerRequestAsync(request.RequestName, request.SymbolsKey);

            if (currentRequest != null)
            {
                return(currentRequest);
            }

            _validationEntitiesContext.SymbolsServerRequests.Add(request);
            try
            {
                await _validationEntitiesContext.SaveChangesAsync();

                return(request);
            }
            catch (DbUpdateException e) when(e.IsUniqueConstraintViolationException())
            {
                // The request must be ingested already.
                return(await GetSymbolsServerRequestAsync(request.RequestName, request.SymbolsKey));
            }
        }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 4
0
            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);
            }
Exemplo n.º 5
0
            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);
            }
Exemplo n.º 6
0
            public void ToValidationResponseIngesting()
            {
                // Arrange
                SymbolsServerRequest request = new SymbolsServerRequest()
                {
                    RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingesting
                };


                // Act
                var result = SymbolsValidationEntitiesService.ToValidationResponse(request);

                // Assert
                Assert.Equal(ValidationStatus.Incomplete, result.Status);
            }
            public void ConvertToIValidationResultIngested()
            {
                // Arrange
                SymbolsServerRequest request = new SymbolsServerRequest()
                {
                    RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingested
                };


                // Act
                var result = SymbolsValidationEntitiesService.ConvertToIValidationResult(request);

                // Assert
                Assert.Equal(ValidationStatus.Succeeded, result.Status);
            }
        public async Task <bool> TryUpdateSymbolsServerRequestAsync(SymbolsServerRequest request, SymbolsPackageIngestRequestStatus newStatus)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (await GetSymbolsServerRequestAsync(request.RequestName, request.SymbolsKey) == null)
            {
                return(false);
            }
            request.RequestStatusKey = newStatus;
            request.LastUpdated      = DateTime.UtcNow;
            await _validationEntitiesContext.SaveChangesAsync();

            return(true);
        }
        public void CanCreateSymbolServerRequest()
        {
            // Arrange
            var request = new SymbolsServerRequest()
            {
                Created          = new DateTime(2018, 4, 1),
                RequestName      = "vstsrequest",
                RequestStatusKey = SymbolsPackageIngestRequestStatus.Ingested,
                SymbolsKey       = 7,
                LastUpdated      = new DateTime(2018, 4, 1)
            };

            // Assert
            Assert.Equal("vstsrequest", request.RequestName);
            Assert.Equal(7, request.SymbolsKey);
            Assert.Equal(2018, request.Created.Year);
            Assert.Equal(2018, request.LastUpdated.Year);
            Assert.Equal(SymbolsPackageIngestRequestStatus.Ingested, request.RequestStatusKey);
        }
        /// <summary>
        /// Converts a <see cref="SymbolsServerRequest"/> to <see cref="INuGetValidationResponse"/>
        /// </summary>
        /// <param name="symbolsServerRequest">A <see cref="SymbolsServerRequest" />.</param>
        /// <returns>The <see cref="INuGetValidationResponse"/>.</returns>
        public static INuGetValidationResponse ToValidationResponse(SymbolsServerRequest symbolsServerRequest)
        {
            if (symbolsServerRequest == null)
            {
                return(new NuGetValidationResponse(ValidationStatus.NotStarted));
            }
            switch (symbolsServerRequest.RequestStatusKey)
            {
            case SymbolsPackageIngestRequestStatus.FailedIngestion:
                return(new NuGetValidationResponse(ValidationStatus.Failed));

            case SymbolsPackageIngestRequestStatus.Ingested:
                return(new NuGetValidationResponse(ValidationStatus.Succeeded));

            case SymbolsPackageIngestRequestStatus.Ingesting:
                return(new NuGetValidationResponse(ValidationStatus.Incomplete));

            default:
                throw new ArgumentOutOfRangeException("Unexpected SymbolsPackageIngestRequestStatus.");
            }
        }