< Summary

Information
Class: ProjectTemplate.Web.Models.ErrorViewModel
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Models/ErrorViewModel.cs
Line coverage
80%
Covered lines: 17
Uncovered lines: 4
Coverable lines: 21
Total lines: 48
Line coverage: 80.9%
Branch coverage
50%
Covered branches: 8
Total branches: 16
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_RequestId()100%11100%
get_StatusCode()100%11100%
get_ShowRequestId()100%11100%
get_Title()50%9877.77%
get_Message()50%9877.77%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Models/ErrorViewModel.cs

#LineLine coverage
 1namespace ProjectTemplate.Web.Models;
 2
 3/// <summary>
 4/// View model for error pages that exposes request and status information.
 5/// </summary>
 6public class ErrorViewModel
 7{
 8    /// <summary>
 9    /// The unique request identifier, if available. May be null.
 10    /// </summary>
 5411    public string? RequestId { get; set; }
 12
 13    /// <summary>
 14    /// The HTTP status code associated with the error.
 15    /// </summary>
 7216    public int StatusCode { get; set; }
 17
 18    /// <summary>
 19    /// Indicates whether a request identifier should be shown.
 20    /// </summary>
 1821    public bool ShowRequestId => !string.IsNullOrWhiteSpace(RequestId);
 22
 23    /// <summary>
 24    /// A short title describing the error derived from the <see cref="StatusCode"/>.
 25    /// </summary>
 3626    public string Title => StatusCode switch
 3627    {
 1628        StatusCodes.Status400BadRequest => "Bad Request",
 829        StatusCodes.Status401Unauthorized => "Unauthorized",
 830        StatusCodes.Status403Forbidden => "Forbidden",
 431        StatusCodes.Status404NotFound => "Page Not Found",
 032        StatusCodes.Status429TooManyRequests => "Too Many Requests",
 033        _ => "Application Error"
 3634    };
 35
 36    /// <summary>
 37    /// A user-friendly message describing the error derived from the <see cref="StatusCode"/>.
 38    /// </summary>
 1839    public string Message => StatusCode switch
 1840    {
 841        StatusCodes.Status400BadRequest => "The request could not be processed.",
 442        StatusCodes.Status401Unauthorized => "Authentication is required to access this resource.",
 443        StatusCodes.Status403Forbidden => "You do not have permission to access this resource.",
 244        StatusCodes.Status404NotFound => "The requested page could not be found.",
 045        StatusCodes.Status429TooManyRequests => "Too many requests were received. Please try again later.",
 046        _ => "An unexpected error occurred while processing the request."
 1847    };
 48}