Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Sep 5, 2022
1 parent 64d1e08 commit 8efe539
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion tests/FsCodec.SystemTextJson.Tests/CodecTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ let [<Property>] roundtrips value =

let des = serdes.Deserialize<Envelope> ser
let wrapped = FsCodec.Core.TimelineEvent<JsonElement>.Create(-1L, eventType, des.d)
test <@ wrapped.EventId <> System.Guid.Empty
&& (let d = System.DateTimeOffset.UtcNow - wrapped.Timestamp
abs d.TotalMinutes < 1) @>
let decoded = eventCodec.TryDecode wrapped |> ValueOption.get

let expected =
match value with
| AO ({ opt = Some null } as v) -> AO { v with opt = None }
Expand All @@ -69,3 +71,22 @@ let [<Property>] roundtrips value =
// Also validate the adapters work when put in series (NewtonsoftJson tests are responsible for covering the individual hops)
let decodedMultiHop = multiHopCodec.TryDecode wrapped |> ValueOption.get
test <@ expected = decodedMultiHop @>

let [<Xunit.Fact>] ``EventData.Create basics`` () =
let e = FsCodec.Core.EventData.Create("et", "data")

test <@ e.EventId <> System.Guid.Empty
&& e.EventType = "et"
&& e.Data = "data"
&& (let d = System.DateTimeOffset.UtcNow - e.Timestamp
abs d.TotalMinutes < 1) @>

let [<Xunit.Fact>] ``TimelineEvent.Create basics`` () =
let e = FsCodec.Core.TimelineEvent.Create(42, "et", "data")

test <@ e.EventId = System.Guid.Empty
&& not e.IsUnfold
&& e.EventType = "et"
&& e.Data = "data"
&& (let d = System.DateTimeOffset.UtcNow - e.Timestamp
abs d.TotalMinutes < 1) @>
2 changes: 1 addition & 1 deletion tests/FsCodec.SystemTextJson.Tests/PicklerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ let [<Fact>] ``Global GuidConverter roundtrips`` () =
// With the converter, things roundtrip either way
for result in [defaultHandlingHasDashes; resNoDashes] do
let des = serdesWithConverter.Deserialize result
test <@ value= des @>
test <@ value = des @>

0 comments on commit 8efe539

Please sign in to comment.