< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.DemultiplexingDispatchMessageFormatter
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/DemultiplexingDispatchMessageFormatter.cs
Line coverage
44%
Covered lines: 17
Uncovered lines: 21
Coverable lines: 38
Total lines: 106
Line coverage: 44.7%
Branch coverage
40%
Covered branches: 8
Total branches: 20
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)75%4487.5%
DeserializeRequest(...)50%8854.54%
SerializeReply(...)100%110%
GetSupportedFormats(...)0%440%
TryGetEncodingFormat(...)50%2266.66%
GetSupportedFormats()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/DemultiplexingDispatchMessageFormatter.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.Globalization;
 7using System.Text;
 8using CoreWCF.Channels;
 9
 10namespace CoreWCF.Dispatcher
 11{
 12    internal class DemultiplexingDispatchMessageFormatter : IDispatchMessageFormatter
 13    {
 14        private readonly IDispatchMessageFormatter _defaultFormatter;
 15        private readonly Dictionary<WebContentFormat, IDispatchMessageFormatter> _formatters;
 16        private string _supportedFormats;
 17
 16018        public DemultiplexingDispatchMessageFormatter(IDictionary<WebContentFormat, IDispatchMessageFormatter> formatter
 19        {
 16020            if (formatters == null)
 21            {
 022                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(formatters));
 23            }
 24
 16025            _formatters = new Dictionary<WebContentFormat, IDispatchMessageFormatter>();
 96026            foreach (WebContentFormat key in formatters.Keys)
 27            {
 32028                _formatters.Add(key, formatters[key]);
 29            }
 30
 16031            _defaultFormatter = defaultFormatter;
 16032        }
 33
 34        public void DeserializeRequest(Message message, object[] parameters)
 35        {
 536            if (message == null)
 37            {
 038                return;
 39            }
 40
 41            IDispatchMessageFormatter selectedFormatter;
 542            if (TryGetEncodingFormat(message, out WebContentFormat format))
 43            {
 544                _formatters.TryGetValue(format, out selectedFormatter);
 545                if (selectedFormatter == null)
 46                {
 047                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.Format(
 48                }
 49            }
 50            else
 51            {
 052                selectedFormatter = _defaultFormatter;
 053                if (selectedFormatter == null)
 54                {
 055                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.Format(
 56                }
 57            }
 58
 559            selectedFormatter.DeserializeRequest(message, parameters);
 560        }
 61
 062        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) => throw Diagno
 63
 64        internal static string GetSupportedFormats(IEnumerable<WebContentFormat> formats)
 65        {
 066            StringBuilder sb = new StringBuilder();
 067            int i = 0;
 068            foreach (WebContentFormat format in formats)
 69            {
 070                if (i > 0)
 71                {
 072                    sb.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator);
 073                    sb.Append(" ");
 74                }
 075                sb.Append("'" + format.ToString() + "'");
 076                ++i;
 77            }
 78
 079            return sb.ToString();
 80        }
 81
 82        internal static bool TryGetEncodingFormat(Message message, out WebContentFormat format)
 83        {
 584            message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out object prop);
 585            if (!(prop is WebBodyFormatMessageProperty formatProperty))
 86            {
 087                format = WebContentFormat.Default;
 088                return false;
 89            }
 90
 591            format = formatProperty.Format;
 92
 593            return true;
 94        }
 95
 96        private string GetSupportedFormats()
 97        {
 098            if (_supportedFormats == null)
 99            {
 0100                _supportedFormats = GetSupportedFormats(_formatters.Keys);
 101            }
 102
 0103            return _supportedFormats;
 104        }
 105    }
 106}