-
Notifications
You must be signed in to change notification settings - Fork 48
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 #628 from SteveDunn/bug-stj-allows-nulls
Bug stj allows nulls
- Loading branch information
Showing
1,996 changed files
with
7,827 additions
and
5 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
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
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
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
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,52 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization.Metadata; | ||
using SystemTextJsonSerializer = System.Text.Json.JsonSerializer; | ||
|
||
namespace ConsumerTests.BugFixTests.BugFix624; | ||
|
||
[ValueObject<string>(conversions: Conversions.SystemTextJson)] | ||
public partial class NonStrictReferenceVo; | ||
|
||
[ValueObject<string>(conversions: Conversions.SystemTextJson, deserializationStrictness: DeserializationStrictness.DisallowNulls)] | ||
public partial class StrictReferenceVo; | ||
|
||
[ValueObject(conversions: Conversions.SystemTextJson)] | ||
public partial struct ValueVo; | ||
|
||
public class StrictContainer | ||
{ | ||
// ReSharper disable once NullableWarningSuppressionIsUsed | ||
public StrictReferenceVo Rvo { get; set; } = null!; | ||
} | ||
|
||
public class NonStrictContainer | ||
{ | ||
// ReSharper disable once NullableWarningSuppressionIsUsed | ||
public NonStrictReferenceVo Rvo { get; set; } = null!; | ||
} | ||
|
||
/// <summary> | ||
/// Fixes bug https://github.com/SteveDunn/Vogen/issues/624 where STJ | ||
/// deserialization would allow a null value object if it was a reference type | ||
/// </summary> | ||
public class Tests | ||
{ | ||
[Fact] | ||
public void Should_throw_if_null() | ||
{ | ||
string json = $$"""{"Rvo":null}"""; | ||
|
||
Action a = () => JsonSerializer.Deserialize<StrictContainer>(json); | ||
a.Should().ThrowExactly<ValueObjectValidationException>().WithMessage("Cannot create a value object with null."); | ||
} | ||
|
||
[Fact] | ||
public void Can_override_null_behaviour_to_not_throw() | ||
{ | ||
string json = $$"""{"Rvo":null}"""; | ||
|
||
var x = JsonSerializer.Deserialize<NonStrictContainer>(json)!; | ||
x.Rvo.Should().BeNull(); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
tests/SnapshotTests/SystemTextJsonGeneration/DeserializationStrictnessTests.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 System.Threading.Tasks; | ||
using VerifyXunit; | ||
using Vogen; | ||
|
||
namespace SnapshotTests.SystemTextJsonGeneration; | ||
|
||
[UsesVerify] | ||
public class DeserializationStrictnessTests | ||
{ | ||
[Fact] | ||
public Task Reference_value_objects_allow_nulls_by_default() | ||
{ | ||
var source = """ | ||
using Vogen; | ||
namespace Whatever; | ||
[ValueObject] | ||
public partial class ReferenceVo; | ||
"""; | ||
|
||
return new SnapshotRunner<ValueObjectGenerator>() | ||
.WithSource(source) | ||
.RunOnAllFrameworks(); | ||
} | ||
|
||
[Fact] | ||
public Task Can_disallow_nulls_for_reference_value_objects() | ||
{ | ||
var source = """ | ||
using Vogen; | ||
namespace Whatever; | ||
[ValueObject(deserializationStrictness: DeserializationStrictness.DisallowNulls)] | ||
public partial class ReferenceVo; | ||
"""; | ||
|
||
return new SnapshotRunner<ValueObjectGenerator>() | ||
.WithSource(source) | ||
.RunOnAllFrameworks(); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.