< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_JsonWriter()-0%100%
.ctor()-0%100%
WriteToAsync()-0%100%
WriteTo(...)-0%100%
TryComputeLength(...)-0%100%
Dispose()-0%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
 018        public Utf8JsonWriter JsonWriter { get; }
 19
 020        public Utf8JsonRequestContent()
 21        {
 022            _stream = new MemoryStream();
 023            _content = Create(_stream);
 024            JsonWriter = new Utf8JsonWriter(_stream);
 025        }
 26
 27        public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
 28        {
 029            await JsonWriter.FlushAsync(cancellation).ConfigureAwait(false);
 030            await _content.WriteToAsync(stream, cancellation).ConfigureAwait(false);
 031        }
 32
 33        public override void WriteTo(Stream stream, CancellationToken cancellation)
 34        {
 035            JsonWriter.Flush();
 036            _content.WriteTo(stream, cancellation);
 037        }
 38
 39        public override bool TryComputeLength(out long length)
 40        {
 041            length = JsonWriter.BytesCommitted + JsonWriter.BytesPending;
 042            return true;
 43        }
 44
 45        public override void Dispose()
 46        {
 047            JsonWriter.Dispose();
 048            _content.Dispose();
 049        }
 50    }
 51}