Skip to content

Commit

Permalink
Ensure supported countries cannot be modified directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Jul 24, 2019
1 parent b5b5147 commit 5364406
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/IbanNet/IbanValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IReadOnlyDictionary<string, CountryInfo> SupportedCountries
{
InitRegistry();

return _structures;
return new ReadOnlyDictionary<string, CountryInfo>(_structures);
}
}

Expand Down
18 changes: 17 additions & 1 deletion test/IbanNet.Tests/IbanValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using FluentAssertions;
using System;
using System.Collections.Generic;
using FluentAssertions;
using IbanNet.Registry;
using NUnit.Framework;

namespace IbanNet
Expand Down Expand Up @@ -177,5 +180,18 @@ public void When_validating_good_iban_should_validate(string countryCode, string
// Assert
actual.Should().BeEquivalentTo(expectedResult);
}

[Test]
public void When_casting_readonly_countries_dictionary_should_not_be_able_to_add()
{
var countries = (IDictionary<string, CountryInfo>)_validator.SupportedCountries;

// Act
Action act = () => countries.Add("key", new CountryInfo());

// Assert
act.Should().Throw<NotSupportedException>()
.WithMessage("Collection is read-only.");
}
}
}

0 comments on commit 5364406

Please sign in to comment.