public async Task ValidateAsync_HappyFlow_ShouldNotAddAnyValidationResults(
            [Frozen] Mock <IEnumerable <IValidationRule> > validationRules,
            [Frozen] Mock <IRuleConfigurationRepository> ruleConfigurationRepository,
            [Frozen] Mock <ILogger <ChangeOfChargesDomainValidator> > logger)
        {
            // Arrange
            SetupValidationRulesCollection(validationRules);

            ruleConfigurationRepository.Setup(x => x.GetRuleConfigurationsAsync())
            .ReturnsAsync(new List <ValidationRuleConfiguration>
            {
                new ValidationRuleConfiguration(ValidationRuleNames.StartOfValidIntervalFromNowInDays, "30"),
                new ValidationRuleConfiguration(ValidationRuleNames.EndOfValidIntervalFromNowInDays, "1000"),
            });

            var sut = new ChangeOfChargesDomainValidator(
                validationRules.Object,
                ruleConfigurationRepository.Object,
                logger.Object);

            var changeOfChargesMessage = new ChangeOfChargesMessage
            {
                MktActivityRecord = new MktActivityRecord
                {
                    ValidityStartDate = SystemClock.Instance.GetCurrentInstant()
                                        .Plus(Duration.FromDays(500)),
                },
            };

            // Act
            var validationResult = await sut.ValidateAsync(changeOfChargesMessage);

            // Assert
            validationResult.Errors.Should().BeEmpty();
        }
        public async Task ValidateAsync_WhenRuleConfigurationCannotBeCastCorrectly_ShouldAddValidationResultAndLog(
            [Frozen] Mock <IEnumerable <IValidationRule> > validationRules,
            [Frozen] Mock <IRuleConfigurationRepository> ruleConfigurationRepository,
            [Frozen] Mock <ILogger <ChangeOfChargesDomainValidator> > logger)
        {
            // Arrange
            SetupValidationRulesCollection(validationRules);

            ruleConfigurationRepository.Setup(x => x.GetRuleConfigurationsAsync())
            .ReturnsAsync(new List <ValidationRuleConfiguration>
            {
                new ValidationRuleConfiguration(ValidationRuleNames.StartOfValidIntervalFromNowInDays, "not valid"),
                new ValidationRuleConfiguration(ValidationRuleNames.EndOfValidIntervalFromNowInDays, "not valid"),
            });

            var sut = new ChangeOfChargesDomainValidator(
                validationRules.Object,
                ruleConfigurationRepository.Object,
                logger.Object);

            // Act
            var validationResult = await sut.ValidateAsync(new ChangeOfChargesMessage());

            // Assert
            validationResult.Errors.Single().Code.Should().Be("VRXYZ");
            logger.VerifyLoggerWasCalled("Rule value could not be mapped", LogLevel.Error);
        }
        public async Task ValidateAsync_WhenRuleThrowsRuleNotFoundException_ShouldAddValidationResultAndLog(
            [Frozen] Mock <IEnumerable <IValidationRule> > validationRules,
            [Frozen] Mock <IRuleConfigurationRepository> ruleConfigurationRepository,
            [Frozen] Mock <ILogger <ChangeOfChargesDomainValidator> > logger)
        {
            // Arrange
            SetupValidationRulesCollection(validationRules);

            ruleConfigurationRepository.Setup(x => x.GetRuleConfigurationsAsync())
            .ReturnsAsync(new List <ValidationRuleConfiguration>());
            var sut = new ChangeOfChargesDomainValidator(
                validationRules.Object,
                ruleConfigurationRepository.Object,
                logger.Object);

            // Act
            var validationResult = await sut.ValidateAsync(new ChangeOfChargesMessage());

            // Assert
            validationResult.Errors.Single().Code.Should().Be("VRXYZ");
            logger.VerifyLoggerWasCalled("Rule configuration could not be found", LogLevel.Error);
        }