Skip to content

Commit

Permalink
Fixed LocaleUnit. (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Francis Pion <francis.pion@akinox.com>
  • Loading branch information
Utar94 and fpion-akinox authored Feb 7, 2024
1 parent 6de320b commit 9acc25c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Logitar.Identity.Domain/Logitar.Identity.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/Logitar/Identity</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>0.11.4.0</AssemblyVersion>
<AssemblyVersion>0.11.5.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Version>0.11.4</Version>
<Version>0.11.5</Version>
<NeutralLanguage>en-CA</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReleaseNotes>Fixed event serialization.</PackageReleaseNotes>
<PackageReleaseNotes>Fixed LocaleUnit.</PackageReleaseNotes>
<PackageTags>logitar;net;framework;identity;domain</PackageTags>
<PackageProjectUrl>https://github.com/Logitar/Identity/tree/main/src/Logitar.Identity.Domain</PackageProjectUrl>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Logitar.Identity.Domain/Shared/LocaleUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Logitar.Identity.Domain.Shared;
/// by an optional <see href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 Alpha-2 country code</see>. These codes shall be separated by an
/// hyphen (-).
/// </summary>
public class LocaleUnit
public record LocaleUnit
{
/// <summary>
/// The maximum length of locale codes.
Expand Down
13 changes: 13 additions & 0 deletions tests/Logitar.Identity.Domain.UnitTests/Shared/LocaleUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ public void ctor_it_should_throw_ValidationException_when_the_value_is_not_a_val
});
}

[Theory(DisplayName = "Equals: two locales with the same code should be equal.")]
[InlineData("en")]
[InlineData("en-US")]
public void Equals_two_locales_with_the_same_code_should_be_equal(string code)
{
LocaleUnit left = new(code);
LocaleUnit right = new(CultureInfo.GetCultureInfo(code));

Assert.Equal(left, right);
Assert.True(left.Equals(right));
Assert.True(left == right);
}

[Theory(DisplayName = "TryCreate: it should return a locale when the value is not empty.")]
[InlineData("es-MX")]
[InlineData(" es")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ public void ctor_it_should_throw_ValidationException_when_the_value_is_not_a_val
Assert.Contains(exception.Errors, e => e.ErrorCode == "TimeZoneValidator");
}

[Theory(DisplayName = "Equals: two time zones with the same identifier should be equal.")]
[InlineData("America/Montreal")]
[InlineData("America/New_York")]
public void Equals_two_time_zones_with_the_same_identifier_should_be_equal(string id)
{
TimeZoneUnit left = new(id);

DateTimeZone? dtz = DateTimeZoneProviders.Tzdb.GetZoneOrNull(id);
Assert.NotNull(dtz);
TimeZoneUnit right = new(dtz);

Assert.Equal(left, right);
Assert.True(left.Equals(right));
Assert.True(left == right);
}

[Theory(DisplayName = "TryCreate: it should return a time zone when the value is not empty.")]
[InlineData("America/New_York")]
[InlineData(" America/Montreal ")]
Expand Down
13 changes: 13 additions & 0 deletions tests/Logitar.Identity.Domain.UnitTests/Shared/UrlUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ public void ctor_it_should_throw_ValidationException_when_the_Uri_value_is_too_l
});
}

[Theory(DisplayName = "Equals: two URLs with the same value should be equal.")]
[InlineData("https://www.test.com/")]
[InlineData("https://www.test.com/projects/123?source=google#sub")]
public void Equals_two_Urls_with_the_same_value_should_be_equal(string value)
{
UrlUnit left = new(value);
UrlUnit right = new(new Uri(value));

Assert.Equal(left, right);
Assert.True(left.Equals(right));
Assert.True(left == right);
}

[Theory(DisplayName = "TryCreate: it should return a URL when the value is not empty.")]
[InlineData("http://test.com")]
[InlineData(" https://www.test.com/ ")]
Expand Down

0 comments on commit 9acc25c

Please sign in to comment.