From cdbfc7e26cb71122e2a1e1d8d1ada4df705d180a Mon Sep 17 00:00:00 2001 From: Friedrich Weinmann Date: Thu, 2 Jul 2026 08:33:24 +0200 Subject: [PATCH 1/2] rstimeout config validation and logging by config --- PSFramework/PSFramework.psd1 | 2 +- PSFramework/changelog.md | 6 ++ .../ComputerManagement/Invoke-PSFCommand.ps1 | 2 +- .../configuration/Export-PSFConfig.ps1 | 2 +- .../functions/configuration/Get-PSFConfig.ps1 | 2 +- .../configuration/Get-PSFConfigValue.ps1 | 2 +- .../configuration/Import-PSFConfig.ps1 | 2 +- .../configuration/Register-PSFConfig.ps1 | 2 +- .../Register-PSFConfigValidation.ps1 | 2 +- .../configuration/Reset-PSFConfig.ps1 | 2 +- .../configuration/Unregister-PSFConfig.ps1 | 2 +- .../flowcontrol/Stop-PSFFunction.ps1 | 2 +- .../flowcontrol/Test-PSFFunctionInterrupt.ps1 | 2 +- .../flowcontrol/Test-PSFParameterBinding.ps1 | 2 +- .../flowcontrol/Test-PSFPowerShell.ps1 | 2 +- .../functions/import/Import-PSFCmdlet.ps1 | 2 +- .../Register-PSFParameterClassMapping.ps1 | 2 +- .../functions/import/Set-PSFTypeAlias.ps1 | 2 +- .../functions/license/Get-PSFLicense.ps1 | 2 +- .../functions/license/New-PSFLicense.ps1 | 2 +- .../functions/license/Remove-PSFLicense.ps1 | 2 +- .../logging/Disable-PSFLoggingProvider.ps1 | 44 ++++++++++++-- .../logging/Get-PSFLoggingProvider.ps1 | 2 +- .../Get-PSFLoggingProviderInstance.ps1 | 2 +- .../logging/Install-PSFLoggingProvider.ps1 | 2 +- .../logging/Register-PSFLoggingProvider.ps1 | 2 +- .../logging/Set-PSFLoggingProvider.ps1 | 59 ++++++++++++++++++- .../functions/message/Get-PSFMessage.ps1 | 2 +- .../message/Get-PSFMessageLevelModifier.ps1 | 2 +- .../message/New-PSFMessageLevelModifier.ps1 | 2 +- .../message/Register-PSFMessageEvent.ps1 | 2 +- .../message/Register-PSFMessageTransform.ps1 | 2 +- .../Remove-PSFMessageLevelModifier.ps1 | 2 +- .../functions/message/Write-PSFHostColor.ps1 | 2 +- .../message/Write-PSFMessageProxy.ps1 | 2 +- .../resultcache/Clear-PSFresultCache.ps1 | 2 +- .../resultcache/Get-PSFResultCache.ps1 | 2 +- .../resultcache/Set-PSFResultCache.ps1 | 2 +- .../runspace/Get-PSFDynamicContentObject.ps1 | 2 +- .../functions/runspace/Get-PSFRunspace.ps1 | 2 +- .../runspace/Register-PSFRunspace.ps1 | 2 +- .../runspace/Set-PSFDynamicContentObject.ps1 | 2 +- .../functions/runspace/Start-PSFRunspace.ps1 | 2 +- .../functions/runspace/Stop-PSFRunspace.ps1 | 2 +- .../serialization/Export-PSFClixml.ps1 | 2 +- .../Get-PSFTypeSerializationData.ps1 | 2 +- .../serialization/Import-PSFClixml.ps1 | 2 +- .../Register-PSFTypeSerializationData.ps1 | 2 +- .../Register-PSFTeppArgumentCompleter.ps1 | 2 +- .../Register-PSFTeppScriptblock.ps1 | 2 +- .../tabexpansion/Set-PSFTeppResult.ps1 | 2 +- .../taskengine/Disable-PSFTaskEngineTask.ps1 | 2 +- .../taskengine/Enable-PSFTaskEngineTask.ps1 | 2 +- .../taskengine/Get-PSFTaskEngineCache.ps1 | 2 +- .../taskengine/Get-PSFTaskEngineTask.ps1 | 2 +- .../taskengine/Register-PSFTaskEngineTask.ps1 | 2 +- .../taskengine/Set-PSFTaskEngineCache.ps1 | 2 +- .../taskengine/Test-PSFTaskEngineCache.ps1 | 2 +- .../taskengine/Test-PSFTaskEngineTask.ps1 | 2 +- .../utility/New-PSFSupportPackage.ps1 | 2 +- .../Resolve-PSFDefaultParameterValue.ps1 | 2 +- .../functions/utility/Resolve-PSFPath.ps1 | 2 +- .../configurationvalidation/rstimeout.ps1 | 24 ++++++++ .../configuration/validations/bool.Tests.ps1 | 26 ++++++++ .../validations/consolecolor.Tests.ps1 | 24 ++++++++ .../validations/credential.Tests.ps1 | 28 +++++++++ .../validations/datetime.Tests.ps1 | 25 ++++++++ .../validations/double.Tests.ps1 | 25 ++++++++ .../configuration/validations/guid.Tests.ps1 | 26 ++++++++ .../validations/guidarray.Tests.ps1 | 32 ++++++++++ .../validations/integer.Tests.ps1 | 25 ++++++++ .../validations/integer0to9.Tests.ps1 | 24 ++++++++ .../validations/integer1to9.Tests.ps1 | 24 ++++++++ .../validations/integerarray.Tests.ps1 | 27 +++++++++ .../validations/integerpositive.Tests.ps1 | 24 ++++++++ .../validations/languagecode.Tests.ps1 | 25 ++++++++ .../configuration/validations/long.Tests.ps1 | 25 ++++++++ .../psframework.logfilefiletype.Tests.ps1 | 28 +++++++++ .../validations/rstimeout.Tests.ps1 | 29 +++++++++ .../validations/secret.Tests.ps1 | 28 +++++++++ .../validations/sizestyle.Tests.ps1 | 28 +++++++++ .../validations/string.Tests.ps1 | 24 ++++++++ .../validations/stringarray.Tests.ps1 | 35 +++++++++++ .../validations/timespan.Tests.ps1 | 25 ++++++++ .../validations/uriabsolute.Tests.ps1 | 25 ++++++++ .../validations/urihttp.Tests.ps1 | 25 ++++++++ 86 files changed, 791 insertions(+), 67 deletions(-) create mode 100644 PSFramework/internal/configurationvalidation/rstimeout.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/bool.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/consolecolor.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/credential.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/datetime.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/double.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/guid.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/guidarray.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/integer.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/integer0to9.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/integer1to9.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/integerarray.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/integerpositive.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/languagecode.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/long.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/psframework.logfilefiletype.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/rstimeout.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/secret.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/sizestyle.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/string.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/stringarray.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/timespan.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/uriabsolute.Tests.ps1 create mode 100644 PSFramework/tests/functions/configuration/validations/urihttp.Tests.ps1 diff --git a/PSFramework/PSFramework.psd1 b/PSFramework/PSFramework.psd1 index 6073f77d..b5ccab66 100644 --- a/PSFramework/PSFramework.psd1 +++ b/PSFramework/PSFramework.psd1 @@ -4,7 +4,7 @@ RootModule = 'PSFramework.psm1' # Version number of this module. - ModuleVersion = '1.14.454' + ModuleVersion = '1.14.457' # ID used to uniquely identify this module GUID = '8028b914-132b-431f-baa9-94a6952f21ff' diff --git a/PSFramework/changelog.md b/PSFramework/changelog.md index 4595f905..349198cf 100644 --- a/PSFramework/changelog.md +++ b/PSFramework/changelog.md @@ -1,5 +1,11 @@ # CHANGELOG +## 1.14.457 (2026-07-02) + +- New: ConfigValidation rstimeout - Validates input as a legal setting for the Runspace Workflow Worker's timeout +- Upd: Set-PSFLoggingProvider - accepts input via config set +- Upd: Disable-PSFLoggingProvider - accepts input via config set + ## 1.14.454 (2026-07-01) - New: Type PSFramework.Utility.HumanizedTimeSpan - a human-friendly duration display alternative. diff --git a/PSFramework/functions/ComputerManagement/Invoke-PSFCommand.ps1 b/PSFramework/functions/ComputerManagement/Invoke-PSFCommand.ps1 index 8f5c2c24..8296a833 100644 --- a/PSFramework/functions/ComputerManagement/Invoke-PSFCommand.ps1 +++ b/PSFramework/functions/ComputerManagement/Invoke-PSFCommand.ps1 @@ -51,7 +51,7 @@ Runs the $scriptblock against all computers in AD with a name that starts with "srv-db". #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectUsageOfAssignmentOperator", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Invoke-PSFCommand')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Invoke-PSFCommand')] param ( [PSFComputer[]] [Alias('Session')] diff --git a/PSFramework/functions/configuration/Export-PSFConfig.ps1 b/PSFramework/functions/configuration/Export-PSFConfig.ps1 index 7fbdc1e2..b33b4a7c 100644 --- a/PSFramework/functions/configuration/Export-PSFConfig.ps1 +++ b/PSFramework/functions/configuration/Export-PSFConfig.ps1 @@ -55,7 +55,7 @@ Exports all settings of the module 'MyModule' that are no longer the original default values to json. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] - [CmdletBinding(DefaultParameterSetName = 'FullName', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Export-PSFConfig')] + [CmdletBinding(DefaultParameterSetName = 'FullName', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Export-PSFConfig')] param ( [Parameter(ParameterSetName = "FullName", Position = 0, Mandatory = $true)] [string] diff --git a/PSFramework/functions/configuration/Get-PSFConfig.ps1 b/PSFramework/functions/configuration/Get-PSFConfig.ps1 index 60377914..28ac1045 100644 --- a/PSFramework/functions/configuration/Get-PSFConfig.ps1 +++ b/PSFramework/functions/configuration/Get-PSFConfig.ps1 @@ -43,7 +43,7 @@ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] [OutputType([PSFramework.Configuration.Config])] - [CmdletBinding(DefaultParameterSetName = "FullName", HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFConfig')] + [CmdletBinding(DefaultParameterSetName = "FullName", HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFConfig')] Param ( [Parameter(ParameterSetName = "FullName", Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] diff --git a/PSFramework/functions/configuration/Get-PSFConfigValue.ps1 b/PSFramework/functions/configuration/Get-PSFConfigValue.ps1 index 0b92597b..e4348b32 100644 --- a/PSFramework/functions/configuration/Get-PSFConfigValue.ps1 +++ b/PSFramework/functions/configuration/Get-PSFConfigValue.ps1 @@ -31,7 +31,7 @@ Returns the configured value for 'Default.CoffeeMilk'. If no such value is configured, it returns '0' instead. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectComparisonWithNull", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFConfigValue')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFConfigValue')] param ( [Alias('Name')] [Parameter(Mandatory = $true, Position = 0)] diff --git a/PSFramework/functions/configuration/Import-PSFConfig.ps1 b/PSFramework/functions/configuration/Import-PSFConfig.ps1 index a1f9b4ea..19229dc7 100644 --- a/PSFramework/functions/configuration/Import-PSFConfig.ps1 +++ b/PSFramework/functions/configuration/Import-PSFConfig.ps1 @@ -90,7 +90,7 @@ Imports all the module specific settings that have been persisted in any of the default file system paths. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", "")] - [CmdletBinding(DefaultParameterSetName = "Path", HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Import-PSFConfig')] + [CmdletBinding(DefaultParameterSetName = "Path", HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Import-PSFConfig')] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = "Path")] [string[]] diff --git a/PSFramework/functions/configuration/Register-PSFConfig.ps1 b/PSFramework/functions/configuration/Register-PSFConfig.ps1 index 01e676a8..9b910dd2 100644 --- a/PSFramework/functions/configuration/Register-PSFConfig.ps1 +++ b/PSFramework/functions/configuration/Register-PSFConfig.ps1 @@ -49,7 +49,7 @@ Retrieves all configuration items of the module MyModule, then registers them in registry to enforce them for all users on the current system. #> - [CmdletBinding(DefaultParameterSetName = "Default", HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFConfig')] + [CmdletBinding(DefaultParameterSetName = "Default", HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFConfig')] param ( [Parameter(ParameterSetName = "Default", Position = 0, ValueFromPipeline = $true)] [PSFramework.Configuration.Config[]] diff --git a/PSFramework/functions/configuration/Register-PSFConfigValidation.ps1 b/PSFramework/functions/configuration/Register-PSFConfigValidation.ps1 index b88dca27..82314495 100644 --- a/PSFramework/functions/configuration/Register-PSFConfigValidation.ps1 +++ b/PSFramework/functions/configuration/Register-PSFConfigValidation.ps1 @@ -26,7 +26,7 @@ Registers the scriptblock stored in $scriptblock as validation with the name IntPositive #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFConfigValidation')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFConfigValidation')] Param ( [Parameter(Mandatory = $true)] [string] diff --git a/PSFramework/functions/configuration/Reset-PSFConfig.ps1 b/PSFramework/functions/configuration/Reset-PSFConfig.ps1 index 9be22d84..d7db853b 100644 --- a/PSFramework/functions/configuration/Reset-PSFConfig.ps1 +++ b/PSFramework/functions/configuration/Reset-PSFConfig.ps1 @@ -50,7 +50,7 @@ Resets the configuration item named 'MyModule.Group.Setting1'. #> - [CmdletBinding(DefaultParameterSetName = 'Pipeline', SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Reset-PSFConfig')] + [CmdletBinding(DefaultParameterSetName = 'Pipeline', SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Reset-PSFConfig')] param ( [Parameter(ValueFromPipeline = $true, ParameterSetName = 'Pipeline')] [PSFramework.Configuration.Config[]] diff --git a/PSFramework/functions/configuration/Unregister-PSFConfig.ps1 b/PSFramework/functions/configuration/Unregister-PSFConfig.ps1 index 0c590900..612e64a5 100644 --- a/PSFramework/functions/configuration/Unregister-PSFConfig.ps1 +++ b/PSFramework/functions/configuration/Unregister-PSFConfig.ps1 @@ -52,7 +52,7 @@ Unregisters all configuration settings for the module MyModule. #> - [CmdletBinding(DefaultParameterSetName = 'Pipeline', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Unregister-PSFConfig')] + [CmdletBinding(DefaultParameterSetName = 'Pipeline', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Unregister-PSFConfig')] param ( [Parameter(ValueFromPipeline = $true, ParameterSetName = 'Pipeline')] [PSFramework.Configuration.Config[]] diff --git a/PSFramework/functions/flowcontrol/Stop-PSFFunction.ps1 b/PSFramework/functions/flowcontrol/Stop-PSFFunction.ps1 index 27403085..59b4f19e 100644 --- a/PSFramework/functions/flowcontrol/Stop-PSFFunction.ps1 +++ b/PSFramework/functions/flowcontrol/Stop-PSFFunction.ps1 @@ -130,7 +130,7 @@ In both cases, the error record added to $error will have the content of $foo added, the better to figure out what went wrong. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(DefaultParameterSetName = 'Message', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Stop-PSFFunction')] + [CmdletBinding(DefaultParameterSetName = 'Message', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Stop-PSFFunction')] param ( [Parameter(Mandatory = $true, ParameterSetName = 'Message')] [string] diff --git a/PSFramework/functions/flowcontrol/Test-PSFFunctionInterrupt.ps1 b/PSFramework/functions/flowcontrol/Test-PSFFunctionInterrupt.ps1 index 9479a3cc..7a384742 100644 --- a/PSFramework/functions/flowcontrol/Test-PSFFunctionInterrupt.ps1 +++ b/PSFramework/functions/flowcontrol/Test-PSFFunctionInterrupt.ps1 @@ -24,7 +24,7 @@ The calling function will stop if this function returns true. #> [OutputType([System.Boolean])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFFunctionInterrupt')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Test-PSFFunctionInterrupt')] Param ( ) diff --git a/PSFramework/functions/flowcontrol/Test-PSFParameterBinding.ps1 b/PSFramework/functions/flowcontrol/Test-PSFParameterBinding.ps1 index 87dee124..4884a638 100644 --- a/PSFramework/functions/flowcontrol/Test-PSFParameterBinding.ps1 +++ b/PSFramework/functions/flowcontrol/Test-PSFParameterBinding.ps1 @@ -45,7 +45,7 @@ Returns whether any of the specified parameters was not bound #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFParameterBinding')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Test-PSFParameterBinding')] Param ( [Parameter(Mandatory = $true, Position = 0)] [string[]] diff --git a/PSFramework/functions/flowcontrol/Test-PSFPowerShell.ps1 b/PSFramework/functions/flowcontrol/Test-PSFPowerShell.ps1 index 65277ad7..7ca2ef9f 100644 --- a/PSFramework/functions/flowcontrol/Test-PSFPowerShell.ps1 +++ b/PSFramework/functions/flowcontrol/Test-PSFPowerShell.ps1 @@ -62,7 +62,7 @@ Will return $false unless executed on a PowerShell 6.1 console running on windows. #> [OutputType([System.Boolean])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFPowerShell')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Test-PSFPowerShell')] param ( [Version] $PSMinVersion, diff --git a/PSFramework/functions/import/Import-PSFCmdlet.ps1 b/PSFramework/functions/import/Import-PSFCmdlet.ps1 index bdad6d8f..a3e5379b 100644 --- a/PSFramework/functions/import/Import-PSFCmdlet.ps1 +++ b/PSFramework/functions/import/Import-PSFCmdlet.ps1 @@ -35,7 +35,7 @@ Original Author: Chris Dent Link: https://www.indented.co.uk/cmdlets-without-a-dll/ #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Import-PSFCmdlet')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Import-PSFCmdlet')] param ( [Parameter(Mandatory = $true)] [String] diff --git a/PSFramework/functions/import/Register-PSFParameterClassMapping.ps1 b/PSFramework/functions/import/Register-PSFParameterClassMapping.ps1 index 3eb86156..e0c48720 100644 --- a/PSFramework/functions/import/Register-PSFParameterClassMapping.ps1 +++ b/PSFramework/functions/import/Register-PSFParameterClassMapping.ps1 @@ -33,7 +33,7 @@ - having it accept the type 'microsoft.activedirectory.management.adcomputer' - having it use the 'DNSHostName' property if available, falling back to 'Name' if necessary #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFParameterClassMapping')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFParameterClassMapping')] param ( [Parameter(Mandatory = $true)] [PSFramework.Parameter.ParameterClasses] diff --git a/PSFramework/functions/import/Set-PSFTypeAlias.ps1 b/PSFramework/functions/import/Set-PSFTypeAlias.ps1 index 9062216d..ba33f067 100644 --- a/PSFramework/functions/import/Set-PSFTypeAlias.ps1 +++ b/PSFramework/functions/import/Set-PSFTypeAlias.ps1 @@ -34,7 +34,7 @@ Creates an alias for the type 'System.IO.Path' named 'path' #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(DefaultParameterSetName = 'Name', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFTypeAlias')] + [CmdletBinding(DefaultParameterSetName = 'Name', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Set-PSFTypeAlias')] Param ( [Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'Name', ValueFromPipelineByPropertyName = $true)] [string] diff --git a/PSFramework/functions/license/Get-PSFLicense.ps1 b/PSFramework/functions/license/Get-PSFLicense.ps1 index 71033f42..74381b0a 100644 --- a/PSFramework/functions/license/Get-PSFLicense.ps1 +++ b/PSFramework/functions/license/Get-PSFLicense.ps1 @@ -32,7 +32,7 @@ Returns a list of all registered licenses for products that have commercial licenses and are libraries. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] - [CmdletBinding(PositionalBinding = $false, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFLicense')] + [CmdletBinding(PositionalBinding = $false, HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFLicense')] [OutputType([PSFramework.License.License])] param ( [Parameter(Position = 0)] diff --git a/PSFramework/functions/license/New-PSFLicense.ps1 b/PSFramework/functions/license/New-PSFLicense.ps1 index 7c66a386..b096cab8 100644 --- a/PSFramework/functions/license/New-PSFLicense.ps1 +++ b/PSFramework/functions/license/New-PSFLicense.ps1 @@ -80,7 +80,7 @@ This registers the Awesome Test Product as licensed under the common FreeBSD license. #> - [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/New-PSFLicense')] + [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/New-PSFLicense')] [OutputType([PSFramework.License.License])] param ( diff --git a/PSFramework/functions/license/Remove-PSFLicense.ps1 b/PSFramework/functions/license/Remove-PSFLicense.ps1 index 31cb3dc3..b3bbcd3f 100644 --- a/PSFramework/functions/license/Remove-PSFLicense.ps1 +++ b/PSFramework/functions/license/Remove-PSFLicense.ps1 @@ -25,7 +25,7 @@ Removes the license for the product "FooBar" from the license store. #> - [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Remove-PSFLicense')] + [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Remove-PSFLicense')] Param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [PSFramework.License.License[]] diff --git a/PSFramework/functions/logging/Disable-PSFLoggingProvider.ps1 b/PSFramework/functions/logging/Disable-PSFLoggingProvider.ps1 index f57ac2c8..a2170da3 100644 --- a/PSFramework/functions/logging/Disable-PSFLoggingProvider.ps1 +++ b/PSFramework/functions/logging/Disable-PSFLoggingProvider.ps1 @@ -19,6 +19,11 @@ .PARAMETER InstanceObject A full Logging Provider Instance object, as return by Get-PSFLoggingProviderInstance + + .PARAMETER Config + One or more configuration objects to disable. + Each entry must provide the provider Name and may include a specific InstanceName. + All other settings are ignored. .PARAMETER NoFinalizeWait Do not wait for the logging to conclude or the final events shutting down the provider instance to finish. @@ -50,7 +55,13 @@ .EXAMPLE PS C:\> Get-PSFLoggingProviderInstance | Disable-PSFLoggingProvider - Disables all active logging provider instacnes + Disables all active logging provider instances + + .EXAMPLE + PS C:\> Disable-PSFLoggingProvider -Config $config.Logging + + Disables all logging provider instances defined in $config.Logging + This allows convenient logging configuration from a config file - it takes the same config data Set-PSFLoggingProvider accepts. #> [CmdletBinding(DefaultParameterSetName = 'ByName')] param ( @@ -70,6 +81,10 @@ [PSFramework.Logging.ProviderInstance[]] $InstanceObject, + [Parameter(Mandatory = $true, ParameterSetName = 'ByConfig')] + [object[]] + $Config, + [switch] $NoFinalizeWait ) @@ -86,19 +101,36 @@ $instance.NotAfter = $limit } - foreach ($instance in $instances) { - $instance.Drain((-not $NoFinalizeWait)) - } + $null = $inInstances.Add($instance) } foreach ($instance in $InstanceObject) { $instance.NotAfter = $limit $null = $inInstances.Add($instance) } + + foreach ($entry in $Config) { + if ($null -eq $entry) { continue } + $param = $entry | ConvertTo-PSFHashtable -Include Name, InstanceName -Remap ([ordered]@{ Name = 'ProviderName'; InstanceName = 'Name' }) + if (-not $param.Name) { $param.Name = 'Default' } + + $instances = Get-PSFLoggingProviderInstance @param + + foreach ($instance in $instances) { + $instance.NotAfter = $limit + } + + $null = $inInstances.Add($instance) + } } end { + # Prevent duplicate draining + $drained = [System.Collections.ArrayList]@() + foreach ($instance in $inInstances) { - $instance.Drain((-not $NoFinalizeWait)) - } + if ($instance -in $drained) { continue } + $instance.Drain((-not $NoFinalizeWait)) + $null = $drained.Add($instance) + } } } \ No newline at end of file diff --git a/PSFramework/functions/logging/Get-PSFLoggingProvider.ps1 b/PSFramework/functions/logging/Get-PSFLoggingProvider.ps1 index 8820ffc5..5dd2ba3d 100644 --- a/PSFramework/functions/logging/Get-PSFLoggingProvider.ps1 +++ b/PSFramework/functions/logging/Get-PSFLoggingProvider.ps1 @@ -25,7 +25,7 @@ Returns the filesystem provider #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFLoggingProvider')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFLoggingProvider')] [OutputType([PSFramework.Logging.Provider])] Param ( [Alias('Provider', 'ProviderName')] diff --git a/PSFramework/functions/logging/Get-PSFLoggingProviderInstance.ps1 b/PSFramework/functions/logging/Get-PSFLoggingProviderInstance.ps1 index 13cf8372..0ab9e651 100644 --- a/PSFramework/functions/logging/Get-PSFLoggingProviderInstance.ps1 +++ b/PSFramework/functions/logging/Get-PSFLoggingProviderInstance.ps1 @@ -32,7 +32,7 @@ Returns all logging provider instances - enabled or not - of the logfile provider #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFLoggingProvider')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFLoggingProvider')] [OutputType([PSFramework.Logging.Provider])] param ( [string] diff --git a/PSFramework/functions/logging/Install-PSFLoggingProvider.ps1 b/PSFramework/functions/logging/Install-PSFLoggingProvider.ps1 index 1b1b9edb..958734ce 100644 --- a/PSFramework/functions/logging/Install-PSFLoggingProvider.ps1 +++ b/PSFramework/functions/logging/Install-PSFLoggingProvider.ps1 @@ -33,7 +33,7 @@ Installs a logging provider named 'eventlog' #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Install-PSFLoggingProvider')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Install-PSFLoggingProvider')] param ( [Alias('Provider', 'ProviderName')] [string] diff --git a/PSFramework/functions/logging/Register-PSFLoggingProvider.ps1 b/PSFramework/functions/logging/Register-PSFLoggingProvider.ps1 index 618b30d2..03d3a347 100644 --- a/PSFramework/functions/logging/Register-PSFLoggingProvider.ps1 +++ b/PSFramework/functions/logging/Register-PSFLoggingProvider.ps1 @@ -145,7 +145,7 @@ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] [PSFramework.PSFCore.NoJeaCommandAttribute()] - [CmdletBinding(DefaultParameterSetName = 'Version1', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFLoggingProvider')] + [CmdletBinding(DefaultParameterSetName = 'Version1', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFLoggingProvider')] param ( [Parameter(Mandatory = $true)] [string] diff --git a/PSFramework/functions/logging/Set-PSFLoggingProvider.ps1 b/PSFramework/functions/logging/Set-PSFLoggingProvider.ps1 index 94533913..ff398dec 100644 --- a/PSFramework/functions/logging/Set-PSFLoggingProvider.ps1 +++ b/PSFramework/functions/logging/Set-PSFLoggingProvider.ps1 @@ -13,6 +13,12 @@ .PARAMETER Name The name of the provider to configure + + .PARAMETER Config + One or more configuration objects to apply. + Each entry must provide the provider Name and may include any other supported settings, + such as Enabled, InstanceName, filtering rules, or provider-specific dynamic parameters. + When Enabled is omitted, it defaults to $true. .PARAMETER InstanceName A description of the InstanceName parameter. @@ -102,60 +108,88 @@ PS C:\> Set-PSFLoggingProvider -Name filesystem -ExcludeModules "PSFramework" Prevents all messages from the PSFramework module to be logged to the file system + + .EXAMPLE + PS C:\> $config = @( + >> @{ Name = 'logfile'; MaxLevel = 3; FilePath = 'C:\Logs\MyScript\Task-%date%.csv' } + >> @{ Name = 'eventlog'; ExcludeModules = 'PSFramework'; MaxLevel = 5; LogName = 'Contoso'; Source = 'MyTask' } + >> ) + PS C:\> Set-PSFLoggingProvider -Config $config -Wait + + Applies mixed provider configurations (logfile + eventlog) in sequence using configuration objects. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFLoggingProvider')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Set-PSFLoggingProvider')] param ( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true, ParameterSetName = 'ByName')] [ValidateNotNullOrEmpty()] [Alias('Provider', 'ProviderName')] [string] $Name, + + [Parameter(Mandatory = $true, ParameterSetName = 'ByConfig')] + [object[]] + $Config, + [Parameter(ParameterSetName = 'ByName')] [string] $InstanceName, + [Parameter(ParameterSetName = 'ByName')] [bool] $Enabled, + [Parameter(ParameterSetName = 'ByName')] [string[]] $IncludeModules, + [Parameter(ParameterSetName = 'ByName')] [string[]] $ExcludeModules, + [Parameter(ParameterSetName = 'ByName')] [string[]] $IncludeFunctions, + [Parameter(ParameterSetName = 'ByName')] [string[]] $ExcludeFunctions, + [Parameter(ParameterSetName = 'ByName')] [guid[]] $IncludeRunspaces, + [Parameter(ParameterSetName = 'ByName')] [guid[]] $ExcludeRunspaces, + [Parameter(ParameterSetName = 'ByName')] [string[]] $IncludeTags, + [Parameter(ParameterSetName = 'ByName')] [string[]] $ExcludeTags, + [Parameter(ParameterSetName = 'ByName')] [ValidateRange(1,9)] [int] $MinLevel, + [Parameter(ParameterSetName = 'ByName')] [ValidateRange(1, 9)] [int] $MaxLevel, + [Parameter(ParameterSetName = 'ByName')] [switch] $RequiresInclude, + [Parameter(ParameterSetName = 'ByName')] [switch] $ExcludeWarning, + [Parameter(ParameterSetName = 'ByName')] [switch] $ExcludeError, @@ -194,6 +228,9 @@ begin { + # Skip to Process for define by configuration + if (-not $Name) { return } + if (-not ([PSFramework.Logging.ProviderHost]::Providers.ContainsKey($Name))) { Stop-PSFFunction -String 'Set-PSFLoggingProvider.Provider.NotFound' -StringValues $Name -EnableException $EnableException -Category InvalidArgument -Target $Name @@ -218,6 +255,24 @@ process { if (Test-PSFFunctionInterrupt) { return } + + #region Case: Define by Configuration + if (-not $Name) { + $last = @($Config | Where-Object { $_ })[-1] + foreach ($entry in $Config) { + if ($null -eq $entry) { continue } + $params = $entry | ConvertTo-PSFHashtable + if (-not $params.Name) { + Stop-PSFFunction -String 'Set-PSFLoggingProvider.Error.ConfigNoName' -StringValues $params -EnableException $EnableException -Category InvalidArgument -Target $entry + } + if ($params.Keys -notcontains 'Enabled') { $params.Enabled = $true } + if ($Wait -and $entry -eq $last) { $params.Wait = $true } + if ($EnableException) { $params.EnableException = $EnableException } + Set-PSFLoggingProvider @params + } + return + } + #endregion Case: Define by Configuration $provider.ConfigurationScript.InvokeGlobal($PSBoundParameters) diff --git a/PSFramework/functions/message/Get-PSFMessage.ps1 b/PSFramework/functions/message/Get-PSFMessage.ps1 index 031d285f..e96f4ea3 100644 --- a/PSFramework/functions/message/Get-PSFMessage.ps1 +++ b/PSFramework/functions/message/Get-PSFMessage.ps1 @@ -65,7 +65,7 @@ Returns all log entries within the last 5 executions that contained the tag "fail" #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFMessage')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFMessage')] param ( [string] $FunctionName = "*", diff --git a/PSFramework/functions/message/Get-PSFMessageLevelModifier.ps1 b/PSFramework/functions/message/Get-PSFMessageLevelModifier.ps1 index 075993d6..d951bea5 100644 --- a/PSFramework/functions/message/Get-PSFMessageLevelModifier.ps1 +++ b/PSFramework/functions/message/Get-PSFMessageLevelModifier.ps1 @@ -23,7 +23,7 @@ Returns all message level filters that start with "mymodule." #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFMessageLevelModifier')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFMessageLevelModifier')] Param ( [string] $Name = "*" diff --git a/PSFramework/functions/message/New-PSFMessageLevelModifier.ps1 b/PSFramework/functions/message/New-PSFMessageLevelModifier.ps1 index 1cd0aedc..cf8f403f 100644 --- a/PSFramework/functions/message/New-PSFMessageLevelModifier.ps1 +++ b/PSFramework/functions/message/New-PSFMessageLevelModifier.ps1 @@ -61,7 +61,7 @@ This is useful when prioritizing your own module during development. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/New-PSFMessageLevelModifier')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/New-PSFMessageLevelModifier')] param ( [Parameter(Mandatory = $true)] [string] diff --git a/PSFramework/functions/message/Register-PSFMessageEvent.ps1 b/PSFramework/functions/message/Register-PSFMessageEvent.ps1 index a73fbc56..570a0945 100644 --- a/PSFramework/functions/message/Register-PSFMessageEvent.ps1 +++ b/PSFramework/functions/message/Register-PSFMessageEvent.ps1 @@ -59,7 +59,7 @@ - To execute $ScriptBlock ... - Whenever a message is written with the tag 'engine' by the module 'MyModule' at the level 'Warning' #> - [CmdletBinding(PositionalBinding = $false, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFMessageEvent')] + [CmdletBinding(PositionalBinding = $false, HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFMessageEvent')] Param ( [Parameter(Mandatory = $true)] [string] diff --git a/PSFramework/functions/message/Register-PSFMessageTransform.ps1 b/PSFramework/functions/message/Register-PSFMessageTransform.ps1 index 4ef77416..32c5d1cf 100644 --- a/PSFramework/functions/message/Register-PSFMessageTransform.ps1 +++ b/PSFramework/functions/message/Register-PSFMessageTransform.ps1 @@ -73,7 +73,7 @@ Adds a transform for all target objects that are of a type whose full name starts with 'mymodule.category.' All target objects matching that typename will be run through the specified scriptblock, which in return generates the new target object. #> - [CmdletBinding(PositionalBinding = $false, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFMessageTransform')] + [CmdletBinding(PositionalBinding = $false, HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFMessageTransform')] Param ( [Parameter(Mandatory = $true, ParameterSetName = "Target")] [string] diff --git a/PSFramework/functions/message/Remove-PSFMessageLevelModifier.ps1 b/PSFramework/functions/message/Remove-PSFMessageLevelModifier.ps1 index c3e77c8e..52761c0e 100644 --- a/PSFramework/functions/message/Remove-PSFMessageLevelModifier.ps1 +++ b/PSFramework/functions/message/Remove-PSFMessageLevelModifier.ps1 @@ -31,7 +31,7 @@ Removes the message level modifier named "mymodule.foo" #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Remove-PSFMessageLevelModifier')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Remove-PSFMessageLevelModifier')] Param ( [Parameter(ValueFromPipeline = $true)] [string[]] diff --git a/PSFramework/functions/message/Write-PSFHostColor.ps1 b/PSFramework/functions/message/Write-PSFHostColor.ps1 index 8561e7ea..9909da2e 100644 --- a/PSFramework/functions/message/Write-PSFHostColor.ps1 +++ b/PSFramework/functions/message/Write-PSFHostColor.ps1 @@ -62,7 +62,7 @@ Will print a long multiline text in its entirety while still respecting the colorcodes #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Write-PSFHostColor')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Write-PSFHostColor')] param ( [Parameter(ValueFromPipeline = $true)] [string[]] diff --git a/PSFramework/functions/message/Write-PSFMessageProxy.ps1 b/PSFramework/functions/message/Write-PSFMessageProxy.ps1 index 8cdddbfd..9f103264 100644 --- a/PSFramework/functions/message/Write-PSFMessageProxy.ps1 +++ b/PSFramework/functions/message/Write-PSFMessageProxy.ps1 @@ -44,7 +44,7 @@ Then it will write the message "Example Message", which is automatically written to Level "Important" (which by default will be written to host). #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Write-PSFMessageProxy')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Write-PSFMessageProxy')] param ( [Parameter(Position = 0)] [Alias('Object', 'MessageData')] diff --git a/PSFramework/functions/resultcache/Clear-PSFresultCache.ps1 b/PSFramework/functions/resultcache/Clear-PSFresultCache.ps1 index d7a69bbc..3389f9f7 100644 --- a/PSFramework/functions/resultcache/Clear-PSFresultCache.ps1 +++ b/PSFramework/functions/resultcache/Clear-PSFresultCache.ps1 @@ -18,7 +18,7 @@ Clears the result cache, freeing up any used memory. #> - [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Clear-PSFresultCache')] + [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Clear-PSFresultCache')] param ( ) diff --git a/PSFramework/functions/resultcache/Get-PSFResultCache.ps1 b/PSFramework/functions/resultcache/Get-PSFResultCache.ps1 index 2975aa67..1266714a 100644 --- a/PSFramework/functions/resultcache/Get-PSFResultCache.ps1 +++ b/PSFramework/functions/resultcache/Get-PSFResultCache.ps1 @@ -26,7 +26,7 @@ Returns a meta-information object containing the last result, when it was written and which function did the writing. #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFResultCache')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFResultCache')] param ( [ValidateSet('Value','All')] [string] diff --git a/PSFramework/functions/resultcache/Set-PSFResultCache.ps1 b/PSFramework/functions/resultcache/Set-PSFResultCache.ps1 index ad4cc4a3..10e37f27 100644 --- a/PSFramework/functions/resultcache/Set-PSFResultCache.ps1 +++ b/PSFramework/functions/resultcache/Set-PSFResultCache.ps1 @@ -36,7 +36,7 @@ This will return all objects, even if $NoRes is set to $True. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFResultCache')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Set-PSFResultCache')] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] diff --git a/PSFramework/functions/runspace/Get-PSFDynamicContentObject.ps1 b/PSFramework/functions/runspace/Get-PSFDynamicContentObject.ps1 index 512056b9..cec38f73 100644 --- a/PSFramework/functions/runspace/Get-PSFDynamicContentObject.ps1 +++ b/PSFramework/functions/runspace/Get-PSFDynamicContentObject.ps1 @@ -26,7 +26,7 @@ Returns the Dynamic Content Object named "test" #> [OutputType([PSFramework.Utility.DynamicContentObject])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFDynamicContentObject')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFDynamicContentObject')] Param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string[]] diff --git a/PSFramework/functions/runspace/Get-PSFRunspace.ps1 b/PSFramework/functions/runspace/Get-PSFRunspace.ps1 index b16a3798..9e28848d 100644 --- a/PSFramework/functions/runspace/Get-PSFRunspace.ps1 +++ b/PSFramework/functions/runspace/Get-PSFRunspace.ps1 @@ -21,7 +21,7 @@ Returns the runspace registered under the name 'mymodule.maintenance' #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFRunspace')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFRunspace')] Param ( [string] $Name = "*" diff --git a/PSFramework/functions/runspace/Register-PSFRunspace.ps1 b/PSFramework/functions/runspace/Register-PSFRunspace.ps1 index 9f7670e1..d6a69a47 100644 --- a/PSFramework/functions/runspace/Register-PSFRunspace.ps1 +++ b/PSFramework/functions/runspace/Register-PSFRunspace.ps1 @@ -71,7 +71,7 @@ Creates a background runspace that can never exist more than once in the current process. It will clean all items under $env:TEMP that start with "MyModule-" every 30 seconds (plus 250ms, which are added by the system). #> - [CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'Gen2', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFRunspace')] + [CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'Gen2', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFRunspace')] param ( [Parameter(Mandatory = $true)] diff --git a/PSFramework/functions/runspace/Set-PSFDynamicContentObject.ps1 b/PSFramework/functions/runspace/Set-PSFDynamicContentObject.ps1 index f4db4f71..580480fd 100644 --- a/PSFramework/functions/runspace/Set-PSFDynamicContentObject.ps1 +++ b/PSFramework/functions/runspace/Set-PSFDynamicContentObject.ps1 @@ -66,7 +66,7 @@ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] [OutputType([PSFramework.Utility.DynamicContentObject])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFDynamicContentObject')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Set-PSFDynamicContentObject')] Param ( [string[]] $Name, diff --git a/PSFramework/functions/runspace/Start-PSFRunspace.ps1 b/PSFramework/functions/runspace/Start-PSFRunspace.ps1 index 6b511e9d..f3fbed46 100644 --- a/PSFramework/functions/runspace/Start-PSFRunspace.ps1 +++ b/PSFramework/functions/runspace/Start-PSFRunspace.ps1 @@ -33,7 +33,7 @@ Starts the runspace registered under the name 'mymodule.maintenance' #> - [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Start-PSFRunspace')] + [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Start-PSFRunspace')] param ( [Parameter(ValueFromPipeline = $true)] [string[]] diff --git a/PSFramework/functions/runspace/Stop-PSFRunspace.ps1 b/PSFramework/functions/runspace/Stop-PSFRunspace.ps1 index d5ed890f..1760aaaa 100644 --- a/PSFramework/functions/runspace/Stop-PSFRunspace.ps1 +++ b/PSFramework/functions/runspace/Stop-PSFRunspace.ps1 @@ -39,7 +39,7 @@ .NOTES Additional information about the function. #> - [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Stop-PSFRunspace')] + [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Stop-PSFRunspace')] param ( [Parameter(ValueFromPipeline = $true)] [string[]] diff --git a/PSFramework/functions/serialization/Export-PSFClixml.ps1 b/PSFramework/functions/serialization/Export-PSFClixml.ps1 index e0311f79..737f563b 100644 --- a/PSFramework/functions/serialization/Export-PSFClixml.ps1 +++ b/PSFramework/functions/serialization/Export-PSFClixml.ps1 @@ -44,7 +44,7 @@ Exports a list of all items in the current path as a default clixml readable by Import-Clixml #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Export-PSFClixml')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Export-PSFClixml')] param ( [PsfValidateScript('PSFramework.Validate.FSPath.FileOrParent', ErrorString = 'PSFramework.Validate.FSPath.FileOrParent')] [Parameter(Mandatory = $true, Position = 0)] diff --git a/PSFramework/functions/serialization/Get-PSFTypeSerializationData.ps1 b/PSFramework/functions/serialization/Get-PSFTypeSerializationData.ps1 index 0f2e3170..b363f36e 100644 --- a/PSFramework/functions/serialization/Get-PSFTypeSerializationData.ps1 +++ b/PSFramework/functions/serialization/Get-PSFTypeSerializationData.ps1 @@ -46,7 +46,7 @@ Generates an XML text that can be used to register via Update-TypeData. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectUsageOfAssignmentOperator", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFTypeSerializationData')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFTypeSerializationData')] Param ( [Parameter(ValueFromPipeline = $true)] [object[]] diff --git a/PSFramework/functions/serialization/Import-PSFClixml.ps1 b/PSFramework/functions/serialization/Import-PSFClixml.ps1 index bb4a15f6..2fcff3a2 100644 --- a/PSFramework/functions/serialization/Import-PSFClixml.ps1 +++ b/PSFramework/functions/serialization/Import-PSFClixml.ps1 @@ -21,7 +21,7 @@ Imports the objects serialized to object.xml in the current folder. #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Import-PSFClixml')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Import-PSFClixml')] param ( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Alias('FullName')] diff --git a/PSFramework/functions/serialization/Register-PSFTypeSerializationData.ps1 b/PSFramework/functions/serialization/Register-PSFTypeSerializationData.ps1 index 8255e525..366c6e28 100644 --- a/PSFramework/functions/serialization/Register-PSFTypeSerializationData.ps1 +++ b/PSFramework/functions/serialization/Register-PSFTypeSerializationData.ps1 @@ -24,7 +24,7 @@ Generates a custom type serialization xml and registers it. #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFTypeSerializationData')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFTypeSerializationData')] Param ( [Parameter(ValueFromPipeline = $true, Mandatory = $true)] [string[]] diff --git a/PSFramework/functions/tabexpansion/Register-PSFTeppArgumentCompleter.ps1 b/PSFramework/functions/tabexpansion/Register-PSFTeppArgumentCompleter.ps1 index fa2c66e1..c29f55ed 100644 --- a/PSFramework/functions/tabexpansion/Register-PSFTeppArgumentCompleter.ps1 +++ b/PSFramework/functions/tabexpansion/Register-PSFTeppArgumentCompleter.ps1 @@ -23,7 +23,7 @@ Registers the parameter 'Example' of the command 'Get-Test' to receive the tab completion registered to 'MyModule.Example' #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFTeppArgumentCompleter')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFTeppArgumentCompleter')] Param ( [Parameter(Mandatory = $true)] [string[]] diff --git a/PSFramework/functions/tabexpansion/Register-PSFTeppScriptblock.ps1 b/PSFramework/functions/tabexpansion/Register-PSFTeppScriptblock.ps1 index 56a01fe1..076c28d4 100644 --- a/PSFramework/functions/tabexpansion/Register-PSFTeppScriptblock.ps1 +++ b/PSFramework/functions/tabexpansion/Register-PSFTeppScriptblock.ps1 @@ -82,7 +82,7 @@ Stores a simple scriptblock that will return a list of strings under the name "mymodule-scripts". The system will wrap all the stuff around this that is necessary to provide Tab Expansion and filter out output that doesn't fit the user input so far. #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFTeppScriptblock')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFTeppScriptblock')] Param ( [Parameter(Mandatory = $true)] [System.Management.Automation.ScriptBlock] diff --git a/PSFramework/functions/tabexpansion/Set-PSFTeppResult.ps1 b/PSFramework/functions/tabexpansion/Set-PSFTeppResult.ps1 index 662c6dbe..a74a5e20 100644 --- a/PSFramework/functions/tabexpansion/Set-PSFTeppResult.ps1 +++ b/PSFramework/functions/tabexpansion/Set-PSFTeppResult.ps1 @@ -27,7 +27,7 @@ Stores the names of all computers in AD into the tab completion cache of the completion scriptblock 'MyModule.Computer' #> - [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFTeppResult')] + [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low', HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Set-PSFTeppResult')] param ( [Parameter(Mandatory = $true)] [PSFramework.Validation.PsfValidateSetAttribute(ScriptBlock = { [PSFramework.TabExpansion.TabExpansionHost]::Scripts.Keys } )] diff --git a/PSFramework/functions/taskengine/Disable-PSFTaskEngineTask.ps1 b/PSFramework/functions/taskengine/Disable-PSFTaskEngineTask.ps1 index 63d5e142..803e7f2d 100644 --- a/PSFramework/functions/taskengine/Disable-PSFTaskEngineTask.ps1 +++ b/PSFramework/functions/taskengine/Disable-PSFTaskEngineTask.ps1 @@ -18,7 +18,7 @@ Disables the task named 'mymodule.maintenance' #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Disable-PSFTaskEngineTask')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Disable-PSFTaskEngineTask')] param ( [string[]] $Name, diff --git a/PSFramework/functions/taskengine/Enable-PSFTaskEngineTask.ps1 b/PSFramework/functions/taskengine/Enable-PSFTaskEngineTask.ps1 index c215470b..97723dc2 100644 --- a/PSFramework/functions/taskengine/Enable-PSFTaskEngineTask.ps1 +++ b/PSFramework/functions/taskengine/Enable-PSFTaskEngineTask.ps1 @@ -21,7 +21,7 @@ Enables the task named 'mymodule.maintenance' #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Enable-PSFTaskEngineTask')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Enable-PSFTaskEngineTask')] param ( [string[]] $Name, diff --git a/PSFramework/functions/taskengine/Get-PSFTaskEngineCache.ps1 b/PSFramework/functions/taskengine/Get-PSFTaskEngineCache.ps1 index 821d0bfe..5691633f 100644 --- a/PSFramework/functions/taskengine/Get-PSFTaskEngineCache.ps1 +++ b/PSFramework/functions/taskengine/Get-PSFTaskEngineCache.ps1 @@ -23,7 +23,7 @@ Retrieves the information stored under 'mymodule.maintenancetask' #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFTaskEngineCache')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFTaskEngineCache')] Param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/PSFramework/functions/taskengine/Get-PSFTaskEngineTask.ps1 b/PSFramework/functions/taskengine/Get-PSFTaskEngineTask.ps1 index 7d3d281d..e708cc42 100644 --- a/PSFramework/functions/taskengine/Get-PSFTaskEngineTask.ps1 +++ b/PSFramework/functions/taskengine/Get-PSFTaskEngineTask.ps1 @@ -22,7 +22,7 @@ Returns all tasks registered to the task engine whose name starts with 'mymodule.' (It stands to reason that only tasks belonging to the module 'mymodule' would be returned that way) #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Get-PSFTaskEngineTask')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Get-PSFTaskEngineTask')] Param ( [string] $Name = "*" diff --git a/PSFramework/functions/taskengine/Register-PSFTaskEngineTask.ps1 b/PSFramework/functions/taskengine/Register-PSFTaskEngineTask.ps1 index f05bdfcd..4155ba43 100644 --- a/PSFramework/functions/taskengine/Register-PSFTaskEngineTask.ps1 +++ b/PSFramework/functions/taskengine/Register-PSFTaskEngineTask.ps1 @@ -66,7 +66,7 @@ - Sets it to wait for 1 minute after registration before starting the first execution - Sets it to priority "Critical", ensuring it takes precedence over most other tasks. #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Register-PSFTaskEngineTask')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Register-PSFTaskEngineTask')] param ( [Parameter(Mandatory = $true)] [string] diff --git a/PSFramework/functions/taskengine/Set-PSFTaskEngineCache.ps1 b/PSFramework/functions/taskengine/Set-PSFTaskEngineCache.ps1 index 72219e16..b61a5063 100644 --- a/PSFramework/functions/taskengine/Set-PSFTaskEngineCache.ps1 +++ b/PSFramework/functions/taskengine/Set-PSFTaskEngineCache.ps1 @@ -48,7 +48,7 @@ Registers a cache that lists all domain controllers in the current domain, keeping the data valid for 8 hours before refreshing it. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Set-PSFTaskEngineCache')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Set-PSFTaskEngineCache')] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/PSFramework/functions/taskengine/Test-PSFTaskEngineCache.ps1 b/PSFramework/functions/taskengine/Test-PSFTaskEngineCache.ps1 index c74daca8..c87f842e 100644 --- a/PSFramework/functions/taskengine/Test-PSFTaskEngineCache.ps1 +++ b/PSFramework/functions/taskengine/Test-PSFTaskEngineCache.ps1 @@ -23,7 +23,7 @@ Does not require the cache to actually contain a value, but must exist. #> [OutputType([System.Boolean])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFTaskEngineCache')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Test-PSFTaskEngineCache')] Param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] diff --git a/PSFramework/functions/taskengine/Test-PSFTaskEngineTask.ps1 b/PSFramework/functions/taskengine/Test-PSFTaskEngineTask.ps1 index dcbe69cc..9631a52d 100644 --- a/PSFramework/functions/taskengine/Test-PSFTaskEngineTask.ps1 +++ b/PSFramework/functions/taskengine/Test-PSFTaskEngineTask.ps1 @@ -17,7 +17,7 @@ Returns, whether the task named 'mymodule.maintenance' has already been executed at least once. #> [OutputType([System.Boolean])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Test-PSFTaskEngineTask')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Test-PSFTaskEngineTask')] Param ( [Parameter(Mandatory = $true)] [string] diff --git a/PSFramework/functions/utility/New-PSFSupportPackage.ps1 b/PSFramework/functions/utility/New-PSFSupportPackage.ps1 index cbf6aa9a..36b4bb3c 100644 --- a/PSFramework/functions/utility/New-PSFSupportPackage.ps1 +++ b/PSFramework/functions/utility/New-PSFSupportPackage.ps1 @@ -80,7 +80,7 @@ #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", "")] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/New-PSFSupportPackage', DefaultParameterSetName = 'Path')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/New-PSFSupportPackage', DefaultParameterSetName = 'Path')] param ( [Parameter(ParameterSetName = 'Path')] [string] diff --git a/PSFramework/functions/utility/Resolve-PSFDefaultParameterValue.ps1 b/PSFramework/functions/utility/Resolve-PSFDefaultParameterValue.ps1 index c1178f2f..ab5f8e86 100644 --- a/PSFramework/functions/utility/Resolve-PSFDefaultParameterValue.ps1 +++ b/PSFramework/functions/utility/Resolve-PSFDefaultParameterValue.ps1 @@ -28,7 +28,7 @@ Returns a hashtable containing all default parameter values in the global scope affecting the command 'Invoke-WebRequest'. #> [OutputType([System.Collections.Hashtable])] - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Resolve-PSFDefaultParameterValue')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Resolve-PSFDefaultParameterValue')] param ( [Parameter(Mandatory = $true)] [System.Collections.Hashtable] diff --git a/PSFramework/functions/utility/Resolve-PSFPath.ps1 b/PSFramework/functions/utility/Resolve-PSFPath.ps1 index fe737ec9..751fb47c 100644 --- a/PSFramework/functions/utility/Resolve-PSFPath.ps1 +++ b/PSFramework/functions/utility/Resolve-PSFPath.ps1 @@ -39,7 +39,7 @@ This will resolve all items in the parent folder, whatever the current path or drive might be. #> - [CmdletBinding(HelpUri = 'https://psframework.org/documentation/commands/PSFramework/Resolve-PSFPath')] + [CmdletBinding(HelpUri = 'https://psframework.org/docs/Commands/PSFramework/Resolve-PSFPath')] param ( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [string[]] diff --git a/PSFramework/internal/configurationvalidation/rstimeout.ps1 b/PSFramework/internal/configurationvalidation/rstimeout.ps1 new file mode 100644 index 00000000..795c62f1 --- /dev/null +++ b/PSFramework/internal/configurationvalidation/rstimeout.ps1 @@ -0,0 +1,24 @@ +Register-PSFConfigValidation -Name "rstimeout" -ScriptBlock { + Param ( + $Value + ) + + $Result = [PSCustomObject]@{ + Success = $True + Value = $null + Message = "" + } + + $textValue = "$Value" + $legal = [enum]::GetNames([PSFramework.Runspace.RSTimeout]) | Where-Object { $_ -ne 'Undefined' } + + if ($legal -notcontains $textValue) { + $Result.Message = "Not a runspace workflow timeout setting: $Value" + $Result.Success = $False + return $Result + } + + $Result.Value = $textValue -as [PSFramework.Runspace.RSTimeout] + + return $Result +} \ No newline at end of file diff --git a/PSFramework/tests/functions/configuration/validations/bool.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/bool.Tests.ps1 new file mode 100644 index 00000000..36d9dfee --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/bool.Tests.ps1 @@ -0,0 +1,26 @@ +Describe "bool config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.bool' + Set-PSFConfig -FullName $script:fullName -Value $false -Validation 'bool' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value $true -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $true + } + + It "accepts values that require conversion" { + $switchValue = [System.Management.Automation.SwitchParameter]::new($true) + { Set-PSFConfig -FullName $script:fullName -Value $switchValue -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).GetType().FullName | Should -Be 'System.Boolean' + Get-PSFConfigValue -FullName $script:fullName | Should -Be $true + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'true' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/consolecolor.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/consolecolor.Tests.ps1 new file mode 100644 index 00000000..8894533c --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/consolecolor.Tests.ps1 @@ -0,0 +1,24 @@ +Describe "consolecolor config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.consolecolor' + Set-PSFConfig -FullName $script:fullName -Value ([System.ConsoleColor]::Black) -Validation 'consolecolor' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value ([System.ConsoleColor]::Red) -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be ([System.ConsoleColor]::Red) + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value 'Blue' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be ([System.ConsoleColor]::Blue) + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'NoColor' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/credential.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/credential.Tests.ps1 new file mode 100644 index 00000000..9e6b3580 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/credential.Tests.ps1 @@ -0,0 +1,28 @@ +Describe "credential config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.credential' + $script:seedCredential = [System.Management.Automation.PSCredential]::new('seed', (ConvertTo-SecureString 'seed' -AsPlainText -Force)) + Set-PSFConfig -FullName $script:fullName -Value $script:seedCredential -Validation 'credential' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $validCredential = [System.Management.Automation.PSCredential]::new('valid', (ConvertTo-SecureString 'pw1' -AsPlainText -Force)) + { Set-PSFConfig -FullName $script:fullName -Value $validCredential -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).UserName | Should -Be 'valid' + } + + It "accepts values that require conversion" { + $securePassword = ConvertTo-SecureString 'pw2' -AsPlainText -Force + $convertedCredential = [System.Management.Automation.PSCredential]::new('converted', $securePassword) + { Set-PSFConfig -FullName $script:fullName -Value $convertedCredential -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).UserName | Should -Be 'converted' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'not-a-credential' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/datetime.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/datetime.Tests.ps1 new file mode 100644 index 00000000..018fe1b5 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/datetime.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "datetime config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.datetime' + Set-PSFConfig -FullName $script:fullName -Value ([datetime]'2000-01-01') -Validation 'datetime' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $value = [datetime]'2024-12-31T12:34:56' + { Set-PSFConfig -FullName $script:fullName -Value $value -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '2026-02-03T04:05:06Z' -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).GetType().FullName | Should -Be 'System.DateTime' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'not-a-date' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/double.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/double.Tests.ps1 new file mode 100644 index 00000000..34611578 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/double.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "double config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.double' + Set-PSFConfig -FullName $script:fullName -Value ([double]0.5) -Validation 'double' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value ([double]3.25) -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 3.25 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '2.75' -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).GetType().FullName | Should -Be 'System.Double' + Get-PSFConfigValue -FullName $script:fullName | Should -Be 2.75 + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'abc' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/guid.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/guid.Tests.ps1 new file mode 100644 index 00000000..ea3132f2 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/guid.Tests.ps1 @@ -0,0 +1,26 @@ +Describe "guid config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.guid' + Set-PSFConfig -FullName $script:fullName -Value ([guid]::Empty) -Validation 'guid' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $value = [guid]::NewGuid() + { Set-PSFConfig -FullName $script:fullName -Value $value -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "accepts values that require conversion" { + $value = [guid]::NewGuid() + { Set-PSFConfig -FullName $script:fullName -Value $value.Guid -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'not-a-guid' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/guidarray.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/guidarray.Tests.ps1 new file mode 100644 index 00000000..d90ec2f1 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/guidarray.Tests.ps1 @@ -0,0 +1,32 @@ +Describe "guidarray config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.guidarray' + Set-PSFConfig -FullName $script:fullName -Value @([guid]::Empty) -Validation 'guidarray' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $g1 = [guid]::NewGuid() + $g2 = [guid]::NewGuid() + { Set-PSFConfig -FullName $script:fullName -Value @($g1, $g2) -EnableException 3>$null } | Should -Not -Throw + $value = Get-PSFConfigValue -FullName $script:fullName + $value[0] | Should -Be $g1 + $value[1] | Should -Be $g2 + } + + It "accepts values that require conversion" { + $g1 = [guid]::NewGuid() + $g2 = [guid]::NewGuid() + { Set-PSFConfig -FullName $script:fullName -Value @($g1.Guid, $g2.Guid) -EnableException 3>$null } | Should -Not -Throw + $value = Get-PSFConfigValue -FullName $script:fullName + $value[0].GetType().FullName | Should -Be 'System.Guid' + $value[1].GetType().FullName | Should -Be 'System.Guid' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value @('still-not-a-guid') -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/integer.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/integer.Tests.ps1 new file mode 100644 index 00000000..bc01d9d1 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/integer.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "integer config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.integer' + Set-PSFConfig -FullName $script:fullName -Value 0 -Validation 'integer' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 42 -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 42 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '17' -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).GetType().FullName | Should -Be 'System.Int32' + Get-PSFConfigValue -FullName $script:fullName | Should -Be 17 + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'abc' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/integer0to9.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/integer0to9.Tests.ps1 new file mode 100644 index 00000000..7d7e2c27 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/integer0to9.Tests.ps1 @@ -0,0 +1,24 @@ +Describe "integer0to9 config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.integer0to9' + Set-PSFConfig -FullName $script:fullName -Value 0 -Validation 'integer0to9' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 5 -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 5 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '7' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 7 + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 10 -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/integer1to9.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/integer1to9.Tests.ps1 new file mode 100644 index 00000000..11ad0240 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/integer1to9.Tests.ps1 @@ -0,0 +1,24 @@ +Describe "integer1to9 config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.integer1to9' + Set-PSFConfig -FullName $script:fullName -Value 1 -Validation 'integer1to9' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 4 -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 4 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '9' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 9 + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 0 -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/integerarray.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/integerarray.Tests.ps1 new file mode 100644 index 00000000..f36fca71 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/integerarray.Tests.ps1 @@ -0,0 +1,27 @@ +Describe "integerarray config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.integerarray' + Set-PSFConfig -FullName $script:fullName -Value @(0) -Validation 'integerarray' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value @([int]1, [int]2, [int]3) -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).Count | Should -Be 3 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value @('4', '5') -EnableException 3>$null } | Should -Not -Throw + $value = Get-PSFConfigValue -FullName $script:fullName + $value[0].GetType().FullName | Should -Be 'System.Int32' + $value[0] | Should -Be 4 + $value[1] | Should -Be 5 + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value @('one', 2) -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/integerpositive.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/integerpositive.Tests.ps1 new file mode 100644 index 00000000..3bfc36bf --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/integerpositive.Tests.ps1 @@ -0,0 +1,24 @@ +Describe "integerpositive config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.integerpositive' + Set-PSFConfig -FullName $script:fullName -Value 0 -Validation 'integerpositive' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 3 -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 3 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '8' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 8 + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value -1 -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/languagecode.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/languagecode.Tests.ps1 new file mode 100644 index 00000000..b9dd16ce --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/languagecode.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "languagecode config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.languagecode' + Set-PSFConfig -FullName $script:fullName -Value 'en-US' -Validation 'languagecode' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 'de-DE' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'de-DE' + } + + It "accepts values that require conversion" { + $culture = [System.Globalization.CultureInfo]::GetCultureInfo('fr-FR') + { Set-PSFConfig -FullName $script:fullName -Value $culture -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'fr-FR' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'zz-INVALID' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/long.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/long.Tests.ps1 new file mode 100644 index 00000000..9ce8a912 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/long.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "long config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.long' + Set-PSFConfig -FullName $script:fullName -Value ([long]0) -Validation 'long' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value ([long]1234567890123) -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be ([long]1234567890123) + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '9876543210' -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).GetType().FullName | Should -Be 'System.Int64' + Get-PSFConfigValue -FullName $script:fullName | Should -Be ([long]9876543210) + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'abc' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/psframework.logfilefiletype.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/psframework.logfilefiletype.Tests.ps1 new file mode 100644 index 00000000..dfeeeded --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/psframework.logfilefiletype.Tests.ps1 @@ -0,0 +1,28 @@ +Describe "psframework.logfilefiletype config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.psframework.logfilefiletype' + $script:enumNames = [enum]::GetNames([PSFramework.Logging.LogFileFileType]) + Set-PSFConfig -FullName $script:fullName -Value $script:enumNames[0] -Validation 'psframework.logfilefiletype' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $value = [PSFramework.Logging.LogFileFileType]$script:enumNames[0] + { Set-PSFConfig -FullName $script:fullName -Value $value -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "accepts values that require conversion" { + $convertedName = if ($script:enumNames.Count -gt 1) { $script:enumNames[1] } else { $script:enumNames[0] } + $expected = [PSFramework.Logging.LogFileFileType]$convertedName + { Set-PSFConfig -FullName $script:fullName -Value $convertedName -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $expected + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'not-a-logfile-type' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/rstimeout.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/rstimeout.Tests.ps1 new file mode 100644 index 00000000..e5ed6376 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/rstimeout.Tests.ps1 @@ -0,0 +1,29 @@ +Describe "rstimeout config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.rstimeout' + $script:enumNames = [enum]::GetNames([PSFramework.Runspace.RSTimeout]) | Where-Object { $_ -ne 'Undefined' } + Set-PSFConfig -FullName $script:fullName -Value $script:enumNames[0] -Validation 'rstimeout' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $value = [PSFramework.Runspace.RSTimeout]$script:enumNames[0] + { Set-PSFConfig -FullName $script:fullName -Value $value -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "accepts values that require conversion" { + $convertedName = if ($script:enumNames.Count -gt 1) { $script:enumNames[1] } else { $script:enumNames[0] } + $expected = [PSFramework.Runspace.RSTimeout]$convertedName + { Set-PSFConfig -FullName $script:fullName -Value $convertedName -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $expected + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'Undefined' -EnableException 3>$null } | Should -Throw + { Set-PSFConfig -FullName $script:fullName -Value 'BlaBlaBlubb' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/secret.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/secret.Tests.ps1 new file mode 100644 index 00000000..2eddb239 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/secret.Tests.ps1 @@ -0,0 +1,28 @@ +Describe "secret config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.secret' + $seedCredential = [System.Management.Automation.PSCredential]::new('seed', (ConvertTo-SecureString 'seed' -AsPlainText -Force)) + Set-PSFConfig -FullName $script:fullName -Value $seedCredential -Validation 'secret' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $validCredential = [System.Management.Automation.PSCredential]::new('valid', (ConvertTo-SecureString 'pw1' -AsPlainText -Force)) + { Set-PSFConfig -FullName $script:fullName -Value $validCredential -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).UserName | Should -Be 'valid' + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value 'plain-text-secret' -EnableException 3>$null } | Should -Not -Throw + $value = Get-PSFConfigValue -FullName $script:fullName + $value.GetType().FullName | Should -Be 'System.Management.Automation.PSCredential' + $value.UserName | Should -Be '' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value ([byte[]](1,2,3)) -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/sizestyle.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/sizestyle.Tests.ps1 new file mode 100644 index 00000000..888e3496 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/sizestyle.Tests.ps1 @@ -0,0 +1,28 @@ +Describe "sizestyle config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.sizestyle' + $script:enumNames = [enum]::GetNames([PSFramework.Utility.SizeStyle]) + Set-PSFConfig -FullName $script:fullName -Value $script:enumNames[0] -Validation 'sizestyle' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $value = [PSFramework.Utility.SizeStyle]$script:enumNames[0] + { Set-PSFConfig -FullName $script:fullName -Value $value -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "accepts values that require conversion" { + $convertedName = if ($script:enumNames.Count -gt 1) { $script:enumNames[1] } else { $script:enumNames[0] } + $expected = [PSFramework.Utility.SizeStyle]$convertedName + { Set-PSFConfig -FullName $script:fullName -Value $convertedName -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $expected + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'not-a-size-style' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/string.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/string.Tests.ps1 new file mode 100644 index 00000000..eb49bfa4 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/string.Tests.ps1 @@ -0,0 +1,24 @@ +Describe "string config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.string' + Set-PSFConfig -FullName $script:fullName -Value 'seed' -Validation 'string' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 'hello world' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'hello world' + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value 12345 -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be '12345' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value ([object]::new()) -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/stringarray.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/stringarray.Tests.ps1 new file mode 100644 index 00000000..190dc1b5 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/stringarray.Tests.ps1 @@ -0,0 +1,35 @@ +Describe "stringarray config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + Add-Type -TypeDefinition @" +public class PSFStringArrayThrowingToString { + public override string ToString() { + throw new System.InvalidOperationException("No string representation"); + } +} +"@ -ErrorAction SilentlyContinue + + $script:fullName = 'PSFTests.Validation.stringarray' + Set-PSFConfig -FullName $script:fullName -Value @('seed') -Validation 'stringarray' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value @('one', 'two') -EnableException 3>$null } | Should -Not -Throw + (Get-PSFConfigValue -FullName $script:fullName).Count | Should -Be 2 + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value @(1, $true, [guid]::Empty) -EnableException 3>$null } | Should -Not -Throw + $value = Get-PSFConfigValue -FullName $script:fullName + $value[0] | Should -Be '1' + $value[1] | Should -Be 'True' + } + + It "rejects invalid values" { + $badValue = [PSFStringArrayThrowingToString]::new() + { Set-PSFConfig -FullName $script:fullName -Value @($badValue) -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/timespan.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/timespan.Tests.ps1 new file mode 100644 index 00000000..703bb547 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/timespan.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "timespan config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.timespan' + Set-PSFConfig -FullName $script:fullName -Value ([timespan]::Zero) -Validation 'timespan' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + $value = [timespan]::FromMinutes(5) + { Set-PSFConfig -FullName $script:fullName -Value $value -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be $value + } + + It "accepts values that require conversion" { + { Set-PSFConfig -FullName $script:fullName -Value '00:10:00' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be ([timespan]::FromMinutes(10)) + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'not-a-timespan' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/uriabsolute.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/uriabsolute.Tests.ps1 new file mode 100644 index 00000000..a280652e --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/uriabsolute.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "uriabsolute config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.uriabsolute' + Set-PSFConfig -FullName $script:fullName -Value 'https://example.com' -Validation 'uriabsolute' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 'https://contoso.com/path' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'https://contoso.com/path' + } + + It "accepts values that require conversion" { + $uriObject = [uri]'https://fabrikam.com/service' + { Set-PSFConfig -FullName $script:fullName -Value $uriObject -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'https://fabrikam.com/service' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value '/relative/path' -EnableException 3>$null } | Should -Throw + } +} diff --git a/PSFramework/tests/functions/configuration/validations/urihttp.Tests.ps1 b/PSFramework/tests/functions/configuration/validations/urihttp.Tests.ps1 new file mode 100644 index 00000000..43991339 --- /dev/null +++ b/PSFramework/tests/functions/configuration/validations/urihttp.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "urihttp config validation" -Tag "CI", "Config", "Unit" { + BeforeAll { + $script:fullName = 'PSFTests.Validation.urihttp' + Set-PSFConfig -FullName $script:fullName -Value 'https://example.com' -Validation 'urihttp' -Initialize -AllowDelete -EnableException 3>$null + } + + AfterAll { + Remove-PSFConfig -FullName $script:fullName -Confirm:$false 3>$null + } + + It "accepts values that are already valid" { + { Set-PSFConfig -FullName $script:fullName -Value 'http://contoso.com/path' -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'http://contoso.com/path' + } + + It "accepts values that require conversion" { + $uriObject = [uri]'https://fabrikam.com/service' + { Set-PSFConfig -FullName $script:fullName -Value $uriObject -EnableException 3>$null } | Should -Not -Throw + Get-PSFConfigValue -FullName $script:fullName | Should -Be 'https://fabrikam.com/service' + } + + It "rejects invalid values" { + { Set-PSFConfig -FullName $script:fullName -Value 'ftp://contoso.com/path' -EnableException 3>$null } | Should -Throw + } +} From 131d1bb83e318a767757f708b9d7e1a0172b4e0f Mon Sep 17 00:00:00 2001 From: Friedrich Weinmann Date: Thu, 2 Jul 2026 09:17:25 +0200 Subject: [PATCH 2/2] Update stringsLogging.psd1 --- PSFramework/en-us/stringsLogging.psd1 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/PSFramework/en-us/stringsLogging.psd1 b/PSFramework/en-us/stringsLogging.psd1 index 3aace0ec..6c4e590d 100644 --- a/PSFramework/en-us/stringsLogging.psd1 +++ b/PSFramework/en-us/stringsLogging.psd1 @@ -1,20 +1,21 @@ @{ - 'Add-PSFLoggingProviderRunspace.Instance.NotFound' = 'Unable to find logging provider instance {1} of provider {0}' # $ProviderName, $InstanceName + 'Add-PSFLoggingProviderRunspace.Instance.NotFound' = 'Unable to find logging provider instance {1} of provider {0}' # $ProviderName, $InstanceName - 'Import-PSFLoggingProvider.Import.Error' = "Error loading json data from {0}" # $effectivePath - 'Import-PSFLoggingProvider.Datum.Error' = "Error processing logging provider entry" # + 'Import-PSFLoggingProvider.Import.Error' = "Error loading json data from {0}" # $effectivePath + 'Import-PSFLoggingProvider.Datum.Error' = "Error processing logging provider entry" # - 'Install-PSFLoggingProvider.Provider.NotFound' = "Provider {0} not found!" # $Name - 'Install-PSFLoggingProvider.Installation.Error' = "Failed to install provider '{0}'" # $Name + 'Install-PSFLoggingProvider.Provider.NotFound' = "Provider {0} not found!" # $Name + 'Install-PSFLoggingProvider.Installation.Error' = "Failed to install provider '{0}'" # $Name 'Register-PSFLoggingProvider.RegistrationEvent.Failed' = "Failed to register logging provider '{0}' - Registration event failed." # $Name - 'Register-PSFLoggingProvider.Installation.Failed' = "Failed to install logging provider '{0}'" # $Name + 'Register-PSFLoggingProvider.Installation.Failed' = "Failed to install logging provider '{0}'" # $Name 'Register-PSFLoggingProvider.NotInstalled.Termination' = "Failed to enable logging provider {0} on registration! It was not recognized as installed. Consider running 'Install-PSFLoggingProvider' to properly install the prerequisites." # $Name 'Register-PSFMessageColorTransform.Level.Invalid' = 'Invalid level for a message color rule: {0}! The levels "Warning" and "Error" cannot be selected as warning messages cannot be colored.' # $Level - 'Set-PSFLoggingProvider.Provider.NotFound' = 'Provider {0} not found!' # $Name - 'Set-PSFLoggingProvider.Provider.V1NoInstance' = 'The Provider {0} is a first generation logging provider and does not support instances!' # $Name - 'Set-PSFLoggingProvider.Provider.NotInstalled' = 'Provider {0} not installed! Run "Install-PSFLoggingProvider" first' # $Name - 'Set-PSFLoggingProvider.Wait.Timeout' = 'Timeout waiting for {0} > {1} to be created. Logs may not be written as expected!' # $Name, $InstanceName + 'Set-PSFLoggingProvider.Error.ConfigNoName' = 'Invalid logging configuration: No provider name ("Name") specified! | {0}' # $params + 'Set-PSFLoggingProvider.Provider.NotFound' = 'Provider {0} not found!' # $Name + 'Set-PSFLoggingProvider.Provider.V1NoInstance' = 'The Provider {0} is a first generation logging provider and does not support instances!' # $Name + 'Set-PSFLoggingProvider.Provider.NotInstalled' = 'Provider {0} not installed! Run "Install-PSFLoggingProvider" first' # $Name + 'Set-PSFLoggingProvider.Wait.Timeout' = 'Timeout waiting for {0} > {1} to be created. Logs may not be written as expected!' # $Name, $InstanceName } \ No newline at end of file