XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
UTF-8
#pragma warning disable CS0618
using XFEExtension.NetCore.XFETransform.JsonConverter;

namespace XFEExtension.NetCore.Test.Json;

public class XFEJsonCompatibilityTests
{
    [Fact]
    public void QueryableJsonNode_UsesLazyEngineAndPreservesNavigation()
    {
        QueryableJsonNode node = "{\"status\":500,\"data\":{\"name\":\"ok\"},\"values\":[1,2,3]}";

        Assert.Equal("500", node["status"]!.Value);
        Assert.Equal("ok", (node > "data" > "name")!.Value);
        Assert.Equal(new[] { 1, 2, 3 }, node["values"]!.GetList<int>());
    }

    [Fact]
    public void QueryableJsonNode_PreservesPackageOperations()
    {
        QueryableJsonNode node = "{\"code\":0,\"message\":\"ok\",\"items\":[{\"id\":1,\"name\":\"one\",\"trash\":true},{\"id\":2,\"name\":\"two\"}]}";

        var objectPackage = node["package:object", "code", "message"]!.PackageObject();
        Assert.Equal("0", objectPackage["code"].Value);
        Assert.Equal("ok", objectPackage["message"].Value);

        var listPackage = node["items"]!["package:list", "id", "name"]!.PackageInListObject();
        Assert.Equal(2, listPackage.Count);
        Assert.Equal("two", listPackage[1]["name"].Value);
    }

    [Fact]
    public void JsonNodeConverter_StillProvidesExplicitEagerTree()
    {
        var tree = new JsonNodeConverter("{\"data\":{\"value\":7}}").ConvertToJsonNode();
        var root = Assert.IsType<JsonComplexPropertyNode>(tree);
        var data = Assert.IsType<JsonComplexPropertyNode>(Assert.Single(root.DescendingNodes));
        var value = Assert.IsType<JsonPropertyNode>(Assert.Single(data.DescendingNodes));

        Assert.Equal("data", data.PropertyName);
        Assert.Equal("value", value.PropertyName);
        Assert.Equal("7", value.Value);
    }
}
#pragma warning restore CS0618