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) }); }
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 IsValidCountryCodeRule(IIbanRegistry ibanRegistry) { _ibanRegistry = ibanRegistry ?? throw new ArgumentNullException(nameof(ibanRegistry)); }
/// <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)); }