-
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
1 changed file
with
37 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 37 additions & 2 deletions
39
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 |
---|---|---|
@@ -1,7 +1,42 @@ | ||
namespace Logitar.Identity.Infrastructure.Converters; | ||
using Logitar.Identity.Core.Passwords; | ||
using Moq; | ||
|
||
namespace Logitar.Identity.Infrastructure.Converters; | ||
|
||
[Trait(Traits.Category, Categories.Unit)] | ||
public class PasswordConverterTests | ||
{ | ||
// TODO(fpion): implement | ||
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); | ||
} | ||
} |