public void Given_multiple_check_digit_validators_matching_the_country_when_validating_it_should_validate_using_any(bool matchesFirst)
        {
            var checkDigitValidatorStubs = new Dictionary <string, IEnumerable <NationalCheckDigitsValidator> >
            {
                { "ZZ", new[] { _checkDigitsValidatorMock.Object, _checkDigitsValidatorMock.Object } }
            };

            _checkDigitsValidatorMock
            .SetupSequence(m => m.Validate(It.IsAny <string>()))
            .Returns(matchesFirst)
            .Returns(true);

            var sut = new HasValidNationalCheckDigitsRule(checkDigitValidatorStubs);

            var context = new ValidationRuleContext("ZZ0123456",
                                                    new IbanCountry("ZZ")
            {
                Bban = new BbanStructure(
                    new TestPattern(new[] { new PatternToken(AsciiCategory.Digit, 7) }),
                    2)
            });

            // Act
            sut.Validate(context);

            // Assert
            _checkDigitsValidatorMock.Verify(m => m.Validate(It.IsAny <string>()), Times.Exactly(matchesFirst ? 1 : 2));
        }
        public HasValidNationalCheckDigitsRuleTests()
        {
            _checkDigitsValidatorMock = new Mock <NationalCheckDigitsValidator>(Mock.Of <ICheckDigitsCalculator>(), new[] { "ZZ" });

            var checkDigitValidatorStubs = new Dictionary <string, IEnumerable <NationalCheckDigitsValidator> >
            {
                { "ZZ", new[] { _checkDigitsValidatorMock.Object } }
            };

            _sut = new HasValidNationalCheckDigitsRule(checkDigitValidatorStubs);
        }
        public void Given_multiple_check_digit_validators_when_validating_it_should_only_use_those_that_have_matching_country()
        {
            var matchingCheckDigitValidatorMock = new Mock <NationalCheckDigitsValidator>(Mock.Of <ICheckDigitsCalculator>(), new[] { "WW" });

            var checkDigitValidatorStubs = new Dictionary <string, IEnumerable <NationalCheckDigitsValidator> >
            {
                { "ZZ", new[] { _checkDigitsValidatorMock.Object } },
                { "WW", new[] { matchingCheckDigitValidatorMock.Object } }
            };

            _checkDigitsValidatorMock
            .Setup(m => m.Validate(It.IsAny <string>()))
            .Returns(true)
            .Verifiable();

            matchingCheckDigitValidatorMock
            .Setup(m => m.Validate(It.IsAny <string>()))
            .Returns(true)
            .Verifiable();

            var sut = new HasValidNationalCheckDigitsRule(checkDigitValidatorStubs);

            var context = new ValidationRuleContext("WW0123456",
                                                    new IbanCountry("WW")
            {
                Bban = new BbanStructure(
                    new TestPattern(new[] { new PatternToken(AsciiCategory.Digit, 7) }),
                    2)
            });

            // Act
            ValidationRuleResult actual = sut.Validate(context);

            // Assert
            actual.Should().BeSameAs(ValidationRuleResult.Success);
            matchingCheckDigitValidatorMock.Verify();
            _checkDigitsValidatorMock.Verify(m => m.Validate(It.IsAny <string>()), Times.Never);
        }