コード例 #1
0
    public void TopLevelPropertiesCanBeSerializedError()
    {
        IJsonRpcMessageFactory factory = this.formatter;
        var message = factory.CreateErrorMessage();

        Assert.NotNull(message);

        message.Error = new JsonRpcError.ErrorDetail()
        {
            Message = "test"
        };
        Assert.True(message.TrySetTopLevelProperty("testProperty", "testValue"));
        Assert.True(message.TrySetTopLevelProperty("objectProperty", new CustomType()
        {
            Age = 25
        }));

        var roundTripMessage = this.Roundtrip(message);

        Assert.True(roundTripMessage.TryGetTopLevelProperty("testProperty", out string?value));
        Assert.Equal("testValue", value);

        Assert.True(roundTripMessage.TryGetTopLevelProperty("objectProperty", out CustomType? customObject));
        Assert.Equal(25, customObject?.Age);
    }
コード例 #2
0
    public void TopLevelPropertiesWithNullValue()
    {
        IJsonRpcMessageFactory factory = this.formatter;
        var requestMessage             = factory.CreateRequestMessage();

        Assert.NotNull(requestMessage);

        requestMessage.Method = "test";
        Assert.True(requestMessage.TrySetTopLevelProperty <string?>("testProperty", null));

        var roundTripMessage = this.Roundtrip(requestMessage);

        Assert.True(roundTripMessage.TryGetTopLevelProperty("testProperty", out string?value));
        Assert.Null(value);
    }
コード例 #3
0
    public void TopLevelPropertiesCanBeSerializedRequest()
    {
        IJsonRpcMessageFactory factory = this.formatter;
        var requestMessage             = factory.CreateRequestMessage();

        Assert.NotNull(requestMessage);

        requestMessage.Method = "test";
        Assert.True(requestMessage.TrySetTopLevelProperty("testProperty", "testValue"));
        Assert.True(requestMessage.TrySetTopLevelProperty("objectProperty", new CustomType()
        {
            Age = 25
        }));

        var roundTripMessage = this.Roundtrip(requestMessage);

        Assert.True(roundTripMessage.TryGetTopLevelProperty("testProperty", out string?value));
        Assert.Equal("testValue", value);

        Assert.True(roundTripMessage.TryGetTopLevelProperty("objectProperty", out CustomType? customObject));
        Assert.Equal(25, customObject?.Age);
    }