-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #641 from SteveDunn/bug-639-implicit-operators-ski…
…p-normalization Implicit casts from the primitive now call the `NormalizeInput` method if one is provided
- Loading branch information
Showing
5 changed files
with
100 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization.Metadata; | ||
using SystemTextJsonSerializer = System.Text.Json.JsonSerializer; | ||
|
||
namespace ConsumerTests.BugFixTests.BugFix639; | ||
|
||
[ValueObject<string>(fromPrimitiveCasting: CastOperator.Implicit)] | ||
public partial class C_With | ||
{ | ||
private static string NormalizeInput(string input) => input.ToUpper(); | ||
} | ||
|
||
[ValueObject<string>(fromPrimitiveCasting: CastOperator.Implicit)] | ||
public partial class C_Without; | ||
|
||
/// <summary> | ||
/// Fixes bug https://github.com/SteveDunn/Vogen/issues/639 where any | ||
/// `NormalizeInput` method was not called when implicitly converting a primitive to a value object | ||
/// </summary> | ||
public class Tests | ||
{ | ||
[Fact] | ||
public void Should_call_if_present() | ||
{ | ||
C_With vo = "abc"; | ||
vo.Value.Should().Be("ABC"); | ||
} | ||
|
||
[Fact] | ||
public void Should_not_call_if_not_present() | ||
{ | ||
C_Without vo = "abc"; | ||
vo.Value.Should().Be("abc"); | ||
} | ||
} |
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