< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.ImpersonatingMessage
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/ImpersonatingMessage.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 38
Coverable lines: 38
Total lines: 143
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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(...)0%220%
OnClose()100%110%
OnWriteMessageAsync(...)100%110%
OnWriteMessage(...)100%110%
OnWriteStartEnvelope(...)100%110%
OnWriteStartHeaders(...)100%110%
OnWriteStartBody(...)100%110%
OnGetBodyAttribute(...)100%110%
OnCreateBufferedCopy(...)100%110%
OnWriteBodyContentsAsync(...)100%110%
OnWriteBodyContents(...)100%110%
OnBodyToString(...)100%110%
ImpersonateCall(...)0%220%
ImpersonateCall(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/ImpersonatingMessage.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.Threading.Tasks;
 6using System.Xml;
 7using CoreWCF.Channels;
 8
 9namespace CoreWCF.Security
 10{
 11    internal sealed class ImpersonatingMessage : Message
 12    {
 13        private readonly Message _innerMessage;
 14
 015        public ImpersonatingMessage(Message innerMessage)
 16        {
 017            _innerMessage = innerMessage ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(inne
 018        }
 19
 20        public override bool IsEmpty
 21        {
 22            get
 23            {
 024                return _innerMessage.IsEmpty;
 25            }
 26        }
 27
 28        public override bool IsFault
 29        {
 030            get { return _innerMessage.IsFault; }
 31        }
 32
 33        public override MessageHeaders Headers
 34        {
 035            get { return _innerMessage.Headers; }
 36        }
 37
 38        public override MessageProperties Properties
 39        {
 040            get { return _innerMessage.Properties; }
 41        }
 42
 43        public override MessageVersion Version
 44        {
 045            get { return _innerMessage.Version; }
 46        }
 47
 48        public override RecycledMessageState RecycledMessageState
 49        {
 50            get
 51            {
 052                return _innerMessage.RecycledMessageState;
 53            }
 54        }
 55
 56        protected override void OnClose()
 57        {
 058            base.OnClose();
 059            _innerMessage.Close();
 060        }
 61
 62        //Runs impersonated.
 63        public override Task OnWriteMessageAsync(XmlDictionaryWriter writer)
 64        {
 065            return ImpersonateCall(() => _innerMessage.WriteMessageAsync(writer));
 66        }
 67
 68        //Runs impersonated.
 69        protected override void OnWriteMessage(XmlDictionaryWriter writer)
 70        {
 071            ImpersonateCall(() => _innerMessage.WriteMessage(writer));
 072        }
 73
 74        protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
 75        {
 076            _innerMessage.WriteStartEnvelope(writer);
 077        }
 78
 79        protected override void OnWriteStartHeaders(XmlDictionaryWriter writer)
 80        {
 081            _innerMessage.WriteStartHeaders(writer);
 082        }
 83
 84        protected override void OnWriteStartBody(XmlDictionaryWriter writer)
 85        {
 086            _innerMessage.WriteStartBody(writer);
 087        }
 88
 89        protected override string OnGetBodyAttribute(string localName, string ns)
 90        {
 091            return _innerMessage.GetBodyAttribute(localName, ns);
 92        }
 93
 94        protected override MessageBuffer OnCreateBufferedCopy(int maxBufferSize)
 95        {
 096            return _innerMessage.CreateBufferedCopy(maxBufferSize);
 97        }
 98
 99        internal override Task OnWriteBodyContentsAsync(XmlDictionaryWriter writer)
 100        {
 0101            return ImpersonateCall(() => _innerMessage.WriteBodyContentsAsync(writer));
 102        }
 103
 104        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 105        {
 0106            ImpersonateCall(() => _innerMessage.WriteBodyContents(writer));
 0107        }
 108
 109        //Runs impersonated.
 110        protected override void OnBodyToString(XmlDictionaryWriter writer)
 111        {
 0112            ImpersonateCall(() => _innerMessage.BodyToString(writer));
 0113        }
 114
 115        private void ImpersonateCall(Action callToImpersonate)
 116        {
 0117            if (ImpersonateOnSerializingReplyMessageProperty.TryGet(_innerMessage, out ImpersonateOnSerializingReplyMess
 118            {
 0119                _ = impersonationProperty.RunImpersonated(() =>
 0120                      {
 0121                          callToImpersonate();
 0122                          return (object)null;
 0123                      });
 124            }
 125            else
 126            {
 0127                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.UnableToImper
 128            }
 129        }
 130
 131        private T ImpersonateCall<T>(Func<T> callToImpersonate)
 132        {
 0133            if (ImpersonateOnSerializingReplyMessageProperty.TryGet(_innerMessage, out ImpersonateOnSerializingReplyMess
 134            {
 0135                return impersonationProperty.RunImpersonated(callToImpersonate);
 136            }
 137            else
 138            {
 0139                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.UnableToImper
 140            }
 141        }
 142    }
 143}