< Summary

Class:Azure.Core.TestFramework.MockResponse
Assembly:Azure.Core.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\MockResponse.cs
Covered lines:30
Uncovered lines:1
Coverable lines:31
Total lines:100
Line coverage:96.7% (30 of 31)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_Status()-100%100%
get_ReasonPhrase()-100%100%
get_ContentStream()-100%100%
get_ClientRequestId()-100%100%
get_IsDisposed()-0%100%
SetContent(...)-100%100%
SetContent(...)-100%100%
AddHeader(...)-100%100%
TryGetHeader(...)-100%100%
TryGetHeaderValues(...)-100%100%
ContainsHeader(...)-100%100%
EnumerateHeaders()-100%100%
JoinHeaderValue(...)-100%100%
Dispose()-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.IO;
 7using System.Linq;
 8using System.Text;
 9
 10namespace Azure.Core.TestFramework
 11{
 12    public class MockResponse : Response
 13    {
 32953314        private readonly Dictionary<string, List<string>> _headers = new Dictionary<string, List<string>>(StringComparer
 15
 32953316        public MockResponse(int status, string reasonPhrase = null)
 17        {
 32953318            Status = status;
 32953319            ReasonPhrase = reasonPhrase;
 32953320        }
 21
 97120122        public override int Status { get; }
 23
 375024        public override string ReasonPhrase { get; }
 25
 137508726        public override Stream ContentStream { get; set; }
 27
 139028        public override string ClientRequestId { get; set; }
 29
 030        public bool IsDisposed { get; private set; }
 31
 32        public void SetContent(byte[] content)
 33        {
 58834            ContentStream = new MemoryStream(content);
 58835        }
 36
 37        public void SetContent(string content)
 38        {
 46039            SetContent(Encoding.UTF8.GetBytes(content));
 46040        }
 41
 42        public void AddHeader(HttpHeader header)
 43        {
 487987344            if (!_headers.TryGetValue(header.Name, out List<string> values))
 45            {
 460633946                _headers[header.Name] = values = new List<string>();
 47            }
 48
 487987349            values.Add(header.Value);
 487987350        }
 51
 52#if HAS_INTERNALS_VISIBLE_CORE
 53        internal
 54#endif
 55        protected override bool TryGetHeader(string name, out string value)
 56        {
 75353657            if (_headers.TryGetValue(name, out List<string> values))
 58            {
 20697259                value = JoinHeaderValue(values);
 20697260                return true;
 61            }
 62
 54656463            value = null;
 54656464            return false;
 65        }
 66
 67#if HAS_INTERNALS_VISIBLE_CORE
 68        internal
 69#endif
 70        protected override bool TryGetHeaderValues(string name, out IEnumerable<string> values)
 71        {
 5104072            var result = _headers.TryGetValue(name, out List<string> valuesList);
 5104073            values = valuesList;
 5104074            return result;
 75        }
 76
 77#if HAS_INTERNALS_VISIBLE_CORE
 78        internal
 79#endif
 80        protected override bool ContainsHeader(string name)
 81        {
 1136482            return TryGetHeaderValues(name, out _);
 83        }
 84
 85#if HAS_INTERNALS_VISIBLE_CORE
 86        internal
 87#endif
 15352888        protected override IEnumerable<HttpHeader> EnumerateHeaders() => _headers.Select(h => new HttpHeader(h.Key, Join
 89
 90        private static string JoinHeaderValue(IEnumerable<string> values)
 91        {
 35037292            return string.Join(",", values);
 93        }
 94
 95        public override void Dispose()
 96        {
 32158697            IsDisposed = true;
 32158698        }
 99    }
 100}