-
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
20 changed files
with
695 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/ApiKeyIdConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
using Logitar.Identity.Core.ApiKeys; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class ApiKeyIdConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public ApiKeyIdConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new ApiKeyIdConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
ApiKeyId apiKeyId = ApiKeyId.NewId(TenantId.NewId()); | ||
ApiKeyId deserialized = JsonSerializer.Deserialize<ApiKeyId>(string.Concat('"', apiKeyId, '"'), _serializerOptions); | ||
Assert.Equal(apiKeyId, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the default value from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_DefaultValue() | ||
{ | ||
ApiKeyId apiKeyId = JsonSerializer.Deserialize<ApiKeyId>("null", _serializerOptions); | ||
Assert.Equal(default, apiKeyId); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
ApiKeyId apiKeyId = ApiKeyId.NewId(TenantId.NewId()); | ||
string json = JsonSerializer.Serialize(apiKeyId, _serializerOptions); | ||
Assert.Equal(string.Concat('"', apiKeyId, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/CustomIdentifierConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class CustomIdentifierConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public CustomIdentifierConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new CustomIdentifierConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
CustomIdentifier customIdentifier = new("1234567890"); | ||
CustomIdentifier? deserialized = JsonSerializer.Deserialize<CustomIdentifier>(string.Concat('"', customIdentifier, '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(customIdentifier, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
CustomIdentifier? customIdentifier = JsonSerializer.Deserialize<CustomIdentifier>("null", _serializerOptions); | ||
Assert.Null(customIdentifier); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
CustomIdentifier customIdentifier = new("1234567890"); | ||
string json = JsonSerializer.Serialize(customIdentifier, _serializerOptions); | ||
Assert.Equal(string.Concat('"', customIdentifier, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/DescriptionConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class DescriptionConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public DescriptionConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new DescriptionConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
Description description = new("Hello World!"); | ||
Description? deserialized = JsonSerializer.Deserialize<Description>(string.Concat('"', description, '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(description, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
Description? description = JsonSerializer.Deserialize<Description>("null", _serializerOptions); | ||
Assert.Null(description); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
Description description = new("Hello World!"); | ||
string json = JsonSerializer.Serialize(description, _serializerOptions); | ||
Assert.Equal(string.Concat('"', description, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/DisplayNameConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class DisplayNameConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public DisplayNameConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new DisplayNameConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
DisplayName displayName = new("Administrator"); | ||
DisplayName? deserialized = JsonSerializer.Deserialize<DisplayName>(string.Concat('"', displayName, '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(displayName, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
DisplayName? displayName = JsonSerializer.Deserialize<DisplayName>("null", _serializerOptions); | ||
Assert.Null(displayName); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
DisplayName displayName = new("Administrator"); | ||
string json = JsonSerializer.Serialize(displayName, _serializerOptions); | ||
Assert.Equal(string.Concat('"', displayName, '"'), json); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/EntityIdConverterTests.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Logitar.Identity.Core; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class EntityIdConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public EntityIdConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new EntityIdConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
EntityId entityId = EntityId.NewId(); | ||
EntityId deserialized = JsonSerializer.Deserialize<EntityId>(string.Concat('"', entityId, '"'), _serializerOptions); | ||
Assert.Equal(entityId, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the default value from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_DefaultValue() | ||
{ | ||
EntityId entityId = JsonSerializer.Deserialize<EntityId>("null", _serializerOptions); | ||
Assert.Equal(default, entityId); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
EntityId entityId = EntityId.NewId(); | ||
string json = JsonSerializer.Serialize(entityId, _serializerOptions); | ||
Assert.Equal(string.Concat('"', entityId, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/GenderConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core.Users; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class GenderConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public GenderConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new GenderConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
Gender gender = new("male"); | ||
Gender? deserialized = JsonSerializer.Deserialize<Gender>(string.Concat('"', gender, '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(gender, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
Gender? gender = JsonSerializer.Deserialize<Gender>("null", _serializerOptions); | ||
Assert.Null(gender); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
Gender gender = new("female"); | ||
string json = JsonSerializer.Serialize(gender, _serializerOptions); | ||
Assert.Equal(string.Concat('"', gender, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/IdentifierConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class IdentifierConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public IdentifierConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new IdentifierConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
Identifier identifier = new("HealthInsuranceNumber"); | ||
Identifier? deserialized = JsonSerializer.Deserialize<Identifier>(string.Concat('"', identifier, '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(identifier, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
Identifier? identifier = JsonSerializer.Deserialize<Identifier>("null", _serializerOptions); | ||
Assert.Null(identifier); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
Identifier identifier = new("HealthInsuranceNumber"); | ||
string json = JsonSerializer.Serialize(identifier, _serializerOptions); | ||
Assert.Equal(string.Concat('"', identifier, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/LocaleConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class LocaleConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public LocaleConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new LocaleConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
Locale locale = new("en-US"); | ||
Locale? deserialized = JsonSerializer.Deserialize<Locale>(string.Concat('"', locale.Code, '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(locale, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
Locale? locale = JsonSerializer.Deserialize<Locale>("null", _serializerOptions); | ||
Assert.Null(locale); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
Locale locale = new("fr-CA"); | ||
string json = JsonSerializer.Serialize(locale, _serializerOptions); | ||
Assert.Equal(string.Concat('"', locale.Code, '"'), json); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...s/Logitar.Identity.Infrastructure.UnitTests/Converters/OneTimePasswordIdConverterTests.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Logitar.Identity.Core; | ||
using Logitar.Identity.Core.Passwords; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class OneTimePasswordIdConverterTests | ||
{ | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public OneTimePasswordIdConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new OneTimePasswordIdConverter()); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
OneTimePasswordId oneTimePasswordId = OneTimePasswordId.NewId(TenantId.NewId()); | ||
OneTimePasswordId deserialized = JsonSerializer.Deserialize<OneTimePasswordId>(string.Concat('"', oneTimePasswordId, '"'), _serializerOptions); | ||
Assert.Equal(oneTimePasswordId, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the default value from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_DefaultValue() | ||
{ | ||
OneTimePasswordId oneTimePasswordId = JsonSerializer.Deserialize<OneTimePasswordId>("null", _serializerOptions); | ||
Assert.Equal(default, oneTimePasswordId); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
OneTimePasswordId oneTimePasswordId = OneTimePasswordId.NewId(TenantId.NewId()); | ||
string json = JsonSerializer.Serialize(oneTimePasswordId, _serializerOptions); | ||
Assert.Equal(string.Concat('"', oneTimePasswordId, '"'), json); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/Logitar.Identity.Infrastructure.UnitTests/Converters/PasswordConverterTests.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Logitar.Identity.Core.Passwords; | ||
using Moq; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class PasswordConverterTests | ||
{ | ||
private readonly Mock<IPasswordManager> _passwordManager = new(); | ||
private readonly JsonSerializerOptions _serializerOptions = new(); | ||
|
||
public PasswordConverterTests() | ||
{ | ||
_serializerOptions.Converters.Add(new PasswordConverter(_passwordManager.Object)); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize the correct value from a non-null value.")] | ||
public void Given_Value_When_Deserialize_Then_CorrectValue() | ||
{ | ||
Base64Password password = new("P@s$W0rD"); | ||
_passwordManager.Setup(x => x.Decode(password.Encode())).Returns(password); | ||
|
||
Password? deserialized = JsonSerializer.Deserialize<Password>(string.Concat('"', password.Encode(), '"'), _serializerOptions); | ||
Assert.NotNull(deserialized); | ||
Assert.Same(password, deserialized); | ||
} | ||
|
||
[Fact(DisplayName = "It should deserialize null from a null value.")] | ||
public void Given_NullValue_When_Deserialize_Then_NullValue() | ||
{ | ||
Password? password = JsonSerializer.Deserialize<Password>("null", _serializerOptions); | ||
Assert.Null(password); | ||
} | ||
|
||
[Fact(DisplayName = "It should serialize correctly the value.")] | ||
public void Given_Value_When_Serialize_Then_SerializedCorrectly() | ||
{ | ||
Base64Password password = new("P@s$W0rD"); | ||
string json = JsonSerializer.Serialize<Password>(password, _serializerOptions); | ||
Assert.Equal(string.Concat('"', password.Encode(), '"'), json); | ||
} | ||
} |
Oops, something went wrong.