public void ReadIntOptional()
    {
        JsonDocument jdoc = JsonDocument.Parse("{\"foo\":1234}");

        // Test success case.
        int val = -1;

        JsonReadOptionalUtils.ReadIntOptional(jdoc.RootElement, "foo", x => val = x);
        Assert.Equal(1234, val);

        // Test missing optional.
        val = -1;
        JsonReadOptionalUtils.ReadIntOptional(jdoc.RootElement, "bar", x => val = x);
        Assert.Equal(-1, val);

        // Test invalid value.
        jdoc = JsonDocument.Parse("{\"foo\":\"abc\"}");
        Assert.Throws <InvalidOperationException>(() => JsonReadOptionalUtils.ReadIntOptional(jdoc.RootElement, "foo", x => val = x));
    }
        public void ReadIntOptional()
        {
            JObject jobj = JObject.Parse("{'foo':'1234'}");

            // Test success case.
            int val = -1;

            JsonReadOptionalUtils.ReadIntOptional(jobj, "foo", x => val = x);
            Assert.AreEqual(1234, val);

            // Test missing optional.
            val = -1;
            JsonReadOptionalUtils.ReadIntOptional(jobj, "bar", x => val = x);
            Assert.AreEqual(-1, val);

            // Test invalid value.
            jobj = JObject.Parse("{'foo':'abc'}");
            Assert.ThrowsException <FormatException>(() => JsonReadOptionalUtils.ReadIntOptional(jobj, "foo", x => val = x));
        }