< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.XmlElementElement
Assembly: CoreWCF.ConfigurationManager
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/XmlElementElement.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 39
Coverable lines: 39
Total lines: 100
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
.ctor(...)100%110%
Copy(...)0%660%
DeserializeElement(...)100%110%
DeserializeElementCore(...)100%110%
ResetInternal(...)100%110%
SerializeToXmlElement(...)0%880%
PostDeserialize()100%110%
Validate()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/XmlElementElement.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.Configuration;
 6using System.Xml;
 7
 8namespace CoreWCF.Configuration
 9{
 10    public sealed class XmlElementElement : ConfigurationElement
 11    {
 012        public XmlElementElement()
 13        {
 014        }
 15
 016        public XmlElementElement(XmlElement element) : this()
 17        {
 018            XmlElement = element;
 019        }
 20
 21        public void Copy(XmlElementElement source)
 22        {
 023            if (IsReadOnly())
 24            {
 025                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.Format(SR.
 26            }
 027            if (null == source)
 28            {
 029                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(source));
 30            }
 31
 032            if (null != source.XmlElement)
 33            {
 034                XmlElement = (XmlElement)source.XmlElement.Clone();
 35            }
 036        }
 37
 38        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
 39        {
 040            DeserializeElementCore(reader);
 041        }
 42
 43        private void DeserializeElementCore(XmlReader reader)
 44        {
 045            XmlDocument doc = new XmlDocument();
 046            XmlElement = (XmlElement)doc.ReadNode(reader);
 047        }
 48
 49        internal void ResetInternal(XmlElementElement element)
 50        {
 051            Reset(element);
 052        }
 53
 54        protected override bool SerializeToXmlElement(XmlWriter writer, string elementName)
 55        {
 056            bool dataToWrite = XmlElement != null;
 057            if (dataToWrite && writer != null)
 58            {
 059                if (!string.Equals(elementName, ConfigurationStrings.XmlElement, StringComparison.Ordinal))
 60                {
 061                    writer.WriteStartElement(elementName);
 62                }
 63
 064                using (XmlNodeReader reader = new XmlNodeReader(XmlElement))
 65                {
 066                    writer.WriteNode(reader, false);
 067                }
 68
 069                if (!string.Equals(elementName, ConfigurationStrings.XmlElement, StringComparison.Ordinal))
 70                {
 071                    writer.WriteEndElement();
 72                }
 73            }
 074            return dataToWrite;
 75        }
 76
 77        protected override void PostDeserialize()
 78        {
 079            Validate();
 080            base.PostDeserialize();
 081        }
 82
 83        private void Validate()
 84        {
 085            if (XmlElement == null)
 86            {
 087                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.Format(SR.
 088                    ElementInformation.Source,
 089                    ElementInformation.LineNumber));
 90            }
 091        }
 92
 93        [ConfigurationProperty(ConfigurationStrings.XmlElement, DefaultValue = null, Options = ConfigurationPropertyOpti
 94        public XmlElement XmlElement
 95        {
 096            get { return (XmlElement)base[ConfigurationStrings.XmlElement]; }
 097            set { base[ConfigurationStrings.XmlElement] = value; }
 98        }
 99    }
 100}