-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
551 additions
and
16 deletions.
There are no files selected for viewing
73 changes: 71 additions & 2 deletions
73
tests/Logitar.Identity.Core.UnitTests/CustomIdentifierTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
namespace Logitar.Identity.Core; | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
using Logitar.Security.Cryptography; | ||
|
||
namespace Logitar.Identity.Core; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class CustomIdentifierTests | ||
{ | ||
// TODO(fpion): implement | ||
[Fact(DisplayName = "ctor: it should construct the correct instance given a valid value.")] | ||
public void Given_ValidValue_When_ctor_Then_ConstructedCorrectly() | ||
{ | ||
string value = " 1234567890 "; | ||
CustomIdentifier displayName = new(value); | ||
Assert.Equal(value.Trim(), displayName.Value); | ||
} | ||
|
||
[Theory(DisplayName = "ctor: it should throw ValidationException given an empty or white-space value.")] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_EmptyOrWhiteSpace_When_ctor_Then_ValidationException(string value) | ||
{ | ||
var exception = Assert.Throws<ValidationException>(() => new CustomIdentifier(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("NotEmptyValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
|
||
[Fact(DisplayName = "ctor: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_ctor_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => new CustomIdentifier(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("MaximumLengthValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
|
||
[Fact(DisplayName = "ToString: it should return the correct string representation.")] | ||
public void Given_CustomIdentifier_When_ToString_Then_CorrectString() | ||
{ | ||
CustomIdentifier displayName = new("1234567890"); | ||
Assert.Equal(displayName.Value, displayName.ToString()); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should return a new instance given a valid value.")] | ||
public void Given_ValidValue_When_TryCreate_Then_InstanceReturned() | ||
{ | ||
string value = " 1234567890 "; | ||
CustomIdentifier? displayName = CustomIdentifier.TryCreate(value); | ||
Assert.NotNull(displayName); | ||
Assert.Equal(value.Trim(), displayName.Value); | ||
} | ||
|
||
[Theory(DisplayName = "TryCreate: it should return null given a null, empty, or white-space value.")] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_NullEmptyOrWhiteSpace_When_TryCreate_Then_NullReturned(string? value) | ||
{ | ||
Assert.Null(CustomIdentifier.TryCreate(value)); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_TryCreate_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => CustomIdentifier.TryCreate(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("MaximumLengthValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
namespace Logitar.Identity.Core; | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
|
||
namespace Logitar.Identity.Core; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class DescriptionTests | ||
{ | ||
// TODO(fpion): implement | ||
[Fact(DisplayName = "ctor: it should construct the correct instance given a valid value.")] | ||
public void Given_ValidValue_When_ctor_Then_ConstructedCorrectly() | ||
{ | ||
string value = " Hello World! "; | ||
Description description = new(value); | ||
Assert.Equal(value.Trim(), description.Value); | ||
} | ||
|
||
[Theory(DisplayName = "ctor: it should throw ValidationException given an empty or white-space value.")] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_EmptyOrWhiteSpace_When_ctor_Then_ValidationException(string value) | ||
{ | ||
var exception = Assert.Throws<ValidationException>(() => new Description(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("NotEmptyValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
|
||
[Fact(DisplayName = "ToString: it should return the correct string representation.")] | ||
public void Given_Description_When_ToString_Then_CorrectString() | ||
{ | ||
Description description = new("Hello World!"); | ||
Assert.Equal(description.Value, description.ToString()); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should return a new instance given a valid value.")] | ||
public void Given_ValidValue_When_TryCreate_Then_InstanceReturned() | ||
{ | ||
string value = " Hello World! "; | ||
Description? description = Description.TryCreate(value); | ||
Assert.NotNull(description); | ||
Assert.Equal(value.Trim(), description.Value); | ||
} | ||
|
||
[Theory(DisplayName = "TryCreate: it should return null given a null, empty, or white-space value.")] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_NullEmptyOrWhiteSpace_When_TryCreate_Then_NullReturned(string? value) | ||
{ | ||
Assert.Null(Description.TryCreate(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
namespace Logitar.Identity.Core; | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
using Logitar.Security.Cryptography; | ||
|
||
namespace Logitar.Identity.Core; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class DisplayNameTests | ||
{ | ||
// TODO(fpion): implement | ||
[Fact(DisplayName = "ctor: it should construct the correct instance given a valid value.")] | ||
public void Given_ValidValue_When_ctor_Then_ConstructedCorrectly() | ||
{ | ||
string value = " Administrator "; | ||
DisplayName displayName = new(value); | ||
Assert.Equal(value.Trim(), displayName.Value); | ||
} | ||
|
||
[Theory(DisplayName = "ctor: it should throw ValidationException given an empty, or white-space value.")] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_EmptyOrWhiteSpace_When_ctor_Then_ValidationException(string value) | ||
{ | ||
var exception = Assert.Throws<ValidationException>(() => new DisplayName(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("NotEmptyValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
|
||
[Fact(DisplayName = "ctor: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_ctor_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => new DisplayName(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("MaximumLengthValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
|
||
[Fact(DisplayName = "ToString: it should return the correct string representation.")] | ||
public void Given_DisplayName_When_ToString_Then_CorrectString() | ||
{ | ||
DisplayName displayName = new("Administrator"); | ||
Assert.Equal(displayName.Value, displayName.ToString()); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should return a new instance given a valid value.")] | ||
public void Given_ValidValue_When_TryCreate_Then_InstanceReturned() | ||
{ | ||
string value = " Administrator "; | ||
DisplayName? displayName = DisplayName.TryCreate(value); | ||
Assert.NotNull(displayName); | ||
Assert.Equal(value.Trim(), displayName.Value); | ||
} | ||
|
||
[Theory(DisplayName = "TryCreate: it should return null given a null, empty, or white-space value.")] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_NullEmptyOrWhiteSpace_When_TryCreate_Then_NullReturned(string? value) | ||
{ | ||
Assert.Null(DisplayName.TryCreate(value)); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_TryCreate_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => DisplayName.TryCreate(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("MaximumLengthValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
namespace Logitar.Identity.Core; | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
using Logitar.Security.Cryptography; | ||
|
||
namespace Logitar.Identity.Core; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class IdentifierTests | ||
{ | ||
// TODO(fpion): implement | ||
[Fact(DisplayName = "ctor: it should construct the correct instance given a valid value.")] | ||
public void Given_ValidValue_When_ctor_Then_ConstructedCorrectly() | ||
{ | ||
string value = " HealthInsuranceNumber "; | ||
Identifier identifier = new(value); | ||
Assert.Equal(value.Trim(), identifier.Value); | ||
} | ||
|
||
[Theory(DisplayName = "ctor: it should throw ValidationException given an empty or white-space value.")] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_EmptyOrWhiteSpace_When_ctor_Then_ValidationException(string value) | ||
{ | ||
var exception = Assert.Throws<ValidationException>(() => new Identifier(value)); | ||
|
||
ValidationFailure failure = Assert.Single(exception.Errors); | ||
Assert.Equal("NotEmptyValidator", failure.ErrorCode); | ||
Assert.Equal("Value", failure.PropertyName); | ||
} | ||
|
||
[Fact(DisplayName = "ctor: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_ctor_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => new Identifier(value)); | ||
|
||
Assert.Equal(2, exception.Errors.Count()); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "IdentifierValidator" && e.PropertyName == "Value"); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "MaximumLengthValidator" && e.PropertyName == "Value"); | ||
} | ||
|
||
[Fact(DisplayName = "ToString: it should return the correct string representation.")] | ||
public void Given_Identifier_When_ToString_Then_CorrectString() | ||
{ | ||
Identifier identifier = new("HealthInsuranceNumber"); | ||
Assert.Equal(identifier.Value, identifier.ToString()); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should return a new instance given a valid value.")] | ||
public void Given_ValidValue_When_TryCreate_Then_InstanceReturned() | ||
{ | ||
string value = " HealthInsuranceNumber "; | ||
Identifier? identifier = Identifier.TryCreate(value); | ||
Assert.NotNull(identifier); | ||
Assert.Equal(value.Trim(), identifier.Value); | ||
} | ||
|
||
[Theory(DisplayName = "TryCreate: it should return null given a null, empty, or white-space value.")] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_NullEmptyOrWhiteSpace_When_TryCreate_Then_NullReturned(string? value) | ||
{ | ||
Assert.Null(Identifier.TryCreate(value)); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_TryCreate_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => Identifier.TryCreate(value)); | ||
|
||
Assert.Equal(2, exception.Errors.Count()); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "IdentifierValidator" && e.PropertyName == "Value"); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "MaximumLengthValidator" && e.PropertyName == "Value"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
namespace Logitar.Identity.Core; | ||
using FluentValidation; | ||
using Logitar.Security.Cryptography; | ||
using System.Globalization; | ||
|
||
namespace Logitar.Identity.Core; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class LocaleTests | ||
{ | ||
// TODO(fpion): implement | ||
[Fact(DisplayName = "ctor: it should construct the correct instance given a valid value.")] | ||
public void Given_ValidValue_When_ctor_Then_ConstructedCorrectly() | ||
{ | ||
CultureInfo culture = CultureInfo.GetCultureInfo("fr-CA"); | ||
Locale locale = new($" {culture} "); | ||
Assert.Equal(culture.Name, locale.Code); | ||
Assert.Equal(culture, locale.Culture); | ||
} | ||
|
||
[Theory(DisplayName = "ctor: it should throw ValidationException given an empty or white-space value.")] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_EmptyOrWhiteSpace_When_ctor_Then_ValidationException(string value) | ||
{ | ||
var exception = Assert.Throws<ValidationException>(() => new Locale(value)); | ||
|
||
Assert.Equal(2, exception.Errors.Count()); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "LocaleValidator" && e.PropertyName == "Code"); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "NotEmptyValidator" && e.PropertyName == "Code"); | ||
} | ||
|
||
[Fact(DisplayName = "ctor: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_ctor_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => new Locale(value)); | ||
|
||
Assert.Equal(2, exception.Errors.Count()); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "LocaleValidator" && e.PropertyName == "Code"); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "MaximumLengthValidator" && e.PropertyName == "Code"); | ||
} | ||
|
||
[Fact(DisplayName = "ToString: it should return the correct string representation.")] | ||
public void Given_Locale_When_ToString_Then_CorrectString() | ||
{ | ||
CultureInfo culture = CultureInfo.GetCultureInfo("fr-CA"); | ||
Locale locale = new(culture); | ||
Assert.Equal(string.Format("{0} ({1})", culture.DisplayName, culture.Name), locale.ToString()); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should return a new instance given a valid value.")] | ||
public void Given_ValidValue_When_TryCreate_Then_InstanceReturned() | ||
{ | ||
string value = " fr-CA "; | ||
Locale? locale = Locale.TryCreate(value); | ||
Assert.NotNull(locale); | ||
Assert.Equal(value.Trim(), locale.Culture.Name); | ||
} | ||
|
||
[Theory(DisplayName = "TryCreate: it should return null given a null, empty, or white-space value.")] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Given_NullEmptyOrWhiteSpace_When_TryCreate_Then_NullReturned(string? value) | ||
{ | ||
Assert.Null(Locale.TryCreate(value)); | ||
} | ||
|
||
[Fact(DisplayName = "TryCreate: it should throw ValidationException given an invalid value.")] | ||
public void Given_InvalidValue_When_TryCreate_Then_ValidationException() | ||
{ | ||
string value = RandomStringGenerator.GetString(999); | ||
var exception = Assert.Throws<ValidationException>(() => Locale.TryCreate(value)); | ||
|
||
Assert.Equal(2, exception.Errors.Count()); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "LocaleValidator" && e.PropertyName == "Code"); | ||
Assert.Contains(exception.Errors, e => e.ErrorCode == "MaximumLengthValidator" && e.PropertyName == "Code"); | ||
} | ||
} |
Oops, something went wrong.