-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🖋️ feat: Transform signature to value object (#162)
feat: implement signature value object
- Loading branch information
1 parent
c797a62
commit 2db6e2d
Showing
30 changed files
with
435 additions
and
118 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -32,4 +32,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
...et.Contracts/Src/Fitnet.Contracts.Api.UnitTests/SignContract/Signatures/SignatureTests.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,41 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Api.UnitTests.SignContract.Signatures; | ||
using EvolutionaryArchitecture.Fitnet.Contracts.Core.SignContract.Signatures; | ||
|
||
using Core.SignContract.Signatures.Exceptions; | ||
using FluentAssertions; | ||
|
||
public sealed class SignatureTests | ||
{ | ||
[Theory] | ||
[InlineData("John Doe")] | ||
[InlineData("Kamil Baczek")] | ||
[InlineData("Maciej Jedrzejewski")] | ||
[InlineData("John David Smith")] | ||
internal void Given_create_signature_When_signature_is_valid_Then_should_not_throw(string value) | ||
{ | ||
// Arrange | ||
var now = DateTimeOffset.Now; | ||
|
||
// Act | ||
var signature = Signature.From(now, value); | ||
|
||
// Assert | ||
signature.Value.Should().Be(value); | ||
signature.Date.Should().Be(now); | ||
} | ||
|
||
[Theory] | ||
[InlineData("invalidSignature!")] | ||
[InlineData("invalid@Signature")] | ||
internal void Given_create_signature_When_signature_has_forbidden_characters_Then_should_throw_exception(string value) | ||
{ | ||
// Arrange | ||
var now = DateTimeOffset.Now; | ||
|
||
// Act | ||
Action act = () => Signature.From(now, value); | ||
|
||
// Assert | ||
act.Should().Throw<SignatureNotValidException>(); | ||
} | ||
} |
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
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
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
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
2 changes: 1 addition & 1 deletion
2
...ign/Fitnet.Contracts/Src/Fitnet.Contracts.Application/SignContract/SignContractCommand.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,3 +1,3 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Application.SignContract; | ||
|
||
public sealed record SignContractCommand(Guid Id, DateTimeOffset SignedAt) : ICommand<ErrorOr<Guid>>; | ||
public sealed record SignContractCommand(Guid Id, string Signature, DateTimeOffset SignedAt) : ICommand<ErrorOr<Guid>>; |
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
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
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
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
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
4 changes: 3 additions & 1 deletion
4
...-tactical-domain-driven-design/Fitnet.Contracts/Src/Fitnet.Contracts.Core/GlobalUsings.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 +1,3 @@ | ||
global using ErrorOr; | ||
global using System.Text.RegularExpressions; | ||
global using ErrorOr; | ||
global using EvolutionaryArchitecture.Fitnet.Contracts.Core.SignContract.Signatures.Exceptions; |
3 changes: 3 additions & 0 deletions
3
...rc/Fitnet.Contracts.Core/SignContract/Signatures/Exceptions/SignatureNotValidException.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,3 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.SignContract.Signatures.Exceptions; | ||
|
||
public sealed class SignatureNotValidException(string signature) : InvalidOperationException($"Signature: '{signature}' contains invalid characters."); |
25 changes: 25 additions & 0 deletions
25
...en-design/Fitnet.Contracts/Src/Fitnet.Contracts.Core/SignContract/Signatures/Signature.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,25 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.SignContract.Signatures; | ||
|
||
public sealed partial class Signature | ||
{ | ||
private static readonly Regex SignaturePattern = SignatureAllowedCharacters(); | ||
public DateTimeOffset Date { get; } | ||
public string Value { get; } | ||
|
||
private Signature(DateTimeOffset date, string value) | ||
{ | ||
Date = date; | ||
if (!SignaturePattern.IsMatch(value)) | ||
{ | ||
throw new SignatureNotValidException(value); | ||
} | ||
|
||
Value = value; | ||
} | ||
|
||
public static Signature From(DateTimeOffset signedAt, string signature) => | ||
new(signedAt, signature); | ||
|
||
[GeneratedRegex(@"^[A-Za-z\s]+$")] | ||
private static partial Regex SignatureAllowedCharacters(); | ||
} |
Oops, something went wrong.