Skip to content

Commit

Permalink
fix: when enumerating registry, order by country code
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Nov 20, 2024
1 parent 5e813a7 commit 3bc4b8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/IbanNet/Registry/IbanRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public IbanRegistry()
}

/// <inheritdoc />
public IEnumerator<IbanCountry> GetEnumerator() => Dictionary.Values.GetEnumerator();
public IEnumerator<IbanCountry> GetEnumerator()
{
return Dictionary.Values.OrderBy(c => c.TwoLetterISORegionName).GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand Down
12 changes: 12 additions & 0 deletions test/IbanNet.Tests/Registry/IbanRegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ public void Given_that_registry_has_been_hydrated_when_adding_another_provider_t
// Assert
sut.Providers.Should().HaveCount(1);
}

[Fact]
public void Registry_should_be_ordered_by_country_code()
{
var reg = new IbanRegistry { Providers = { new SwiftRegistryProvider() } };

// Act
var countryCodes = reg.Select(c => c.TwoLetterISORegionName).ToList();

// Assert
countryCodes.Should().BeInAscendingOrder();
}
}

0 comments on commit 3bc4b8f

Please sign in to comment.