public async Task SendsSerializeMessage()
        {
            // Arrange
            SymbolsIngesterMessage message = null;

            _serializer
            .Setup(x => x.Serialize(It.IsAny <SymbolsIngesterMessage>()))
            .Returns(() => _brokeredMessage.Object)
            .Callback <SymbolsIngesterMessage>(x => message = x);

            // Act
            await _target.EnqueueSymbolsIngestionMessageAsync(_validationRequest.Object);

            // Assert
            Assert.Equal(_validationRequest.Object.ValidationId, message.ValidationId);
            Assert.Equal(_validationRequest.Object.PackageId, message.PackageId);
            Assert.Equal(_validationRequest.Object.PackageVersion, message.PackageNormalizedVersion);
            Assert.Equal($"{_validationRequest.Object.PackageKey}_{_validationRequest.Object.ValidationId}", message.RequestName);

            Assert.Equal(_validationRequest.Object.NupkgUrl, message.SnupkgUrl);
            _serializer.Verify(
                x => x.Serialize(It.IsAny <SymbolsIngesterMessage>()),
                Times.Once);
            _topicClient.Verify(x => x.SendAsync(_brokeredMessage.Object), Times.Once);
            _topicClient.Verify(x => x.SendAsync(It.IsAny <IBrokeredMessage>()), Times.Once);
        }
Esempio n. 2
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);
            }
Esempio n. 3
0
        public async Task <SymbolsIngesterMessage> EnqueueSymbolsIngestionMessageAsync(IValidationRequest request)
        {
            var message = new SymbolsIngesterMessage(validationId: request.ValidationId,
                                                     symbolPackageKey: request.PackageKey,
                                                     packageId: request.PackageId,
                                                     packageNormalizedVersion: request.PackageVersion,
                                                     snupkgUrl: request.NupkgUrl,
                                                     requestName: SymbolsValidationEntitiesService.CreateSymbolServerRequestNameFromValidationRequest(request));
            var brokeredMessage = _serializer.Serialize(message);

            var visibleAt = DateTimeOffset.UtcNow + (_messageDelay ?? TimeSpan.Zero);

            brokeredMessage.ScheduledEnqueueTimeUtc = visibleAt;

            await _topicClient.SendAsync(brokeredMessage);

            return(message);
        }