< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.MultiplexingDispatchMessageFormatter
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/MultiplexingDispatchMessageFormatter.cs
Line coverage
67%
Covered lines: 23
Uncovered lines: 11
Coverable lines: 34
Total lines: 98
Line coverage: 67.6%
Branch coverage
62%
Covered branches: 15
Total branches: 24
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
DeserializeRequest(...)100%110%
SerializeReply(...)63.63%222264%
SupportsMessageFormat(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/MultiplexingDispatchMessageFormatter.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 CoreWCF.Channels;
 7using CoreWCF.Runtime;
 8using CoreWCF.Web;
 9
 10namespace CoreWCF.Dispatcher
 11{
 12    internal class MultiplexingDispatchMessageFormatter : IDispatchMessageFormatter
 13    {
 14        private readonly Dictionary<WebMessageFormat, IDispatchMessageFormatter> _formatters;
 15
 3016        public WebMessageFormat DefaultFormat { get; }
 17
 34418        public Dictionary<WebMessageFormat, string> DefaultContentTypes { get; }
 19
 16020        public MultiplexingDispatchMessageFormatter(Dictionary<WebMessageFormat, IDispatchMessageFormatter> formatters, 
 21        {
 16022            _formatters = formatters ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(formatte
 16023            DefaultFormat = defaultFormat;
 16024            DefaultContentTypes = new Dictionary<WebMessageFormat, string>();
 25
 26            Fx.Assert(_formatters.ContainsKey(DefaultFormat), "The default format should always be included in the dicti
 16027        }
 28
 29        public void DeserializeRequest(Message message, object[] parameters)
 30        {
 031            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Serializing
 32        }
 33
 34        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
 35        {
 3036            WebOperationContext currentContext = WebOperationContext.Current;
 3037            OutgoingWebResponseContext outgoingResponse = null;
 38
 3039            if (currentContext != null)
 40            {
 3041                outgoingResponse = currentContext.OutgoingResponse;
 42            }
 43
 3044            WebMessageFormat format = DefaultFormat;
 3045            if (outgoingResponse != null)
 46            {
 3047                WebMessageFormat? nullableFormat = outgoingResponse.Format;
 3048                if (nullableFormat.HasValue)
 49                {
 050                    format = nullableFormat.Value;
 51                }
 52            }
 53
 3054            if (!_formatters.ContainsKey(format))
 55            {
 056                string operationName = "<null>";
 57
 058                if (OperationContext.Current != null)
 59                {
 060                    MessageProperties messageProperties = OperationContext.Current.IncomingMessageProperties;
 061                    if (messageProperties.ContainsKey(WebHttpDispatchOperationSelector.HttpOperationNamePropertyName))
 62                    {
 063                        operationName = messageProperties[WebHttpDispatchOperationSelector.HttpOperationNamePropertyName
 64                    }
 65                }
 66
 067                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Operati
 68            }
 69
 3070            if (outgoingResponse != null && string.IsNullOrEmpty(outgoingResponse.ContentType))
 71            {
 2972                string automatedSelectionContentType = outgoingResponse.AutomatedFormatSelectionContentType;
 2973                if (!string.IsNullOrEmpty(automatedSelectionContentType))
 74                {
 75                    // Don't set the content-type if it is default xml for backwards compatibility
 076                    if (!string.Equals(automatedSelectionContentType, DefaultContentTypes[WebMessageFormat.Xml], StringC
 77                    {
 078                        outgoingResponse.ContentType = automatedSelectionContentType;
 79                    }
 80                }
 81                else
 82                {
 83                    // Don't set the content-type if it is default xml for backwards compatibility
 2984                    if (format != WebMessageFormat.Xml)
 85                    {
 2486                        outgoingResponse.ContentType = DefaultContentTypes[format];
 87                    }
 88                }
 89            }
 90
 3091            Message message = _formatters[format].SerializeReply(messageVersion, parameters, result);
 92
 3093            return message;
 94        }
 95
 096        public bool SupportsMessageFormat(WebMessageFormat format) => _formatters.ContainsKey(format);
 97    }
 98}