public async Task ReadMultipleObjects() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); Mocks.StringPipe outputPipe = new Mocks.StringPipe(); SimpleObject data1 = new SimpleObject() { BooleanProp = true, StringProp = "test", NumberProp = 456, }; SimpleObject data2 = new SimpleObject() { BooleanProp = false, StringProp = "test2", NumberProp = 123, }; stringPipe.BufferJsonRpcBlock(new object[] { data1, data2 }); JsonRpcPipe reader = new JsonRpcPipe(stringPipe, outputPipe); SimpleObject result = await reader.ReadBlock <SimpleObject>(); Assert.Equal(data1.StringProp, result.StringProp); Assert.Equal(data1.BooleanProp, result.BooleanProp); Assert.Equal(data1.NumberProp, result.NumberProp); result = await reader.ReadBlock <SimpleObject>(); Assert.Equal(data2.StringProp, result.StringProp); Assert.Equal(data2.BooleanProp, result.BooleanProp); Assert.Equal(data2.NumberProp, result.NumberProp); }
public async Task IgnoreCharsBeforeAndAfter() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); stringPipe.BufferInputString("abc{ \"stringprop\": \"test\", \"booleanprop\": true, \"numberprop\": 456 }123"); JsonBlockPipe reader = new JsonBlockPipe(stringPipe); SimpleObject result = await reader.ReadBlockAsync <SimpleObject>(); Assert.Equal("test", result.StringProp); Assert.True(result.BooleanProp); Assert.Equal((long)456, result.NumberProp); }
public async Task ReadSubclassRelationship() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); stringPipe.BufferInputString("{ \"stringprop\": \"test\", \"booleanprop\": true, \"numberprop\": 456, \"id\": 12345 }"); JsonBlockPipe reader = new JsonBlockPipe(stringPipe); SubObject result = await reader.ReadBlockAsync <SubObject>(); Assert.Equal("test", result.StringProp); Assert.True(result.BooleanProp); Assert.Equal((long)456, result.NumberProp); Assert.Equal((long)12345, result.Id); }
public async Task ReadParentChildRelationship() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); stringPipe.BufferInputString("{ \"parentprop\": \"parent\", \"child\": { \"stringprop\": \"test\", \"booleanprop\": true, \"numberprop\": 456 } }"); JsonBlockPipe reader = new JsonBlockPipe(stringPipe); ParentChildObject result = await reader.ReadBlockAsync <ParentChildObject>(); Assert.Equal("parent", result.ParentProp); Assert.Equal("test", result.Child.StringProp); Assert.True(result.Child.BooleanProp); Assert.Equal((long)456, result.Child.NumberProp); }
public async Task ReadSimpleObject() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); Mocks.StringPipe outputPipe = new Mocks.StringPipe(); SimpleObject data = new SimpleObject(); data.BooleanProp = true; data.StringProp = "test"; data.NumberProp = 456; stringPipe.BufferJsonRpcBlock(data); JsonRpcPipe reader = new JsonRpcPipe(stringPipe, outputPipe); SimpleObject result = await reader.ReadBlock <SimpleObject>(); Assert.Equal(data.StringProp, result.StringProp); Assert.Equal(data.BooleanProp, result.BooleanProp); Assert.Equal(data.NumberProp, result.NumberProp); }
public async Task WriteMessageWithHeaders() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); Mocks.StringPipe outputPipe = new Mocks.StringPipe(); SimpleObject data = new SimpleObject() { BooleanProp = true, StringProp = "test", NumberProp = 456, }; JsonRpcPipe reader = new JsonRpcPipe(stringPipe, outputPipe); await reader.WriteBlock <SimpleObject>(data); string output = outputPipe.OutputBuffer.ToString(); Assert.Equal("Content-Length: 57\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n{\"StringProp\":\"test\",\"BooleanProp\":true,\"NumberProp\":456}\r\n", output); }
public async Task ReadMessageWithOptionalHeaders() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); Mocks.StringPipe outputPipe = new Mocks.StringPipe(); SimpleObject data = new SimpleObject() { BooleanProp = true, StringProp = "test", NumberProp = 456, }; stringPipe.BufferJsonRpcBlock(data, type: "test"); JsonRpcPipe reader = new JsonRpcPipe(stringPipe, outputPipe); SimpleObject result = await reader.ReadBlock <SimpleObject>(); Assert.Equal(data.StringProp, result.StringProp); Assert.Equal(data.BooleanProp, result.BooleanProp); Assert.Equal(data.NumberProp, result.NumberProp); }
public async Task ReadSubclassRelationship() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); Mocks.StringPipe outputPipe = new Mocks.StringPipe(); SubObject data = new SubObject() { StringProp = "test", BooleanProp = true, NumberProp = 456, Id = 12345 }; stringPipe.BufferJsonRpcBlock(data); JsonRpcPipe reader = new JsonRpcPipe(stringPipe, outputPipe); SubObject result = await reader.ReadBlock <SubObject>(); Assert.Equal(data.StringProp, result.StringProp); Assert.Equal(data.BooleanProp, result.BooleanProp); Assert.Equal(data.NumberProp, result.NumberProp); Assert.Equal(data.Id, result.Id); }
public async Task ReadParentChildRelationship() { Mocks.StringPipe stringPipe = new Mocks.StringPipe(); Mocks.StringPipe outputPipe = new Mocks.StringPipe(); ParentChildObject data = new ParentChildObject(); data.ParentProp = "parent"; data.Child = new SimpleObject() { StringProp = "test", BooleanProp = true, NumberProp = 456 }; stringPipe.BufferJsonRpcBlock(data); JsonRpcPipe reader = new JsonRpcPipe(stringPipe, outputPipe); ParentChildObject result = await reader.ReadBlock <ParentChildObject>(); Assert.Equal(data.ParentProp, result.ParentProp); Assert.NotNull(data.Child); Assert.Equal(data.Child.StringProp, result.Child.StringProp); Assert.Equal(data.Child.BooleanProp, result.Child.BooleanProp); Assert.Equal(data.Child.NumberProp, result.Child.NumberProp); }