public void Given_invalid_value_when_validating_it_should_return_error()
        {
            const string testValue = "XX";
            var          country   = new IbanCountry("NL")
            {
                Iban =
                {
                    Structure = "my-structure"
                }
            };

            _structureValidatorMock
            .Setup(m => m.Validate(testValue))
            .Returns(false)
            .Verifiable();

            // Act
            ValidationRuleResult actual = _sut.Validate(new ValidationRuleContext(testValue)
            {
                Country = country
            });

            // Assert
            actual.Should().BeOfType <InvalidStructureResult>();
            _structureValidatorMock.Verify();
            _structureValidationFactoryMock.Verify(m => m.CreateValidator(country.TwoLetterISORegionName, country.Iban.Structure), Times.Once);
        }
Пример #2
0
            public void Given_country_when_getting_bban_builder_it_should_return_instance()
            {
                var country = new IbanCountry("XX");

                // Act
                BbanBuilder actual = country.GetBbanBuilder();

                // Assert
                actual.Should().NotBeNull();
            }
Пример #3
0
            public void Given_null_country_when_getting_bban_builder_it_should_throw()
            {
                IbanCountry country = null;

                // Act
                // ReSharper disable once AssignNullToNotNullAttribute
                Action act = () => country.GetBbanBuilder();

                // Assert
                act.Should()
                .ThrowExactly <ArgumentNullException>()
                .Which.ParamName.Should()
                .Be(nameof(country));
            }
Пример #4
0
        public void Given_null_country_when_adding_it_should_throw(Type builderType)
        {
            IBankAccountBuilder builder = CreateBuilder(builderType);
            IbanCountry         country = null;

            // Act
            // ReSharper disable once AssignNullToNotNullAttribute
            Action act = () => builder.WithCountry(country);

            // Assert
            act.Should()
            .ThrowExactly <ArgumentNullException>()
            .Which.ParamName.Should()
            .Be(nameof(country));
        }
        public void Given_known_country_code_when_validating_it_should_return_success()
        {
            var context = new ValidationRuleContext("XX");
            var country = new IbanCountry("XX");
            var sut     = new IsValidCountryCodeRule(new IbanRegistry
            {
                Providers =
                {
                    new IbanRegistryListProvider(new[] { country })
                }
            });

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

            // Assert
            actual.Should().Be(ValidationRuleResult.Success);
            context.Country.Should().BeSameAs(country);
        }
Пример #6
0
            public static IEnumerable <object[]> WithCountryTestCases()
            {
                IBankAccountBuilder builder     = Mock.Of <IBankAccountBuilder>();
                const string        countryCode = "NL";
                IIbanRegistry       registry    = Mock.Of <IIbanRegistry>();

                IbanCountry other = null;
                var         nl    = new IbanCountry(countryCode);

                Mock.Get(registry).Setup(m => m.TryGetValue(It.IsAny <string>(), out other));
                Mock.Get(registry).Setup(m => m.TryGetValue("NL", out nl));

                yield return(new object[] { null, countryCode, registry, nameof(builder) });

                yield return(new object[] { builder, null, registry, nameof(countryCode) });

                yield return(new object[] { builder, countryCode, null, nameof(registry) });

                yield return(new object[] { builder, "ZZ", registry, nameof(countryCode) });
            }
Пример #7
0
 /// <inheritdoc />
 public IBankAccountBuilder WithCountry(IbanCountry country)
 {
     _bbanBuilder.WithCountry(country);
     _country = country;
     return(this);
 }
Пример #8
0
 /// <inheritdoc />
 public IBankAccountBuilder WithCountry(IbanCountry country)
 {
     _country = country ?? throw new ArgumentNullException(nameof(country));
     return(this);
 }
Пример #9
0
 /// <summary>
 /// Gets an <see cref="BbanBuilder"/> for this country.
 /// </summary>
 /// <param name="ibanCountry">The country.</param>
 /// <returns>An instance of <see cref="BbanBuilder"/> for the country specified in <paramref name="ibanCountry"/>.</returns>
 public static BbanBuilder GetBbanBuilder(this IbanCountry ibanCountry)
 {
     return((BbanBuilder) new BbanBuilder().WithCountry(ibanCountry));
 }
Пример #10
0
 /// <summary>
 /// Gets an <see cref="IbanBuilder"/> for this country.
 /// </summary>
 /// <param name="ibanCountry">The country.</param>
 /// <returns>An instance of <see cref="IbanBuilder"/> for the country specified in <paramref name="ibanCountry"/>.</returns>
 public static IbanBuilder GetIbanBuilder(this IbanCountry ibanCountry)
 {
     return((IbanBuilder) new IbanBuilder().WithCountry(ibanCountry));
 }