< Summary

Class:Azure.Core.Utf8JsonRequestContent
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\Utf8JsonRequestContent.cs
Covered lines:17
Uncovered lines:0
Coverable lines:17
Total lines:51
Line coverage:100% (17 of 17)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_JsonWriter()-100%100%
.ctor()-100%100%
WriteToAsync()-100%100%
WriteTo(...)-100%100%
TryComputeLength(...)-100%100%
Dispose()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\Utf8JsonRequestContent.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4#nullable enable
 5
 6using System.IO;
 7using System.Text.Json;
 8using System.Threading;
 9using System.Threading.Tasks;
 10
 11namespace Azure.Core
 12{
 13    internal class Utf8JsonRequestContent: RequestContent
 14    {
 15        private readonly MemoryStream _stream;
 16        private readonly RequestContent _content;
 17
 196518        public Utf8JsonWriter JsonWriter { get; }
 19
 28120        public Utf8JsonRequestContent()
 21        {
 28122            _stream = new MemoryStream();
 28123            _content = Create(_stream);
 28124            JsonWriter = new Utf8JsonWriter(_stream);
 28125        }
 26
 27        public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
 28        {
 14829            await JsonWriter.FlushAsync(cancellation).ConfigureAwait(false);
 14830            await _content.WriteToAsync(stream, cancellation).ConfigureAwait(false);
 14831        }
 32
 33        public override void WriteTo(Stream stream, CancellationToken cancellation)
 34        {
 41335            JsonWriter.Flush();
 41336            _content.WriteTo(stream, cancellation);
 41337        }
 38
 39        public override bool TryComputeLength(out long length)
 40        {
 56141            length = JsonWriter.BytesCommitted + JsonWriter.BytesPending;
 56142            return true;
 43        }
 44
 45        public override void Dispose()
 46        {
 147            JsonWriter.Dispose();
 148            _content.Dispose();
 149        }
 50    }
 51}