< Summary

Class:Azure.Core.Utf8JsonRequestContent
Assembly:Azure.DigitalTwins.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\Utf8JsonRequestContent.cs
Covered lines:14
Uncovered lines:3
Coverable lines:17
Total lines:51
Line coverage:82.3% (14 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()-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
 11218        public Utf8JsonWriter JsonWriter { get; }
 19
 1620        public Utf8JsonRequestContent()
 21        {
 1622            _stream = new MemoryStream();
 1623            _content = Create(_stream);
 1624            JsonWriter = new Utf8JsonWriter(_stream);
 1625        }
 26
 27        public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
 28        {
 829            await JsonWriter.FlushAsync(cancellation).ConfigureAwait(false);
 830            await _content.WriteToAsync(stream, cancellation).ConfigureAwait(false);
 831        }
 32
 33        public override void WriteTo(Stream stream, CancellationToken cancellation)
 34        {
 2435            JsonWriter.Flush();
 2436            _content.WriteTo(stream, cancellation);
 2437        }
 38
 39        public override bool TryComputeLength(out long length)
 40        {
 3241            length = JsonWriter.BytesCommitted + JsonWriter.BytesPending;
 3242            return true;
 43        }
 44
 45        public override void Dispose()
 46        {
 047            JsonWriter.Dispose();
 048            _content.Dispose();
 049        }
 50    }
 51}