< Summary - Kestrun — Combined Coverage

Information
Class: Public.Razor.Add-KrRazorPageService
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Razor/Add-KrRazorPageService.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 77
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Razor/Add-KrRazorPageService.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds Razor Pages service to the server.
 4    .DESCRIPTION
 5        This cmdlet allows you to register Razor Pages with the Kestrun server.
 6        It can be used to serve dynamic web pages using Razor syntax.
 7    .PARAMETER Server
 8        The Kestrun server instance to which the Razor Pages service will be added.
 9    .PARAMETER Options
 10        The RazorPagesOptions to configure the Razor Pages service.
 11    .PARAMETER RootDirectory
 12        The root directory for the Razor Pages.
 13    .PARAMETER Conventions
 14        An array of page conventions to apply to the Razor Pages.
 15    .PARAMETER PassThru
 16        If specified, the cmdlet will return the modified server instance.
 17    .EXAMPLE
 18        $server | Add-KrRazorPageService -RootDirectory '/Pages' -Conventions $conventions
 19        This example adds Razor Pages service to the server, specifying the root directory and conventions for the pages
 20    .EXAMPLE
 21        $server | Add-KrRazorPageService -Options $options
 22        This example adds Razor Pages service to the server using the specified RazorPagesOptions.
 23    .LINK
 24        https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.razorpages.razorpagesoptions?view=aspnetco
 25    .NOTES
 26        This cmdlet is used to register Razor Pages with the Kestrun server, allowing you to serve dynamic web pages usi
 27#>
 28function Add-KrRazorPageService {
 29    [KestrunRuntimeApi('Definition')]
 30    [CmdletBinding(defaultParameterSetName = 'Items')]
 31    [OutputType([Kestrun.Hosting.KestrunHost])]
 32    param(
 33        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 34        [Kestrun.Hosting.KestrunHost]$Server,
 35
 36        [Parameter(Mandatory = $true, ParameterSetName = 'Options')]
 37        [Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions]$Options,
 38
 39        [Parameter(ParameterSetName = 'Items')]
 40        [string]$RootDirectory,
 41
 42        [Parameter(ParameterSetName = 'Items')]
 43        [Microsoft.AspNetCore.Mvc.ApplicationModels.IPageConvention[]]$Conventions = @(),
 44
 45        [Parameter()]
 46        [switch]$PassThru
 47    )
 48    begin {
 49        # Ensure the server instance is resolved
 050        $Server = Resolve-KestrunServer -Server $Server
 051        if ($null -eq $Server) {
 052            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 53        }
 54    }
 55    process {
 056        if ($PSCmdlet.ParameterSetName -eq 'Items') {
 057            $Options = [Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions]::new()
 058            if (-not [string]::IsNullOrWhiteSpace($RootDirectory)) {
 059                $Options.RootDirectory = $RootDirectory
 60            }
 061            if ($Conventions.Count -gt 0) {
 062                foreach ($c in $Conventions) {
 063                    $Options.Conventions.Add($c)
 64                }
 65            }
 66        }
 67
 068        [Kestrun.Hosting.KestrunHostRazorExtensions]::AddRazorPages($Server, $Options) | Out-Null
 69
 070        if ($PassThru.IsPresent) {
 71            # if the PassThru switch is specified, return the server instance
 72            # Return the modified server instance
 073            return $Server
 74        }
 75    }
 76}
 77

Methods/Properties

Add-KrRazorPageService()