Beispiel #1
0
        public async Task LoadJsonAsync_InvalidJsonTest()
        {
            var body = Encoding.UTF8.GetBytes("### Invalid JSON ###");

            using var bodyStream = new MemoryStream(body);
            using var response   = new HttpResponseMessage();
            response.Content     = new StreamContent(bodyStream);

            using var lazyJson = new LazyJson <string>(response);

            // この時点ではまだレスポンスボディは読まれない
            Assert.Equal(0, bodyStream.Position);

            var exception = await Assert.ThrowsAnyAsync <WebApiException>(() => lazyJson.LoadJsonAsync())
                            .ConfigureAwait(false);

            Assert.IsType <SerializationException>(exception.InnerException);
        }
Beispiel #2
0
        public async Task LoadJsonAsync_Test()
        {
            var body = Encoding.UTF8.GetBytes("\"hogehoge\"");

            using var bodyStream = new MemoryStream(body);
            using var response   = new HttpResponseMessage();
            response.Content     = new StreamContent(bodyStream);

            using var lazyJson = new LazyJson <string>(response);

            // この時点ではまだレスポンスボディは読まれない
            Assert.Equal(0, bodyStream.Position);

            var result = await lazyJson.LoadJsonAsync()
                         .ConfigureAwait(false);

            Assert.Equal("hogehoge", result);
        }