< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.MustUnderstandSoapException
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/MustUnderstandSoapException.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 32
Coverable lines: 32
Total lines: 83
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
ProvideFault(...)0%220%
AddNotUnderstoodHeaders(...)0%220%
.ctor(...)100%110%
OnWriteStartHeader(...)100%110%
OnWriteHeaderContents(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/MustUnderstandSoapException.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.Collections.ObjectModel;
 5using System.Globalization;
 6using System.Xml;
 7using CoreWCF.Channels;
 8
 9namespace CoreWCF
 10{
 11    //[Serializable]
 12    internal class MustUnderstandSoapException : CommunicationException
 13    {
 014        public MustUnderstandSoapException(Collection<MessageHeaderInfo> notUnderstoodHeaders, EnvelopeVersion envelopeV
 15        {
 016            NotUnderstoodHeaders = notUnderstoodHeaders;
 017            EnvelopeVersion = envelopeVersion;
 018        }
 19
 020        public Collection<MessageHeaderInfo> NotUnderstoodHeaders { get; }
 021        public EnvelopeVersion EnvelopeVersion { get; }
 22
 23        internal Message ProvideFault(MessageVersion messageVersion)
 24        {
 025            string name = NotUnderstoodHeaders[0].Name;
 026            string ns = NotUnderstoodHeaders[0].Namespace;
 027            FaultCode code = new FaultCode(MessageStrings.MustUnderstandFault, EnvelopeVersion.Namespace);
 028            FaultReason reason = new FaultReason(SR.Format(SR.SFxHeaderNotUnderstood, name, ns), CultureInfo.CurrentCult
 029            MessageFault fault = MessageFault.CreateFault(code, reason);
 030            string faultAction = messageVersion.Addressing.DefaultFaultAction;
 031            Message message = Channels.Message.CreateMessage(messageVersion, fault, faultAction);
 032            if (EnvelopeVersion == EnvelopeVersion.Soap12)
 33            {
 034                AddNotUnderstoodHeaders(message.Headers);
 35            }
 036            return message;
 37        }
 38
 39        private void AddNotUnderstoodHeaders(MessageHeaders headers)
 40        {
 041            for (int i = 0; i < NotUnderstoodHeaders.Count; ++i)
 42            {
 043                headers.Add(new NotUnderstoodHeader(NotUnderstoodHeaders[i].Name, NotUnderstoodHeaders[i].Namespace));
 44            }
 045        }
 46
 47        private class NotUnderstoodHeader : MessageHeader
 48        {
 49            private readonly string _notUnderstoodName;
 50            private readonly string _notUnderstoodNs;
 51
 052            public NotUnderstoodHeader(string name, string ns)
 53            {
 054                _notUnderstoodName = name;
 055                _notUnderstoodNs = ns;
 056            }
 57
 58            public override string Name
 59            {
 060                get { return Message12Strings.NotUnderstood; }
 61            }
 62
 63            public override string Namespace
 64            {
 065                get { return Message12Strings.Namespace; }
 66            }
 67
 68            protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 69            {
 070                writer.WriteStartElement(Name, Namespace);
 071                writer.WriteXmlnsAttribute(null, _notUnderstoodNs);
 072                writer.WriteStartAttribute(Message12Strings.QName);
 073                writer.WriteQualifiedName(_notUnderstoodName, _notUnderstoodNs);
 074                writer.WriteEndAttribute();
 075            }
 76
 77            protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 78            {
 79                // empty
 080            }
 81        }
 82    }
 83}