< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.X509CertificateRecipientServiceCredential
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/X509CertificateRecipientServiceCredential.cs
Line coverage
46%
Covered lines: 12
Uncovered lines: 14
Coverable lines: 26
Total lines: 77
Line coverage: 46.1%
Branch coverage
16%
Covered branches: 1
Total branches: 6
Branch coverage: 16.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%
.ctor(...)100%11100%
SetCertificate(...)100%110%
SetCertificate(...)0%220%
SetCertificate(...)0%220%
MakeReadOnly()100%110%
ThrowIfImmutable()50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/X509CertificateRecipientServiceCredential.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.Security.Cryptography.X509Certificates;
 6
 7namespace CoreWCF.Security
 8{
 9    public sealed class X509CertificateRecipientServiceCredential
 10    {
 11        private X509Certificate2 _certificate;
 12        internal const StoreLocation DefaultStoreLocation = StoreLocation.LocalMachine;
 13        internal const StoreName DefaultStoreName = StoreName.My;
 14        internal const X509FindType DefaultFindType = X509FindType.FindBySubjectDistinguishedName;
 15        private bool _isReadOnly;
 16
 5217        internal X509CertificateRecipientServiceCredential()
 18        {
 5219        }
 20
 6621        internal X509CertificateRecipientServiceCredential(X509CertificateRecipientServiceCredential other)
 22        {
 6623            _certificate = other._certificate;
 6624            _isReadOnly = other._isReadOnly;
 6625        }
 26
 27        public X509Certificate2 Certificate
 28        {
 29            get
 30            {
 1531                return _certificate;
 32            }
 33            set
 34            {
 835                ThrowIfImmutable();
 836                _certificate = value;
 837            }
 38        }
 39
 40        public void SetCertificate(string subjectName)
 41        {
 042            SetCertificate(subjectName, DefaultStoreLocation, DefaultStoreName);
 043        }
 44
 45        public void SetCertificate(string subjectName, StoreLocation storeLocation, StoreName storeName)
 46        {
 047            if (subjectName == null)
 48            {
 049                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(subjectName));
 50            }
 051            SetCertificate(storeLocation, storeName, DefaultFindType, subjectName);
 052        }
 53
 54        public void SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findV
 55        {
 056            if (findValue == null)
 57            {
 058                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(findValue));
 59            }
 060            ThrowIfImmutable();
 061            _certificate = SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
 062        }
 63
 64        internal void MakeReadOnly()
 65        {
 066            _isReadOnly = true;
 067        }
 68
 69        private void ThrowIfImmutable()
 70        {
 871            if (_isReadOnly)
 72            {
 073                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.ObjectIsReadO
 74            }
 875        }
 76    }
 77}