< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.XmlMessageConverter
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/TypedMessageConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 132
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
ToMessage(...)100%110%
ToMessage(...)0%220%
FromMessage(...)0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/TypedMessageConverter.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 CoreWCF.Channels;
 6using CoreWCF.Dispatcher;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF.Description
 10{
 11    public abstract class TypedMessageConverter
 12    {
 13        public static TypedMessageConverter Create(Type messageContract, string action)
 14        {
 15            return Create(messageContract, action, null, TypeLoader.DefaultDataContractFormatAttribute);
 16        }
 17
 18        public static TypedMessageConverter Create(Type messageContract, string action, string defaultNamespace)
 19        {
 20            return Create(messageContract, action, defaultNamespace, TypeLoader.DefaultDataContractFormatAttribute);
 21        }
 22
 23        public static TypedMessageConverter Create(Type messageContract, string action, XmlSerializerFormatAttribute for
 24        {
 25            return Create(messageContract, action, null, formatterAttribute);
 26        }
 27
 28        public static TypedMessageConverter Create(Type messageContract, string action, DataContractFormatAttribute form
 29        {
 30            return Create(messageContract, action, null, formatterAttribute);
 31        }
 32
 33        public static TypedMessageConverter Create(Type messageContract, string action, string defaultNamespace, XmlSeri
 34        {
 35            if (messageContract == null)
 36            {
 37                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(messageContra
 38            }
 39
 40            if (defaultNamespace == null)
 41            {
 42                defaultNamespace = NamingHelper.DefaultNamespace;
 43            }
 44
 45            return new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, 
 46        }
 47
 48        public static TypedMessageConverter Create(Type messageContract, string action, string defaultNamespace, DataCon
 49        {
 50            if (messageContract == null)
 51            {
 52                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(messageContra
 53            }
 54
 55            if (!messageContract.IsDefined(typeof(MessageContractAttribute), false))
 56            {
 57                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.SFxMessageC
 58            }
 59
 60            if (defaultNamespace == null)
 61            {
 62                defaultNamespace = NamingHelper.DefaultNamespace;
 63            }
 64
 65            return new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, 
 66        }
 67
 68        public abstract Message ToMessage(object typedMessage);
 69        public abstract Message ToMessage(object typedMessage, MessageVersion version);
 70        public abstract object FromMessage(Message message);
 71
 72        private static OperationFormatter GetOperationFormatter(Type t, Attribute formatAttribute, string defaultNS, str
 73        {
 74            bool isXmlSerializer = (formatAttribute is XmlSerializerFormatAttribute);
 75            TypeLoader<object> typeLoader = new TypeLoader<object>();
 76            MessageDescription message = typeLoader.CreateTypedMessageDescription(t, null, null, defaultNS, action, Mess
 77            ContractDescription contract = new ContractDescription("dummy_contract", defaultNS);
 78            OperationDescription operation = new OperationDescription(NamingHelper.XmlName(t.Name), contract, false);
 79            operation.Messages.Add(message);
 80
 81            if (isXmlSerializer)
 82            {
 83                return XmlSerializerOperationBehavior.CreateOperationFormatter(operation, (XmlSerializerFormatAttribute)
 84            }
 85            else
 86            {
 87                return new DataContractSerializerOperationFormatter(operation, (DataContractFormatAttribute)formatAttrib
 88            }
 89        }
 90    }
 91
 92    internal class XmlMessageConverter : TypedMessageConverter
 93    {
 94        private OperationFormatter _formatter;
 95
 096        internal XmlMessageConverter(OperationFormatter formatter)
 97        {
 098            _formatter = formatter;
 099        }
 100
 0101        internal string Action => _formatter.RequestAction;
 102
 103        public override Message ToMessage(object typedMessage)
 104        {
 0105            return ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10);
 106        }
 107
 108        public override Message ToMessage(object typedMessage, MessageVersion version)
 109        {
 0110            if (typedMessage == null)
 111            {
 0112                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(typedMessage)
 113            }
 114
 0115            return _formatter.SerializeRequest(version, new object[] { typedMessage });
 116        }
 117
 118        public override object FromMessage(Message message)
 119        {
 120            Fx.Assert(message.Headers != null, "");
 0121            if (Action != null && message.Headers.Action != null && message.Headers.Action != Action)
 122            {
 0123                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx
 124            }
 125
 0126            object[] result = new object[1];
 0127            _formatter.DeserializeRequest(message, result);
 128
 0129            return result[0];
 130        }
 131    }
 132}