< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.UriTemplateDispatchFormatter
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/UriTemplateDispatchFormatter.cs
Line coverage
91%
Covered lines: 31
Uncovered lines: 3
Coverable lines: 34
Total lines: 107
Line coverage: 91.1%
Branch coverage
80%
Covered branches: 16
Total branches: 20
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
DeserializeRequest(...)80%202090%
SerializeReply(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/UriTemplateDispatchFormatter.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.Specialized;
 7using CoreWCF.Channels;
 8using CoreWCF.Description;
 9using CoreWCF.Web;
 10
 11namespace CoreWCF.Dispatcher
 12{
 13    internal class UriTemplateDispatchFormatter : IDispatchMessageFormatter
 14    {
 15        internal Dictionary<int, string> _pathMapping;
 16        internal Dictionary<int, KeyValuePair<string, Type>> _queryMapping;
 17        private readonly Uri _baseAddress;
 18        private readonly IDispatchMessageFormatter _inner;
 19        private readonly string _operationName;
 20        private readonly QueryStringConverter _qsc;
 21        private readonly int _totalNumUTVars;
 22        private readonly UriTemplate _uriTemplate;
 23
 32624        public UriTemplateDispatchFormatter(OperationDescription operationDescription, IDispatchMessageFormatter inner, 
 25        {
 32626            _inner = inner;
 32627            _qsc = qsc;
 32628            _baseAddress = baseAddress;
 32629            _operationName = operationDescription.Name;
 32630            UriTemplateClientFormatter.Populate(out _pathMapping,
 32631                out _queryMapping,
 32632                out _totalNumUTVars,
 32633                out _uriTemplate,
 32634                operationDescription,
 32635                qsc,
 32636                contractName);
 32637        }
 38
 39        public void DeserializeRequest(Message message, object[] parameters)
 40        {
 3341            object[] innerParameters = new object[parameters.Length - _totalNumUTVars];
 3342            if (innerParameters.Length != 0)
 43            {
 644                _inner.DeserializeRequest(message, innerParameters);
 45            }
 46
 3347            int j = 0;
 3348            UriTemplateMatch utmr = null;
 3349            string UTMRName = IncomingWebRequestContext.UriTemplateMatchResultsPropertyName;
 3350            if (message.Properties.ContainsKey(UTMRName))
 51            {
 3352                utmr = message.Properties[UTMRName] as UriTemplateMatch;
 53            }
 54            else
 55            {
 056                if (message.Headers.To != null && message.Headers.To.IsAbsoluteUri)
 57                {
 058                    utmr = _uriTemplate.Match(_baseAddress, message.Headers.To);
 59                }
 60            }
 61
 3362            NameValueCollection nvc = (utmr == null) ? new NameValueCollection() : utmr.BoundVariables;
 9063            for (int i = 0; i < parameters.Length; ++i)
 64            {
 1265                if (_pathMapping.ContainsKey(i) && utmr != null)
 66                {
 567                    parameters[i] = nvc[_pathMapping[i]];
 68                }
 769                else if (_queryMapping.ContainsKey(i) && utmr != null)
 70                {
 171                    string queryVal = nvc[_queryMapping[i].Key];
 172                    parameters[i] = _qsc.ConvertStringToValue(queryVal, _queryMapping[i].Value);
 73                }
 74                else
 75                {
 676                    parameters[i] = innerParameters[j];
 677                    ++j;
 78                }
 79            }
 80
 81            //if (DiagnosticUtility.ShouldTraceInformation)
 82            //{
 83            //    if (utmr != null)
 84            //    {
 85            //        foreach (string key in utmr.QueryParameters.Keys)
 86            //        {
 87            //            bool isParameterIgnored = true;
 88            //            foreach (KeyValuePair<string, Type> kvp in this._queryMapping.Values)
 89            //            {
 90            //                if (String.Compare(key, kvp.Key, StringComparison.OrdinalIgnoreCase) == 0)
 91            //                {
 92            //                    isParameterIgnored = false;
 93            //                    break;
 94            //                }
 95            //            }
 96            //            if (isParameterIgnored)
 97            //            {
 98            //                TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.WebUnknownQueryParameterIgno
 99            //            }
 100            //        }
 101            //    }
 102            //}
 33103        }
 104
 0105        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) => throw Diagno
 106    }
 107}