< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.PrivacyNoticeBindingElement
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/PrivacyNoticeBindingElement.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 112
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
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%
Clone()100%110%
GetProperty(...)0%220%
CoreWCF.Description.IPolicyExportExtension.ExportPolicy(...)0%660%
IsMatch(...)0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/PrivacyNoticeBindingElement.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.Description;
 7
 8namespace CoreWCF.Channels
 9{
 10    public sealed class PrivacyNoticeBindingElement : BindingElement, IPolicyExportExtension
 11    {
 12        private Uri _url;
 13        private int _version;
 14
 015        public PrivacyNoticeBindingElement()
 16        {
 017            _url = null;
 018        }
 19
 20        public PrivacyNoticeBindingElement(PrivacyNoticeBindingElement elementToBeCloned)
 021            : base(elementToBeCloned)
 22        {
 023            _url = elementToBeCloned._url;
 024            _version = elementToBeCloned._version;
 025        }
 26
 27        public Uri Url
 28        {
 29            get
 30            {
 031                return _url;
 32            }
 33            set
 34            {
 035                if (value == null)
 36                {
 037                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 38                }
 39
 040                _url = value;
 041            }
 42        }
 43
 44        public int Version
 45        {
 46            get
 47            {
 048                return _version;
 49            }
 50            set
 51            {
 052                if (value < 0)
 53                {
 054                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 055                                                                        SR.Format(SRCommon.ValueMustBePositive)));
 56                }
 057                _version = value;
 058            }
 59        }
 60
 61        public override BindingElement Clone()
 62        {
 063            return new PrivacyNoticeBindingElement(this);
 64        }
 65
 66        public override T GetProperty<T>(BindingContext context)
 67        {
 068            if (context == null)
 69            {
 070                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 71            }
 072            return context.GetInnerProperty<T>();
 73        }
 74
 75        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
 76        {
 077            if (context == null)
 078                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 79
 080            if (context.BindingElements != null)
 81            {
 082                PrivacyNoticeBindingElement settings =
 083                    context.BindingElements.Find<PrivacyNoticeBindingElement>();
 84
 085                if (settings != null)
 86                {
 087                    XmlDocument doc = new XmlDocument();
 88
 89                    // PrivacyNotice assertion
 090                    XmlElement assertion = doc.CreateElement(PrivacyNoticePolicyStrings.PrivacyNoticePrefix,
 091                                                              PrivacyNoticePolicyStrings.PrivacyNoticeName,
 092                                                              PrivacyNoticePolicyStrings.PrivacyNoticeNamespace);
 93
 094                    assertion.InnerText = settings.Url.ToString();
 095                    assertion.SetAttribute(PrivacyNoticePolicyStrings.PrivacyNoticeVersionAttributeName, PrivacyNoticePo
 96
 097                    context.GetBindingAssertions().Add(assertion);
 98                }
 99            }
 0100        }
 101
 102        protected override bool IsMatch(BindingElement b)
 103        {
 0104            if (b == null)
 0105                return false;
 0106            PrivacyNoticeBindingElement privacy = b as PrivacyNoticeBindingElement;
 0107            if (privacy == null)
 0108                return false;
 0109            return (_url == privacy._url && _version == privacy._version);
 110        }
 111    }
 112}