< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Models.ContentDispositionOptions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Models/ContentDispositionOptions.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 48
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_FileName()100%11100%
get_Type()100%11100%
ToString()100%66100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Models/ContentDispositionOptions.cs

#LineLine coverage
 1using System.Net;
 2
 3namespace Kestrun.Models;
 4/// <summary>
 5/// Options for Content-Disposition header.
 6/// </summary>
 7public class ContentDispositionOptions
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="ContentDispositionOptions"/> class.
 11    /// </summary>
 7812    public ContentDispositionOptions()
 13    {
 7814        FileName = null;
 7815        Type = ContentDispositionType.NoContentDisposition;
 7816    }
 17
 18    /// <summary>
 19    /// Gets or sets the file name to use in the Content-Disposition header.
 20    /// </summary>
 9621    public string? FileName { get; set; }
 22    /// <summary>
 23    /// Gets or sets the type of Content-Disposition header to use.
 24    /// </summary>
 11025    public ContentDispositionType Type { get; set; }
 26
 27    /// <summary>
 28    /// Returns the Content-Disposition header value as a string, based on the type and file name.
 29    /// </summary>
 30    /// <returns>The Content-Disposition header value, or an empty string if no disposition is set.</returns>
 31    public override string ToString()
 32    {
 433        if (Type == ContentDispositionType.NoContentDisposition)
 34        {
 135            return string.Empty;
 36        }
 37
 338        var disposition = Type == ContentDispositionType.Attachment ? "attachment" : "inline";
 339        if (string.IsNullOrEmpty(FileName))
 40        {
 241            return disposition;
 42        }
 43
 44        // Escape the filename to handle special characters
 145        var escapedFileName = WebUtility.UrlEncode(FileName);
 146        return $"{disposition}; filename=\"{escapedFileName}\"";
 47    }
 48}