Allow JSON parsing to happen in an extension method (#63)

This commit is contained in:
Patrick Stevens
2024-01-08 00:50:33 +00:00
committed by GitHub
parent ad2eeaaa4f
commit 948fbfbc84
12 changed files with 284 additions and 37 deletions

View File

@@ -0,0 +1,26 @@
namespace WoofWare.Myriad.Plugins.Test
open System
open System.Text.Json.Nodes
open ConsumePlugin
open NUnit.Framework
open FsUnitTyped
[<TestFixture>]
module TestExtensionMethod =
[<Test>]
let ``Parse via extension method`` () =
let json =
"""{"tinker": "job", "tailor": 3, "soldier": "https://example.com", "sailor": 3.1}"""
|> JsonNode.Parse
let expected =
{
Tinker = "job"
Tailor = 3
Soldier = Uri "https://example.com"
Sailor = 3.1
}
ToGetExtensionMethod.jsonParse json |> shouldEqual expected

View File

@@ -32,3 +32,18 @@ module TestJsonParse =
let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
actual |> shouldEqual expected
[<Test>]
let ``Inner example`` () =
let s =
"""{
"something": "oh hi"
}"""
let expected =
{
Thing = "oh hi"
}
let actual = s |> JsonNode.Parse |> InnerType.jsonParse
actual |> shouldEqual expected