< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.UriTemplateMatch
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/UriTemplateMatch.cs
Line coverage
63%
Covered lines: 30
Uncovered lines: 17
Coverable lines: 47
Total lines: 166
Line coverage: 63.8%
Branch coverage
33%
Covered branches: 6
Total branches: 18
Branch coverage: 33.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
SetQueryParameters(...)100%11100%
SetRelativePathSegments(...)100%11100%
SetWildcardPathSegmentsStart(...)100%11100%
SetBaseUri(...)100%11100%
PopulateQueryParameters()0%220%
PopulateWildcardSegments()0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/UriTemplateMatch.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.ObjectModel;
 6using System.Collections.Specialized;
 7using System.Net;
 8using CoreWCF.Channels;
 9using CoreWCF.Runtime;
 10
 11namespace CoreWCF
 12{
 13    public class UriTemplateMatch
 14    {
 15        private Uri _baseUri;
 16        private NameValueCollection _boundVariables;
 17        private NameValueCollection _queryParameters;
 18        private Collection<string> _relativePathSegments;
 19        private Collection<string> _wildcardPathSegments;
 3520        private int _wildcardSegmentsStartOffset = -1;
 21        private Uri _originalBaseUri;
 22        private HttpRequestMessageProperty _requestProp;
 23
 3524        public UriTemplateMatch()
 25        {
 3526        }
 27
 28        public Uri BaseUri   // the base address, untouched
 29        {
 30            get
 31            {
 3532                if (_baseUri == null && _originalBaseUri != null)
 33                {
 034                    _baseUri = UriTemplate.RewriteUri(_originalBaseUri, _requestProp.Headers[HttpRequestHeader.Host]);
 35                }
 36
 3537                return _baseUri;
 38            }
 39            set
 40            {
 3541                _baseUri = value;
 3542                _originalBaseUri = null;
 3543                _requestProp = null;
 3544            }
 45        }
 46
 47        public NameValueCollection BoundVariables // result of TryLookup, values are decoded
 48        {
 49            get
 50            {
 7551                if (_boundVariables == null)
 52                {
 3553                    _boundVariables = new NameValueCollection();
 54                }
 55
 7556                return _boundVariables;
 57            }
 58        }
 59
 7060        public object Data { get; set; }
 61
 62        public NameValueCollection QueryParameters  // the result of UrlUtility.ParseQueryString (keys and values are de
 63        {
 64            get
 65            {
 166                if (_queryParameters == null)
 67                {
 068                    PopulateQueryParameters();
 69                }
 70
 171                return _queryParameters;
 72            }
 73        }
 74
 75        public Collection<string> RelativePathSegments  // entire Path (after the base address), decoded
 76        {
 77            get
 78            {
 4079                if (_relativePathSegments == null)
 80                {
 081                    _relativePathSegments = new Collection<string>();
 82                }
 4083                return _relativePathSegments;
 84            }
 85        }
 86
 87        public Uri RequestUri  // uri on the wire, untouched
 88        {
 189            get;
 3590            set;
 91        }
 92
 93        public UriTemplate Template // which one got matched
 94        {
 095            get;
 3596            set;
 97        }
 98
 99        public Collection<string> WildcardPathSegments  // just the Path part matched by "*", decoded
 100        {
 101            get
 102            {
 0103                if (_wildcardPathSegments == null)
 104                {
 0105                    PopulateWildcardSegments();
 106                }
 107
 0108                return _wildcardPathSegments;
 109            }
 110        }
 111
 112        internal void SetQueryParameters(NameValueCollection queryParameters)
 113        {
 1114            _queryParameters = new NameValueCollection(queryParameters);
 1115        }
 116
 117        internal void SetRelativePathSegments(Collection<string> segments)
 118        {
 119            Fx.Assert(segments != null, "segments != null");
 120
 35121            _relativePathSegments = segments;
 35122        }
 123
 124        internal void SetWildcardPathSegmentsStart(int startOffset)
 125        {
 126            Fx.Assert(startOffset >= 0, "startOffset >= 0");
 127
 35128            _wildcardSegmentsStartOffset = startOffset;
 35129        }
 130
 131        internal void SetBaseUri(Uri originalBaseUri, HttpRequestMessageProperty requestProp)
 132        {
 35133            _baseUri = null;
 35134            _originalBaseUri = originalBaseUri;
 35135            _requestProp = requestProp;
 35136        }
 137
 138        private void PopulateQueryParameters()
 139        {
 0140            if (RequestUri != null)
 141            {
 0142                _queryParameters = UriTemplateHelpers.ParseQueryString(this.RequestUri.Query);
 143            }
 144            else
 145            {
 0146                _queryParameters = new NameValueCollection();
 147            }
 0148        }
 149
 150        private void PopulateWildcardSegments()
 151        {
 0152            if (_wildcardSegmentsStartOffset != -1)
 153            {
 0154                _wildcardPathSegments = new Collection<string>();
 0155                for (int i = _wildcardSegmentsStartOffset; i < RelativePathSegments.Count; ++i)
 156                {
 0157                    _wildcardPathSegments.Add(RelativePathSegments[i]);
 158                }
 159            }
 160            else
 161            {
 0162                _wildcardPathSegments = new Collection<string>();
 163            }
 0164        }
 165    }
 166}