< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.HelpHtmlBuilder
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/HelpHtmlBuilder.cs
Line coverage
37%
Covered lines: 17
Uncovered lines: 28
Coverable lines: 45
Total lines: 120
Line coverage: 37.7%
Branch coverage
28%
Covered branches: 4
Total branches: 14
Branch coverage: 28.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CreateServerErrorPage(...)40%101062.5%
CreateTransferRedirectPage(...)100%110%
CreateMethodNotAllowedPage(...)0%220%
CreateEndpointNotFound(...)0%220%
CreateBaseDocument(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Dispatcher/HelpHtmlBuilder.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.Linq;
 6using System.Web;
 7using System.Xml.Linq;
 8
 9namespace CoreWCF.Dispatcher
 10{
 11    internal class HelpHtmlBuilder
 12    {
 13        private const string HtmlHtmlElementName = "{http://www.w3.org/1999/xhtml}html";
 14        private const string HtmlHeadElementName = "{http://www.w3.org/1999/xhtml}head";
 15        private const string HtmlTitleElementName = "{http://www.w3.org/1999/xhtml}title";
 16        private const string HtmlBodyElementName = "{http://www.w3.org/1999/xhtml}body";
 17        private const string HtmlPElementName = "{http://www.w3.org/1999/xhtml}p";
 18        private const string HtmlDivElementName = "{http://www.w3.org/1999/xhtml}div";
 19        private const string HtmlClassAttributeName = "class";
 20        private const string HtmlIdAttributeName = "id";
 21        private const string HtmlHeading1Class = "heading1";
 22        private const string HtmlContentClass = "content";
 23
 24        public static XDocument CreateServerErrorPage(Uri helpUri, Exception error)
 25        {
 426            XDocument document = CreateBaseDocument(SR.Format(SR.HelpPageRequestErrorTitle));
 27
 428            XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
 429                new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.Format(SR.H
 430            if (helpUri == null)
 31            {
 432                if (error != null)
 33                {
 334                    div.Add(new XElement(HtmlPElementName, SR.Format(SR.HelpServerErrorProcessingRequestWithDetails, err
 335                    div.Add(new XElement(HtmlPElementName, error.StackTrace ?? String.Empty));
 36                }
 37                else
 38                {
 139                    div.Add(new XElement(HtmlPElementName, SR.Format(SR.HelpServerErrorProcessingRequest)));
 40                }
 41            }
 42            else
 43            {
 044                string encodedHelpLink = HttpUtility.HtmlEncode(helpUri.AbsoluteUri);
 045                if (error != null)
 46                {
 047                    string errorMessage = HttpUtility.HtmlEncode(error.Message);
 048                    div.Add(XElement.Parse(SR.Format(SR.HelpServerErrorProcessingRequestWithDetailsAndLink, encodedHelpL
 049                    div.Add(new XElement(HtmlPElementName, error.StackTrace ?? string.Empty));
 50                }
 51                else
 52                {
 053                    div.Add(XElement.Parse(SR.Format(SR.HelpServerErrorProcessingRequestWithLink, encodedHelpLink)));
 54                }
 55
 56            }
 57
 458            document.Descendants(HtmlBodyElementName).First().Add(div);
 459            return document;
 60        }
 61
 62        public static XDocument CreateTransferRedirectPage(string originalTo, string newLocation)
 63        {
 064            XDocument document = CreateBaseDocument(SR.HelpPageTitleText);
 65
 066            XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
 067                new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.HelpPageTit
 068                XElement.Parse(SR.Format(SR.HelpPageRedirect, HttpUtility.HtmlEncode(originalTo), HttpUtility.HtmlEncode
 069            document.Descendants(HtmlBodyElementName).First().Add(div);
 070            return document;
 71        }
 72
 73        public static XDocument CreateMethodNotAllowedPage(Uri helpUri)
 74        {
 075            XDocument document = CreateBaseDocument(SR.HelpPageTitleText);
 76
 077            XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
 078                new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.HelpPageTit
 079            if (helpUri == null)
 80            {
 081                div.Add(new XElement(HtmlPElementName, SR.HelpPageMethodNotAllowed));
 82            }
 83            else
 84            {
 085                div.Add(XElement.Parse(SR.Format(SR.HelpPageMethodNotAllowedWithLink, HttpUtility.HtmlEncode(helpUri.Abs
 86            }
 087            document.Descendants(HtmlBodyElementName).First().Add(div);
 088            return document;
 89        }
 90
 91        public static XDocument CreateEndpointNotFound(Uri helpUri)
 92        {
 093            XDocument document = CreateBaseDocument(SR.HelpPageTitleText);
 94
 095            XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
 096                new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.HelpPageTit
 097            if (helpUri == null)
 98            {
 099                div.Add(new XElement(HtmlPElementName, SR.HelpPageEndpointNotFound));
 100            }
 101            else
 102            {
 0103                div.Add(XElement.Parse(SR.Format(SR.HelpPageEndpointNotFoundWithLink, HttpUtility.HtmlEncode(helpUri.Abs
 104            }
 0105            document.Descendants(HtmlBodyElementName).First().Add(div);
 0106            return document;
 107        }
 108
 109        private static XDocument CreateBaseDocument(string title)
 110        {
 4111            return new XDocument(
 4112                new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xht
 4113                new XElement(HtmlHtmlElementName,
 4114                    new XElement(HtmlHeadElementName,
 4115                        new XElement(HtmlTitleElementName, title),
 4116                        new XElement("{http://www.w3.org/1999/xhtml}style", SR.Format(SR.HelpPageHtml))),
 4117                    new XElement(HtmlBodyElementName)));
 118        }
 119    }
 120}