Exemple #1
0
        public async void CoreDeserializeResponseDataAsyncFromStreamWhenJsonStreamIsNull()
        {
            var jsonRpcSerializer = new JsonRpcSerializer();

            await Assert.ThrowsAsync <ArgumentNullException>(() =>
                                                             jsonRpcSerializer.DeserializeResponseDataAsync((Stream)null));
        }
Exemple #2
0
        public async void CoreDeserializeResponseDataAsyncFromStreamWhenJsonStreamIsEmpty()
        {
            var jsonRpcSerializer = new JsonRpcSerializer();

            var exception = await Assert.ThrowsAsync <JsonRpcException>(() =>
                                                                        jsonRpcSerializer.DeserializeResponseDataAsync(Stream.Null));

            Assert.Equal(JsonRpcErrorCodes.InvalidJson, exception.ErrorCode);
        }
Exemple #3
0
        public async void CoreDeserializeResponseDatatAsyncFromStream()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_core_res.json");
            var jsonRpcSerializer = new JsonRpcSerializer();

            jsonRpcSerializer.DynamicResponseBindings[0L] = new JsonRpcResponseContract(typeof(long));

            using (var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonSample)))
            {
                var jsonRpcData = await jsonRpcSerializer.DeserializeResponseDataAsync(jsonStream);

                Assert.False(jsonRpcData.IsBatch);

                var jsonRpcItem = jsonRpcData.Item;

                Assert.True(jsonRpcItem.IsValid);

                var jsonRpcMessage = jsonRpcItem.Message;

                Assert.Equal(0L, jsonRpcMessage.Id);
                Assert.True(jsonRpcMessage.Success);
                Assert.Equal(0L, jsonRpcMessage.Result);
            }
        }