Skip to content

Commit

Permalink
test: Improve assertion on an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Jul 23, 2023
1 parent 8b32663 commit c63b207
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tests/FSharp.SystemTextJson.Tests/Test.Record.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ module NonStruct =
[<Fact>]
let ``deserialize empty record with ignore-null-values on`` () =
let options =
JsonSerializerOptions(DefaultIgnoreCondition = Serialization.JsonIgnoreCondition.WhenWritingNull)
try
JsonSerializer.Deserialize<A>("{}", options) |> ignore
with
| :? System.NullReferenceException -> failwith "Unexpected NRE."
| ex when ex.Message.Contains("Missing field for record type") -> () // It's expected to fail since the record requires its fields to be initialized.
JsonSerializerOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)
let ex =
Assert.Throws<JsonException>(fun () -> JsonSerializer.Deserialize<A>("{}", options) |> ignore)
Assert.Contains("Missing field for record type", ex.Message)

[<Fact>]
let ``serialize via explicit converter`` () =
Expand Down

0 comments on commit c63b207

Please sign in to comment.