private void HandleValidationRule(
            ChangeOfChargesMessage changeOfChargesMessage,
            IValidationRule validationRule,
            HubRequestValidationResult validationResult)
        {
            const string unknownServerError = "Unknown server error";

            try
            {
                if (_ruleConfigurations == null)
                {
                    validationResult.Add(new ValidationError("VR900", unknownServerError));
                    _logger.LogError($"{nameof(_ruleConfigurations)} was null");
                    return;
                }

                var ruleValidationResult = validationRule.Validate(changeOfChargesMessage, _ruleConfigurations);

                if (ruleValidationResult.ValidatedSuccessfully is false)
                {
                    validationResult.Add(ruleValidationResult.ValidationError);
                }
            }
            catch (RuleNotFoundException ruleNotFoundException)
            {
                validationResult.Add(new ValidationError("VRXYZ", unknownServerError));
                _logger.LogError(ruleNotFoundException, "Rule configuration could not be found");
            }
            catch (RuleCouldNotBeMappedException ruleCouldNotBeMappedException)
            {
                validationResult.Add(new ValidationError("VRXYZ", unknownServerError));
                _logger.LogError(ruleCouldNotBeMappedException, "Rule value could not be mapped");
            }
        }
        public async Task <HubRequestValidationResult> ValidateAsync(ChangeOfChargesMessage changeOfChargesMessage)
        {
            var result = await _inputValidationRuleEngine.ValidateAsync(changeOfChargesMessage).ConfigureAwait(false);

            var hubRequestValidationResult = new HubRequestValidationResult(changeOfChargesMessage.Transaction.MRID);

            foreach (var error in result)
            {
                hubRequestValidationResult.Add(new ValidationError(error.RuleNumber, error.Message));
            }

            return(hubRequestValidationResult);
        }
Ejemplo n.º 3
0
        public async Task ValidateAsync_WhenInputValidationResultsContainsErrors_ShouldReturnFalse(
            [Frozen] HubRequestValidationResult validationResult,
            [Frozen] Mock <IChangeOfChargesInputValidator> inputValidator,
            [NotNull] ChangeOfChargesCommandHandlerTestable sut)
        {
            validationResult.Add(new ValidationError("some error code", "some error message"));
            inputValidator.Setup(iv => iv.ValidateAsync(It.IsAny <ChangeOfChargesMessage>()))
            .ReturnsAsync(validationResult);

            var result = await sut.CallValidateAsync(new ChangeOfChargesMessage()).ConfigureAwait(false);

            result.Should().Be(false);
        }
Ejemplo n.º 4
0
        public async Task <IHubResponse> DispatchAsync(IEnumerable <IHubMessage> hubRequests)
        {
            if (hubRequests == null)
            {
                throw new ArgumentNullException(nameof(hubRequests));
            }

            var validationResults = new List <HubRequestValidationResult>();

            foreach (var hubRequest in hubRequests)
            {
                var result = await _hubRequestMediator.DispatchAsync(hubRequest).ConfigureAwait(false);

                var validationResult = new HubRequestValidationResult(hubRequest.Transaction.MRID);

                result.Errors.ForEach(error => validationResult.Add(new ValidationError("UnknownCode", error)));
                validationResults.Add(validationResult);
            }

            return(new CustomHubResponse(validationResults));
        }