< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.UriTemplateVariablePathSegment
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/UriTemplateVariablePathSegment.cs
Line coverage
33%
Covered lines: 6
Uncovered lines: 12
Coverable lines: 18
Total lines: 67
Line coverage: 33.3%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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%11100%
Bind(...)0%220%
IsEquivalentTo(...)0%660%
IsMatch(...)0%440%
Lookup(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/UriTemplateVariablePathSegment.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.Collections.Specialized;
 5using System.Text;
 6using CoreWCF.Runtime;
 7
 8namespace CoreWCF
 9{
 10    internal class UriTemplateVariablePathSegment : UriTemplatePathSegment
 11    {
 12        public UriTemplateVariablePathSegment(string originalSegment, bool endsWithSlash, string varName)
 5213            : base(originalSegment, UriTemplatePartType.Variable, endsWithSlash)
 14        {
 15            Fx.Assert(!string.IsNullOrEmpty(varName), "bad variable segment");
 5216            VarName = varName;
 5217        }
 18
 2619        public string VarName { get; }
 20
 21        public override void Bind(string[] values, ref int valueIndex, StringBuilder path)
 22        {
 23            Fx.Assert(valueIndex < values.Length, "Not enough values to bind");
 024            if (EndsWithSlash)
 25            {
 026                path.AppendFormat("{0}/", values[valueIndex++]);
 27            }
 28            else
 29            {
 030                path.Append(values[valueIndex++]);
 31            }
 032        }
 33
 34        public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
 35        {
 036            if (other == null)
 37            {
 38                Fx.Assert("why would we ever call this?");
 039                return false;
 40            }
 41
 042            if (!ignoreTrailingSlash && (EndsWithSlash != other.EndsWithSlash))
 43            {
 044                return false;
 45            }
 46
 047            return (other.Nature == UriTemplatePartType.Variable);
 48        }
 49
 50        public override bool IsMatch(UriTemplateLiteralPathSegment segment, bool ignoreTrailingSlash)
 51        {
 052            if (!ignoreTrailingSlash && (EndsWithSlash != segment.EndsWithSlash))
 53            {
 054                return false;
 55            }
 56
 057            return (!segment.IsNullOrEmpty());
 58        }
 59
 60        public override void Lookup(string segment, NameValueCollection boundParameters)
 61        {
 62            Fx.Assert(!string.IsNullOrEmpty(segment), "How can that be? Lookup is expected to be called after IsMatch");
 63
 164            boundParameters.Add(VarName, segment);
 165        }
 66    }
 67}