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); }
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)); }
/// <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)); }