< Summary

Class:Azure.Core.TestFramework.AsyncValidatingStream
Assembly:Azure.Core.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\AsyncValidatingStream.cs
Covered lines:20
Uncovered lines:14
Coverable lines:34
Total lines:98
Line coverage:58.8% (20 of 34)
Covered branches:4
Total branches:6
Branch coverage:66.6% (4 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
Flush()-0%100%
FlushAsync(...)-0%100%
Validate(...)-100%66.67%
Read(...)-100%100%
ReadAsync(...)-100%100%
Seek(...)-100%100%
SetLength(...)-0%100%
Write(...)-0%100%
WriteAsync(...)-0%100%
CopyToAsync(...)-100%100%
Close()-100%100%
get_CanRead()-100%100%
get_CanSeek()-100%100%
get_CanWrite()-0%100%
get_Length()-100%100%
get_Position()-100%100%
set_Position(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\AsyncValidatingStream.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.IO;
 6using System.Threading;
 7using System.Threading.Tasks;
 8
 9namespace Azure.Core.TestFramework
 10{
 11    internal class AsyncValidatingStream : Stream
 12    {
 13        private readonly bool _isAsync;
 14
 15        private readonly Stream _innerStream;
 16
 14017        public AsyncValidatingStream(bool isAsync, Stream innerStream)
 18        {
 14019            _isAsync = isAsync;
 14020            _innerStream = innerStream;
 14021        }
 22
 23        public override void Flush()
 24        {
 025            Validate(false);
 026            _innerStream.Flush();
 027        }
 28
 29        public override Task FlushAsync(CancellationToken cancellationToken)
 30        {
 031            Validate(true);
 032            return _innerStream.FlushAsync(cancellationToken);
 33        }
 34
 35        private void Validate(bool isAsync)
 36        {
 26437            if (isAsync != _isAsync)
 38            {
 239                throw new InvalidOperationException("All stream calls were expected to be " + (_isAsync ? "async" : "syn
 40            }
 26241        }
 42
 43        public override int Read(byte[] buffer, int offset, int count)
 44        {
 13245            Validate(false);
 13246            return _innerStream.Read(buffer, offset, count);
 47        }
 48
 49        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = 
 50        {
 12251            Validate(true);
 12052            return _innerStream.ReadAsync(buffer, offset, count, cancellationToken);
 53        }
 54
 55        public override long Seek(long offset, SeekOrigin origin)
 56        {
 2057            return _innerStream.Seek(offset, origin);
 58        }
 59
 60        public override void SetLength(long value)
 61        {
 062            _innerStream.SetLength(value);
 063        }
 64
 65        public override void Write(byte[] buffer, int offset, int count)
 66        {
 067            Validate(false);
 068            _innerStream.Write(buffer, offset, count);
 069        }
 70
 71        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = new 
 72        {
 073            Validate(true);
 074            return _innerStream.WriteAsync(buffer, offset, count, cancellationToken);
 75        }
 76
 77        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
 78        {
 1079            Validate(true);
 1080            return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken);
 81        }
 82
 83        public override void Close()
 84        {
 4685            _innerStream.Close();
 4686        }
 87
 1088        public override bool CanRead => _innerStream.CanRead;
 9089        public override bool CanSeek => _innerStream.CanSeek;
 090        public override bool CanWrite => _innerStream.CanWrite;
 4091        public override long Length => _innerStream.Length;
 92        public override long Position
 93        {
 1094            get => _innerStream.Position;
 095            set => _innerStream.Position = value;
 96        }
 97    }
 98}