< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.HttpStreamFormatter
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/HttpStreamFormatter.cs
Line coverage
73%
Covered lines: 22
Uncovered lines: 8
Coverable lines: 30
Total lines: 93
Line coverage: 73.3%
Branch coverage
42%
Covered branches: 6
Total branches: 14
Branch coverage: 42.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%2285.71%
DeserializeRequest(...)100%11100%
SerializeReply(...)50%2275%
IsEmptyMessage(...)100%11100%
CreateMessageFromStream(...)50%4471.42%
GetStreamFromMessage(...)33.33%6655.55%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/HttpStreamFormatter.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.IO;
 6using CoreWCF.Channels;
 7using CoreWCF.Description;
 8
 9namespace CoreWCF.Dispatcher
 10{
 11    internal class HttpStreamFormatter : IDispatchMessageFormatter
 12    {
 13        private readonly string _contractName;
 14        private readonly string _contractNs;
 15        private readonly string _operationName;
 16
 617        public HttpStreamFormatter(OperationDescription operation)
 18        {
 619            if (operation == null)
 20            {
 021                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(operation));
 22            }
 23
 624            _operationName = operation.Name;
 625            _contractName = operation.DeclaringContract.Name;
 626            _contractNs = operation.DeclaringContract.Namespace;
 627        }
 28
 29        public void DeserializeRequest(Message message, object[] parameters)
 30        {
 131            parameters[0] = GetStreamFromMessage(message, true);
 132        }
 33
 34        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
 35        {
 136            Message message = CreateMessageFromStream(result);
 137            if (result == null)
 38            {
 039                SingleBodyParameterMessageFormatter.SuppressReplyEntityBody(message);
 40            }
 41
 142            return message;
 43        }
 44
 545        internal static bool IsEmptyMessage(Message message) => message.IsEmpty;
 46
 47        private Message CreateMessageFromStream(object data)
 48        {
 49            Message result;
 150            if (data == null)
 51            {
 052                result = Message.CreateMessage(MessageVersion.None, (string)null);
 53            }
 54            else
 55            {
 156                if (!(data is Stream streamData))
 57                {
 058                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.Paramet
 59                }
 60
 161                result = ByteStreamMessage.CreateMessage(streamData);
 162                result.Properties[WebBodyFormatMessageProperty.Name] = WebBodyFormatMessageProperty.RawProperty;
 63            }
 64
 165            return result;
 66        }
 67
 68        private Stream GetStreamFromMessage(Message message, bool isRequest)
 69        {
 170            message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out object prop);
 171            WebBodyFormatMessageProperty formatProperty = (prop as WebBodyFormatMessageProperty);
 172            if (formatProperty == null)
 73            {
 74                // GET and DELETE do not go through the encoder
 075                if (IsEmptyMessage(message))
 76                {
 077                    return new MemoryStream();
 78                }
 79                else
 80                {
 081                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.Format(
 82                }
 83            }
 84
 185            if (formatProperty.Format != WebContentFormat.Raw)
 86            {
 087                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR.Format(SR.I
 88            }
 89
 190            return new MessageBodyStream(message, null, null, HttpStreamMessage.StreamElementName, string.Empty, isReque
 91        }
 92    }
 93}