< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Web.WebFaultException<T>
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Web/WebFaultException .cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 160
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%
.ctor(...)0%220%
.ctor(...)100%110%
GetObjectData(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Web/WebFaultException .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.Net;
 7using System.Runtime.Serialization;
 8using System.Security;
 9using System.Security.Permissions;
 10
 11namespace CoreWCF.Web
 12{
 13    [Serializable]
 14    public class WebFaultException : FaultException, IWebFaultException
 15    {
 16        internal const string WebFaultCodeNamespace = "http://schemas.microsoft.com/2009/WebFault";
 17
 18        public WebFaultException(HttpStatusCode statusCode)
 19            : base(GetDefaultReason(statusCode), GetFaultCode(statusCode))
 20        {
 21            StatusCode = statusCode;
 22        }
 23
 24        protected WebFaultException(SerializationInfo info, StreamingContext context)
 25            : base(info, context)
 26        {
 27            StatusCode = (HttpStatusCode)info.GetValue("statusCode", typeof(HttpStatusCode));
 28        }
 29
 30        public HttpStatusCode StatusCode { get; private set; }
 31
 32        Type IWebFaultException.DetailType => null;
 33
 34        object IWebFaultException.DetailObject => null;
 35
 36        Type[] IWebFaultException.KnownTypes => null;
 37
 38        public override void GetObjectData(SerializationInfo info, StreamingContext context)
 39        {
 40            base.GetObjectData(info, context);
 41
 42            info.AddValue("statusCode", StatusCode);
 43        }
 44
 45        internal static FaultCode GetFaultCode(HttpStatusCode statusCode)
 46        {
 47            if ((int)statusCode >= (int)HttpStatusCode.InternalServerError)
 48            {
 49                return FaultCode.CreateReceiverFaultCode(statusCode.ToString(), WebFaultCodeNamespace);
 50            }
 51            else
 52            {
 53                return FaultCode.CreateSenderFaultCode(statusCode.ToString(), WebFaultCodeNamespace);
 54            }
 55        }
 56
 57        // These reasons come from section 6.1.1 of http://www.ietf.org/rfc/rfc2616.txt
 58        internal static string GetDefaultReason(HttpStatusCode statusCode)
 59        {
 60            switch ((int)statusCode)
 61            {
 62                case 100: return "Continue";
 63                case 101: return "Switching Protocols";
 64                case 200: return "OK";
 65                case 201: return "Created";
 66                case 202: return "Accepted";
 67                case 203: return "Non-Authoritative Information";
 68                case 204: return "No Content";
 69                case 205: return "Reset Content";
 70                case 206: return "Partial Content";
 71                case 300: return "Multiple Choices";
 72                case 301: return "Moved Permanently";
 73                case 302: return "Found";
 74                case 303: return "See Other";
 75                case 304: return "Not Modified";
 76                case 305: return "Use Proxy";
 77                case 307: return "Temporary Redirect";
 78                case 400: return "Bad Request";
 79                case 401: return "Unauthorized";
 80                case 402: return "Payment Required";
 81                case 403: return "Forbidden";
 82                case 404: return "Not Found";
 83                case 405: return "Method Not Allowed";
 84                case 406: return "Not Acceptable";
 85                case 407: return "Proxy Authentication Required";
 86                case 408: return "Request Time-out";
 87                case 409: return "Conflict";
 88                case 410: return "Gone";
 89                case 411: return "Length Required";
 90                case 412: return "Precondition Failed";
 91                case 413: return "Request Entity Too Large";
 92                case 414: return "Request-URI Too Large";
 93                case 415: return "Unsupported Media Type";
 94                case 416: return "Requested range not satisfiable";
 95                case 417: return "Expectation Failed";
 96                case 500: return "Internal Server Error";
 97                case 501: return "Not Implemented";
 98                case 502: return "Bad Gateway";
 99                case 503: return "Service Unavailable";
 100                case 504: return "Gateway Time-out";
 101                case 505: return "HTTP Version not supported";
 102                default:
 103                    {
 104                        int errorClass = ((int)statusCode) / 100;
 105                        switch (errorClass)
 106                        {
 107                            case 1: return "Informational";
 108                            case 2: return "Success";
 109                            case 3: return "Redirection";
 110                            case 4: return "Client Error";
 111                            case 5: return "Server Error";
 112                            default: return null;
 113                        }
 114                    }
 115            }
 116        }
 117    }
 118
 119    [Serializable]
 120    public class WebFaultException<T> : FaultException<T>, IWebFaultException
 121    {
 122        private Type[] _knownTypes;
 123
 124        public WebFaultException(T detail, HttpStatusCode statusCode)
 0125            : base(detail, WebFaultException.GetDefaultReason(statusCode), WebFaultException.GetFaultCode(statusCode))
 126        {
 0127            StatusCode = statusCode;
 0128        }
 129
 130        public WebFaultException(T detail, HttpStatusCode statusCode, IEnumerable<Type> knownTypes)
 0131            : base(detail, WebFaultException.GetDefaultReason(statusCode), WebFaultException.GetFaultCode(statusCode))
 132        {
 0133            StatusCode = statusCode;
 0134            _knownTypes = (knownTypes == null) ? null : new List<Type>(knownTypes).ToArray();
 0135        }
 136
 137        protected WebFaultException(SerializationInfo info, StreamingContext context)
 0138            : base(info, context)
 139        {
 0140            StatusCode = (HttpStatusCode)info.GetValue("statusCode", typeof(HttpStatusCode));
 0141            _knownTypes = (Type[])info.GetValue("knownTypes", typeof(Type[]));
 0142        }
 143
 0144        public HttpStatusCode StatusCode { get; private set; }
 145
 0146        Type IWebFaultException.DetailType => typeof(T);
 147
 0148        object IWebFaultException.DetailObject => Detail;
 149
 0150        Type[] IWebFaultException.KnownTypes => _knownTypes;
 151
 152        public override void GetObjectData(SerializationInfo info, StreamingContext context)
 153        {
 0154            base.GetObjectData(info, context);
 155
 0156            info.AddValue("statusCode", StatusCode);
 0157            info.AddValue("knownTypes", _knownTypes);
 0158        }
 159    }
 160}