Ejemplo n.º 1
0
            public void MessageNullCheck()
            {
                // Arrange
                var handler = new SymbolsValidatorMessageHandler(_logger.Object, _symbolService.Object, _validatorStateService.Object);

                // Act + Assert
                Assert.ThrowsAsync <ArgumentNullException>(() => handler.HandleAsync(null));
            }
Ejemplo n.º 2
0
            public async Task ReturnsFalseWhenTheValidatorStateIsNotSaved()
            {
                // Arrange
                ValidatorStatus status = null;

                _validatorStateService.Setup(s => s.GetStatusAsync(It.IsAny <Guid>())).ReturnsAsync(status);
                var handler = new SymbolsValidatorMessageHandler(_logger.Object, _symbolService.Object, _validatorStateService.Object);

                // Act
                var result = await handler.HandleAsync(_message);

                // Assert
                Assert.False(result);
            }
Ejemplo n.º 3
0
            public async Task ReturnsTrueWhenTheValidatorStateIsSucceded()
            {
                // Arrange
                ValidatorStatus status = new ValidatorStatus()
                {
                    State = ValidationStatus.Succeeded
                };

                _validatorStateService.Setup(s => s.GetStatusAsync(It.IsAny <Guid>())).ReturnsAsync(status);
                var handler = new SymbolsValidatorMessageHandler(_logger.Object, _symbolService.Object, _validatorStateService.Object);

                // Act
                var result = await handler.HandleAsync(_message);

                // Assert
                Assert.True(result);
            }
            public FactBase()
            {
                _symbolService         = new Mock <ISymbolsValidatorService>();
                _validatorStateService = new Mock <IValidatorStateService>();
                _validationEnqueuer    = new Mock <IPackageValidationEnqueuer>();
                _featureFlagService    = new Mock <IFeatureFlagService>();
                _logger = new Mock <ILogger <SymbolsValidatorMessageHandler> >();

                _featureFlagService.SetReturnsDefault(true);

                Target = new SymbolsValidatorMessageHandler(
                    _symbolService.Object,
                    _validatorStateService.Object,
                    _validationEnqueuer.Object,
                    _featureFlagService.Object,
                    _logger.Object);

                _message = new SymbolsValidatorMessage(Guid.NewGuid(), 42, "TestPackage", "1.1.1", "url");
            }
Ejemplo n.º 5
0
            public async Task IncompleteStateIsProcessed()
            {
                // Arrange
                ValidatorStatus status = new ValidatorStatus()
                {
                    State = ValidationStatus.Incomplete
                };

                _validatorStateService.Setup(s => s.GetStatusAsync(It.IsAny <Guid>())).ReturnsAsync(status);
                _symbolService.Setup(s => s.ValidateSymbolsAsync(It.IsAny <SymbolsValidatorMessage>(), It.IsAny <CancellationToken>())).ReturnsAsync(ValidationResult.Incomplete);

                var handler = new SymbolsValidatorMessageHandler(_logger.Object, _symbolService.Object, _validatorStateService.Object);

                // Act
                var result = await handler.HandleAsync(_message);

                // Assert
                Assert.False(result);
                _symbolService.Verify(ss => ss.ValidateSymbolsAsync(It.IsAny <SymbolsValidatorMessage>(), It.IsAny <CancellationToken>()), Times.Once);
            }
Ejemplo n.º 6
0
            public async Task ReturnsFalseIfFailToSaveInDB()
            {
                // Arrange
                ValidatorStatus status = new ValidatorStatus()
                {
                    State = ValidationStatus.Incomplete
                };

                _validatorStateService.Setup(s => s.GetStatusAsync(It.IsAny <Guid>())).ReturnsAsync(status);
                _validatorStateService.Setup(s => s.SaveStatusAsync(It.IsAny <ValidatorStatus>())).ReturnsAsync(SaveStatusResult.StaleStatus);

                _symbolService.Setup(s => s.ValidateSymbolsAsync(It.IsAny <SymbolsValidatorMessage>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(ValidationResult.Succeeded);

                var handler = new SymbolsValidatorMessageHandler(_logger.Object, _symbolService.Object, _validatorStateService.Object);

                // Act
                var result = await handler.HandleAsync(_message);

                // Assert
                Assert.False(result);
            }
Ejemplo n.º 7
0
            public async Task IncompleteStateIsProcessedAndSavedOnFailed()
            {
                // Arrange
                ValidatorStatus status = new ValidatorStatus()
                {
                    State = ValidationStatus.Incomplete
                };

                _validatorStateService.Setup(s => s.GetStatusAsync(It.IsAny <Guid>())).ReturnsAsync(status);
                _validatorStateService.Setup(s => s.SaveStatusAsync(It.IsAny <ValidatorStatus>())).ReturnsAsync(SaveStatusResult.Success);

                _symbolService.Setup(s => s.ValidateSymbolsAsync(It.IsAny <SymbolsValidatorMessage>(), It.IsAny <CancellationToken>())).
                ReturnsAsync(ValidationResult.FailedWithIssues(ValidationIssue.Unknown));

                var handler = new SymbolsValidatorMessageHandler(_logger.Object, _symbolService.Object, _validatorStateService.Object);

                // Act
                var result = await handler.HandleAsync(_message);

                // Assert
                Assert.True(result);
                Assert.Equal(1, status.ValidatorIssues.Count);
                _validatorStateService.Verify(ss => ss.SaveStatusAsync(It.IsAny <ValidatorStatus>()), Times.Once);
            }