Skip to content

Commit

Permalink
Merge pull request #16 from VerdantApp/dependabot/nuget/TIKSN-Framewo…
Browse files Browse the repository at this point in the history
…rk-5.0.1

Bump TIKSN-Framework from 5.0.0 to 5.0.1
  • Loading branch information
tiksn committed Apr 18, 2024
2 parents f0da3ec + fa0ea80 commit fa563a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Source/Licensing/Licensing.csproj
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Bond.CSharp" Version="10.0.0" />
<PackageReference Include="TIKSN-Framework" Version="5.0.0" />
<PackageReference Include="TIKSN-Framework" Version="5.0.1" />
</ItemGroup>

</Project>
37 changes: 24 additions & 13 deletions Source/Licensing/SystemEntitlementsConverter.cs
Expand Up @@ -69,9 +69,7 @@ public class SystemEntitlementsConverter : IEntitlementsConverter<SystemEntitlem
{
entitlements.Countries.ForEach(x => this.ValidateCountryCode(x, errors.Add));

#pragma warning disable SA1010 // Opening square brackets should be spaced correctly
result.CountryCodes = [.. entitlements.Countries.Select(x => x.TwoLetterISORegionName)];
#pragma warning restore SA1010 // Opening square brackets should be spaced correctly
}

if (errors.Count > 0)
Expand Down Expand Up @@ -132,7 +130,7 @@ public class SystemEntitlementsConverter : IEntitlementsConverter<SystemEntitlem
}

var countries = (entitlementsData.CountryCodes ?? new List<string>())
.Select(x => this.CreateRegion(x, errors.Add))
.Choose(x => this.CreateRegion(x, errors.Add))
.ToSeq();

if (errors.Count > 0)
Expand All @@ -146,18 +144,24 @@ public class SystemEntitlementsConverter : IEntitlementsConverter<SystemEntitlem
countries);
}

private RegionInfo CreateRegion(string? name, Action<Error> addError)
private Option<RegionInfo> CreateRegion(string? name, Action<Error> addError)
{
this.ValidateCountryCode(name, addError);

try
{
return this.regionFactory.Create(name);
}
catch (ArgumentException)
if (name is not null)
{
return this.regionFactory.Create("001");
try
{
return this.regionFactory.Create(name);
}
catch (ArgumentException)
{
addError(Error.New(9414785, "Country Code is unknown"));
return None;
}
}

return None;
}

private void ValidateCountryCode(RegionInfo? country, Action<Error> addError)
Expand All @@ -168,18 +172,25 @@ private void ValidateCountryCode(string? code, Action<Error> addError)
if (string.IsNullOrWhiteSpace(code))
{
addError(Error.New(253163448, "Country Code is missing"));
return;
}
else if (code.Length < 2)

if (code.Length < 2)
{
addError(Error.New(1280422427, "Country Code is too short"));
return;
}
else if (code.Length > 2)

if (code.Length > 2)
{
addError(Error.New(1165853056, "Country Code is too long"));
return;
}
else if (!code.All(char.IsAsciiLetterUpper))

if (!code.All(char.IsAsciiLetterUpper))
{
addError(Error.New(1638279115, "Country Code must contain only upper case ASCII letters"));
return;
}

try
Expand Down

0 comments on commit fa563a3

Please sign in to comment.