< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.SamlAuthenticationClaimResource
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SamlAuthenticationClaimResource.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 67
Coverable lines: 67
Total lines: 159
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 46
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
OnDeserialized(...)0%440%
.ctor(...)0%220%
.ctor(...)0%660%
.ctor(...)0%220%
Equals(...)0%28280%
GetHashCode()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SamlAuthenticationClaimResource.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.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.Runtime.Serialization;
 8using SamlAuthorityBinding = Microsoft.IdentityModel.Tokens.Saml.SamlAuthorityBinding;
 9
 10namespace CoreWCF.IdentityModel.Tokens
 11{
 12    [DataContract(Namespace = "http://schemas.datacontract.org/2004/07/System.IdentityModel.Tokens")]
 13    public class SamlAuthenticationClaimResource
 14    {
 15        [DataMember]
 16        private DateTime authenticationInstant;
 17        [DataMember]
 18        private string authenticationMethod;
 19        [DataMember]
 20        private string dnsAddress;
 21        [DataMember]
 22        private string ipAddress;
 23
 24        [OnDeserialized]
 25        private void OnDeserialized(StreamingContext ctx)
 26        {
 027            if (string.IsNullOrEmpty(authenticationMethod))
 028                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(authenticationMethod));
 029            if (AuthorityBindings == null)
 030                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(AuthorityBindings));
 031        }
 32
 033        public SamlAuthenticationClaimResource(
 034            DateTime authenticationInstant,
 035            string authenticationMethod,
 036            string dnsAddress,
 037            string ipAddress
 038            )
 39        {
 040            if (string.IsNullOrEmpty(authenticationMethod))
 041                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(authenticationMethod));
 42
 043            this.authenticationInstant = authenticationInstant;
 044            this.authenticationMethod = authenticationMethod;
 045            this.dnsAddress = dnsAddress;
 046            this.ipAddress = ipAddress;
 047            AuthorityBindings = (new List<SamlAuthorityBinding>()).AsReadOnly();
 048        }
 49
 50        public SamlAuthenticationClaimResource(
 51            DateTime authenticationInstant,
 52            string authenticationMethod,
 53            string dnsAddress,
 54            string ipAddress,
 55            IEnumerable<SamlAuthorityBinding> authorityBindings
 56            )
 057            : this(authenticationInstant, authenticationMethod, dnsAddress, ipAddress)
 58        {
 059            if (authorityBindings == null)
 060                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(authorityBind
 61
 062            List<SamlAuthorityBinding> tempList = new List<SamlAuthorityBinding>();
 063            foreach (SamlAuthorityBinding authorityBinding in authorityBindings)
 64            {
 065                if (authorityBinding != null)
 066                    tempList.Add(authorityBinding);
 67            }
 068            AuthorityBindings = tempList.AsReadOnly();
 69
 070        }
 71
 72        public SamlAuthenticationClaimResource(
 73            DateTime authenticationInstant,
 74            string authenticationMethod,
 75            string dnsAddress,
 76            string ipAddress,
 77            ReadOnlyCollection<SamlAuthorityBinding> authorityBindings
 78            )
 079            : this(authenticationInstant, authenticationMethod, dnsAddress, ipAddress)
 80        {
 081            AuthorityBindings = authorityBindings ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Argum
 82
 083        }
 84
 085        public DateTime AuthenticationInstant => authenticationInstant;
 86
 087        public string AuthenticationMethod => authenticationMethod;
 88
 089        public ReadOnlyCollection<SamlAuthorityBinding> AuthorityBindings { get; private set; }
 90
 91        [DataMember]
 92        private List<SamlAuthorityBinding> SamlAuthorityBindings
 93        {
 94            get
 95            {
 096                List<SamlAuthorityBinding> sab = new List<SamlAuthorityBinding>();
 097                for (int i = 0; i < AuthorityBindings.Count; ++i)
 98                {
 099                    sab.Add(AuthorityBindings[i]);
 100                }
 0101                return sab;
 102            }
 103            set
 104            {
 0105                if (value != null)
 0106                    AuthorityBindings = value.AsReadOnly();
 0107            }
 108        }
 109
 0110        public string IPAddress => ipAddress;
 111
 0112        public string DnsAddress => dnsAddress;
 113
 114        public override bool Equals(object obj)
 115        {
 0116            if (obj == null)
 0117                return false;
 118
 0119            if (ReferenceEquals(this, obj))
 0120                return true;
 121
 0122            if (!(obj is SamlAuthenticationClaimResource rhs))
 0123                return false;
 124
 0125            if ((AuthenticationInstant != rhs.AuthenticationInstant) ||
 0126                (AuthenticationMethod != rhs.AuthenticationMethod) ||
 0127                (AuthorityBindings.Count != rhs.AuthorityBindings.Count) ||
 0128                (IPAddress != rhs.IPAddress) ||
 0129                (DnsAddress != rhs.DnsAddress))
 0130                return false;
 131
 132            int i;
 0133            for (i = 0; i < AuthorityBindings.Count; ++i)
 134            {
 0135                bool matched = false;
 0136                for (int j = 0; j < rhs.AuthorityBindings.Count; ++j)
 137                {
 0138                    if ((AuthorityBindings[i].AuthorityKind == rhs.AuthorityBindings[j].AuthorityKind) &&
 0139                        (AuthorityBindings[i].Binding == rhs.AuthorityBindings[j].Binding) &&
 0140                        (AuthorityBindings[i].Location == rhs.AuthorityBindings[j].Location))
 141                    {
 0142                        matched = true;
 0143                        break;
 144                    }
 145                }
 146
 0147                if (!matched)
 0148                    return false;
 149            }
 150
 0151            return true;
 152        }
 153
 154        public override int GetHashCode()
 155        {
 0156            return (authenticationInstant.GetHashCode() ^ authenticationMethod.GetHashCode());
 157        }
 158    }
 159}