< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Primitives.Tests.CustomSecurity.MyTestAuthorizationPolicy
Assembly: UnitTests.Common
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/CustomSecurity/MyTestAuthorizationPolicy.cs
Line coverage
91%
Covered lines: 22
Uncovered lines: 2
Coverable lines: 24
Total lines: 77
Line coverage: 91.6%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
Evaluate(...)50%4486.66%
.ctor()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/CustomSecurity/MyTestAuthorizationPolicy.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 CoreWCF.IdentityModel.Claims;
 7using CoreWCF.IdentityModel.Policy;
 8
 9namespace CoreWCF.Primitives.Tests.CustomSecurity
 10{
 11    public class MyTestAuthorizationPolicy : IAuthorizationPolicy
 12    {
 413        public MyTestAuthorizationPolicy()
 14        {
 415            Id = Guid.NewGuid().ToString();
 416        }
 17
 18        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
 19        {
 20            CustomAuthState customstate;
 21
 22            // If the state is null, then this has not been called before so
 23            // set up a custom state.
 424            if (state == null)
 25            {
 426                customstate = new CustomAuthState();
 427                state = customstate;
 28            }
 29            else
 30            {
 031                customstate = (CustomAuthState)state;
 32            }
 33
 34            bool bRet;
 35            // If claims have not been added yet...
 436            if (!customstate.ClaimsAdded)
 37            {
 38                // Create an empty list of claims.
 439                IList<Claim> claims = new List<Claim>
 440                {
 441                    new Claim("http://tempuri.org/claims/allowedoperation", "http://tempuri.org/IEchoService/EchoString"
 442                    new Claim("http://tempuri.org/claims/allowedoperation", "http://tempuri.org/IEchoService/ComplexEcho
 443                };
 444                evaluationContext.AddClaimSet(this, new DefaultClaimSet(Issuer, claims));
 45                // Record that claims were added.
 446                customstate.ClaimsAdded = true;
 47                // Return true, indicating that this method does not need to be called again.
 448                bRet = true;
 49            }
 50            else
 51            {
 52                // Should never get here, but just in case, return true.
 053                bRet = true;
 54            }
 55
 456            return bRet;
 57        }
 58
 59        public ClaimSet Issuer
 60        {
 461            get { return ClaimSet.System; }
 62        }
 63
 464        public string Id { get; private set; }
 65
 66        // Internal class for keeping track of state.
 67        private class CustomAuthState
 68        {
 469            public CustomAuthState()
 70            {
 471                ClaimsAdded = false;
 472            }
 73
 1274            public bool ClaimsAdded { get; set; }
 75        }
 76    }
 77}