-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
3 changed files
with
67 additions
and
3 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
37 changes: 37 additions & 0 deletions
37
Tests/FluentAssertions.Specs/Json/JsonElementAssertionsSpecs.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 System; | ||
using System.Text.Json; | ||
using Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace FluentAssertions.Specs.Json; | ||
|
||
public class JsonElementAssertionsSpecs | ||
{ | ||
public class HaveValueKind | ||
{ | ||
[Fact] | ||
public void Throws_for_unexcepected_value_kind() | ||
{ | ||
// Arrange | ||
JsonSerializerOptions options = new(); | ||
|
||
// Act | ||
Action act = () => options.Should().Serialize(42) | ||
.And.Value.Should().HaveValueKind(JsonValueKind.String, because: "Why not?"); | ||
|
||
// Assert | ||
act.Should().Throw<XunitException>() | ||
.WithMessage("Expected options to have value kind JsonValueKind.String {value: 3} because Why not?, but found JsonValueKind.Number {value: 4}"); | ||
} | ||
|
||
[Fact] | ||
public void Guards_excepected_value_kinds() | ||
{ | ||
// Arrange | ||
JsonSerializerOptions options = new(); | ||
|
||
// Act + assert | ||
options.Should().Serialize(42).And.Value.Should().HaveValueKind(JsonValueKind.Number); | ||
} | ||
} | ||
} |