< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.UriTemplateQueryValue
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/UriTemplateQueryValue.cs
Line coverage
29%
Covered lines: 7
Uncovered lines: 17
Coverable lines: 24
Total lines: 90
Line coverage: 29.1%
Branch coverage
20%
Covered branches: 2
Total branches: 10
Branch coverage: 20%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
CreateFromUriTemplate(...)33.33%6637.5%
IsNullOrEmpty(...)0%440%
.ctor()100%110%
Bind(...)100%110%
IsEquivalentTo(...)100%110%
Lookup(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/UriTemplateQueryValue.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.Specialized;
 6using System.Text;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF
 10{
 11    internal abstract class UriTemplateQueryValue
 12    {
 2913        protected UriTemplateQueryValue(UriTemplatePartType nature)
 14        {
 2915            Nature = nature;
 2916        }
 17
 018        public static UriTemplateQueryValue Empty { get; } = new EmptyUriTemplateQueryValue();
 19
 220        public UriTemplatePartType Nature { get; }
 21
 22        public static UriTemplateQueryValue CreateFromUriTemplate(string value, UriTemplate template)
 23        {
 24            // Checking for empty value
 2925            if (value == null)
 26            {
 027                return Empty;
 28            }
 29
 30            // Identifying the type of value - Literal|Compound|Variable
 2931            switch (UriTemplateHelpers.IdentifyPartType(value))
 32            {
 33                case UriTemplatePartType.Literal:
 034                    return UriTemplateLiteralQueryValue.CreateFromUriTemplate(value);
 35
 36                case UriTemplatePartType.Compound:
 037                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
 038                        SR.UTQueryCannotHaveCompoundValue, template._originalTemplate)));
 39
 40                case UriTemplatePartType.Variable:
 2941                    return new UriTemplateVariableQueryValue(template.AddQueryVariable(value.Substring(1, value.Length -
 42
 43                default:
 44                    Fx.Assert("Invalid value from IdentifyStringNature");
 045                    return null;
 46            }
 47        }
 48
 49        public static bool IsNullOrEmpty(UriTemplateQueryValue utqv)
 50        {
 051            if (utqv == null)
 52            {
 053                return true;
 54            }
 55
 056            if (utqv == Empty)
 57            {
 058                return true;
 59            }
 60
 061            return false;
 62        }
 63
 64        public abstract void Bind(string keyName, string[] values, ref int valueIndex, StringBuilder query);
 65
 66        public abstract bool IsEquivalentTo(UriTemplateQueryValue other);
 67
 68        public abstract void Lookup(string value, NameValueCollection boundParameters);
 69
 70        internal class EmptyUriTemplateQueryValue : UriTemplateQueryValue
 71        {
 72            public EmptyUriTemplateQueryValue()
 073                : base(UriTemplatePartType.Literal)
 74            {
 075            }
 76
 77            public override void Bind(string keyName, string[] values, ref int valueIndex, StringBuilder query)
 78            {
 079                query.AppendFormat("&{0}", UrlUtility.UrlEncode(keyName, Encoding.UTF8));
 080            }
 81
 082            public override bool IsEquivalentTo(UriTemplateQueryValue other) => other == Empty;
 83
 84            public override void Lookup(string value, NameValueCollection boundParameters)
 85            {
 86                Fx.Assert(string.IsNullOrEmpty(value), "shouldn't have a value");
 087            }
 88        }
 89    }
 90}