예제 #1
0
        public void Given_bankAccountNumber_when_building_it_should_return_value(Type builderType, string countryCode, string bankAccountNumber, string expected)
        {
            IBankAccountBuilder builder = CreateBuilder(builderType)
                                          .WithCountry(countryCode, IbanRegistry.Default)
                                          .WithBankAccountNumber(bankAccountNumber);

            // Act
            string actual = builder.Build();

            // Assert
            actual.Should().Be(expected);
        }
예제 #2
0
        public void Given_only_country_when_building_it_should_not_throw(Type builderType, string countryCode, string expected)
        {
            IBankAccountBuilder builder = CreateBuilder(builderType)
                                          .WithCountry(countryCode, IbanRegistry.Default);

            // Act
            Func <string> act = () => builder.Build();

            // Assert
            act.Should()
            .NotThrow()
            .Which.Should()
            .Be(expected);
        }
예제 #3
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));
        }
예제 #4
0
        public void Given_country_is_not_set_when_building_it_should_throw(Type builderType)
        {
            string exSource = builderType.Name.Substring(0, 4).ToUpperInvariant();

            IBankAccountBuilder builder = CreateBuilder(builderType);

            // Act
            Action act = () => builder.Build();

            // Assert
            act.Should()
            .ThrowExactly <BankAccountBuilderException>()
            .WithMessage($"The {exSource} cannot be built.")
            .WithInnerException <InvalidOperationException>()
            .WithMessage("The country is required.");
        }
예제 #5
0
        public void Given_country_does_not_support_branchIdentifier_when_building_it_should_throw(Type builderType)
        {
            string exSource = builderType.Name.Substring(0, 4).ToUpperInvariant();

            IBankAccountBuilder builder = CreateBuilder(builderType)
                                          .WithCountry("NL", IbanRegistry.Default)
                                          .WithBranchIdentifier("123");

            // Act
            Action act = () => builder.Build();

            // Assert
            act.Should()
            .ThrowExactly <BankAccountBuilderException>()
            .WithMessage($"The {exSource} cannot be built.")
            .WithInnerException <InvalidOperationException>()
            .WithMessage("A value for 'Branch' is not supported for country code NL.");
        }
예제 #6
0
        /// <summary>
        /// Adds the specified <paramref name="countryCode"/> to the builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="countryCode">The country code.</param>
        /// <param name="registry">The IBAN registry to resolve the country from.</param>
        /// <returns>The builder to continue chaining.</returns>
        public static IBankAccountBuilder WithCountry(this IBankAccountBuilder builder, string countryCode, IIbanRegistry registry)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (registry is null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (!registry.TryGetValue(countryCode, out IbanCountry? country))
            {
                throw new ArgumentException(Resources.ArgumentException_Builder_The_country_code_is_not_registered, nameof(countryCode));
            }

            return(builder.WithCountry(country));
        }
예제 #7
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) });
            }
예제 #8
0
        public void Given_value_is_too_short_and_padding_is_enabled_when_building_it_should_pad_with_zeroes(
            Type builderType,
            Action <IBankAccountBuilder, string, bool> @delegate,
            string countryCode,
            string value,
            string expected
            )
        {
            IBankAccountBuilder builder = CreateBuilder(builderType)
                                          .WithCountry(countryCode, IbanRegistry.Default);

            @delegate(builder, value, true);

            // Act
            Func <string> act = () => builder.Build();

            // Assert
            act.Should()
            .NotThrow()
            .Which.Should().Be(expected);
        }
예제 #9
0
        public void Given_value_is_too_short_and_padding_is_disabled_when_building_it_should_throw(
            Type builderType,
            Action <IBankAccountBuilder, string, bool> @delegate
            )
        {
            string exSource = builderType.Name.Substring(0, 4).ToUpperInvariant();

            IBankAccountBuilder builder = CreateBuilder(builderType)
                                          .WithCountry("GB", IbanRegistry.Default);

            @delegate(builder, "1", false);

            // Act
            Action act = () => builder.Build();

            // Assert
            act.Should()
            .ThrowExactly <BankAccountBuilderException>()
            .WithMessage($"The {exSource} cannot be built.")
            .WithInnerException <InvalidOperationException>()
            .WithMessage("The value '1' does not have the correct length of *.");
        }
예제 #10
0
            public void Given_invalid_arg_when_getting_builder_with_countryCode_it_should_throw(IBankAccountBuilder builder, string countryCode, IIbanRegistry registry, string expectedParamName)
            {
                // Act
                Action act = () => builder.WithCountry(countryCode, registry);

                // Assert
                act.Should()
                .Throw <ArgumentException>()
                .Which.ParamName.Should()
                .Be(expectedParamName);
            }
예제 #11
0
 public static BankAccount Default(IBankAccountBuilder builder) => builder.Build();