From 096edc9d600846b0f108b8b027ebf7ebdcd07a3e Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 25 Apr 2023 09:55:18 +0200 Subject: [PATCH] Corrected unit tests and updated changelog --- CHANGELOG.md | 5 ++ ...MSFT_SPDistributedCacheClientSettings.psm1 | 50 +++++++++++++++++++ ...SPDistributedCacheClientSettings.Tests.ps1 | 33 ++++++++++++ 3 files changed, 88 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f9765587..bad923b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- SPDistributedCacheClientSettings + - Added additional parameters for SP2019 and SPSE + ### Changed - SPFarm diff --git a/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 b/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 index 752f3116d..c15c97152 100644 --- a/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPDistributedCacheClientSettings/MSFT_SPDistributedCacheClientSettings.psm1 @@ -910,6 +910,56 @@ function Set-TargetResource } } + if ($PSBoundParameters.ContainsKey("DDBFCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DDBFCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DDBFCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DEHCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DEHCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DEHCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DFSPTCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DFSPTCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DFSPTCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DSPABSCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DSPABSCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DSPABSCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DSPCVCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DSPCVCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DSPCVCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DSPOATCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DSPOATCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DSPOATCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DSGCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DSGCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DSGCChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DUACMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DUACRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DUACChannelOpenTimeOut") -eq $true -or + $PSBoundParameters.ContainsKey("DUAuCMaxConnectionsToServer") -eq $true -or + $PSBoundParameters.ContainsKey("DUAuCRequestTimeout") -eq $true -or + $PSBoundParameters.ContainsKey("DUAuCChannelOpenTimeOut") -eq $true) + { + $installedVersion = Get-SPDscInstalledProductVersion + if ($installedVersion.FileMajorPart -eq 15 -or ` + $installedVersion.ProductBuildPart.ToString().Length -eq 4) + { + $message = ("The following parameters are only supported in SharePoint 2019 and above: " + ` + "DDBFCMaxConnectionsToServer, DDBFCRequestTimeout, DDBFCChannelOpenTimeOut, " + ` + "DEHCMaxConnectionsToServer, DEHCRequestTimeout, DEHCChannelOpenTimeOut, " + ` + "DFSPTCMaxConnectionsToServer, DFSPTCRequestTimeout, DFSPTCChannelOpenTimeOut, " + ` + "DSPABSCMaxConnectionsToServer, DSPABSCRequestTimeout, DSPABSCChannelOpenTimeOut, " + ` + "DSPCVCMaxConnectionsToServer, DSPCVCRequestTimeout, DSPCVCChannelOpenTimeOut, " + ` + "DSPOATCMaxConnectionsToServer, DSPOATCRequestTimeout, DSPOATCChannelOpenTimeOut, " + ` + "DSGCMaxConnectionsToServer, DSGCRequestTimeout, DSGCChannelOpenTimeOut, " + ` + "DUACMaxConnectionsToServer, DUACRequestTimeout, DUACChannelOpenTimeOut, " + ` + "DUAuCMaxConnectionsToServer, DUAuCRequestTimeout, DUAuCChannelOpenTimeOut") + Add-SPDscEvent -Message $message ` + -EntryType 'Error' ` + -EventID 100 ` + -Source $MyInvocation.MyCommand.Source + throw $message + } + } + Invoke-SPDscCommand -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 index 0e11e1fb5..60bfffc0e 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPDistributedCacheClientSettings.Tests.ps1 @@ -329,6 +329,39 @@ try } } } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Build.ToString().Length -lt 5) + { + Context -Name "SP2019+ parameters specified with older versions" -Fixture { + BeforeAll { + Mock -CommandName Get-SPDistributedCacheClientSetting -MockWith { + return @{ + MaxConnectionsToServer = 1 + RequestTimeout = 3000 + ChannelOpenTimeOut = 3000 + } + } + $testParams = @{ + IsSingleInstance = "Yes" + DUAuCMaxConnectionsToServer = 1 + DUAuCRequestTimeout = 3000 + DUAuCChannelOpenTimeOut = 3000 + } + } + + It "Should throw exception in the Get method" { + { Get-TargetResource @testParams } | Should -Throw "The following parameters are only supported in SharePoint 2019 and above" + } + + It "Should throw exception in the Set method" { + { Set-TargetResource @testParams } | Should -Throw "The following parameters are only supported in SharePoint 2019 and above" + } + + It "Should throw exception in the Test method" { + { Test-TargetResource @testParams } | Should -Throw "The following parameters are only supported in SharePoint 2019 and above" + } + } + } } } }