< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ContentOnlyMessage
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/ContentOnlyMessage.cs
Line coverage
66%
Covered lines: 10
Uncovered lines: 5
Coverable lines: 15
Total lines: 109
Line coverage: 66.6%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
OnBodyToString(...)100%110%
CreateMessageDisposedException()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/ContentOnlyMessage.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Xml;
 6using CoreWCF.Diagnostics;
 7
 8// TODO: This is duplicated from Primitives. Either move to common code and include in both places or add to contract. I
 9
 10namespace CoreWCF.Channels
 11{
 12    /// <summary>
 13    /// Base class for non-SOAP messages
 14    /// </summary>
 15    internal abstract class ContentOnlyMessage : Message
 16    {
 17        private readonly MessageHeaders _headers;
 18        private MessageProperties _properties;
 19
 13520        protected ContentOnlyMessage()
 21        {
 13522            _headers = new MessageHeaders(MessageVersion.None);
 13523        }
 24
 25        public override MessageHeaders Headers
 26        {
 27            get
 28            {
 62129                if (IsDisposed)
 30                {
 031                    throw TraceUtility.ThrowHelperError(CreateMessageDisposedException(), this);
 32                }
 33
 62134                return _headers;
 35            }
 36        }
 37
 38        public override MessageProperties Properties
 39        {
 40            get
 41            {
 86942                if (IsDisposed)
 43                {
 044                    throw TraceUtility.ThrowHelperError(CreateMessageDisposedException(), this);
 45                }
 46
 86947                if (_properties == null)
 48                {
 13549                    _properties = new MessageProperties();
 50                }
 51
 86952                return _properties;
 53            }
 54        }
 55
 56        public override MessageVersion Version
 57        {
 58            get
 59            {
 67560                return _headers.MessageVersion;
 61            }
 62        }
 63
 64        protected override void OnBodyToString(XmlDictionaryWriter writer)
 65        {
 066            OnWriteBodyContents(writer);
 067        }
 68
 69        internal Exception CreateMessageDisposedException()
 70        {
 071            return new ObjectDisposedException("", SR.MessageClosed);
 72        }
 73    }
 74
 75    internal class StringMessage : ContentOnlyMessage
 76    {
 77        private readonly string _data;
 78
 79        public StringMessage(string data)
 80            : base()
 81        {
 82            _data = data;
 83        }
 84
 85        public override bool IsEmpty
 86        {
 87            get
 88            {
 89                return string.IsNullOrEmpty(_data);
 90            }
 91        }
 92
 93        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 94        {
 95            if (_data != null && _data.Length > 0)
 96            {
 97                writer.WriteElementString("BODY", _data);
 98            }
 99        }
 100    }
 101
 102    internal class NullMessage : StringMessage
 103    {
 104        public NullMessage()
 105            : base(string.Empty)
 106        {
 107        }
 108    }
 109}