From cf3f0b25a25b3a73c2dc42ad5708f572ea554791 Mon Sep 17 00:00:00 2001 From: "Hannappel, Christoph" Date: Mon, 23 Dec 2024 11:45:28 +0100 Subject: [PATCH 1/5] Fix: SPSearchCrawlerImpactRule does not throw if Rule does not exist. --- CHANGELOG.md | 4 ++++ .../MSFT_SPSearchCrawlerImpactRule.psm1 | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53208f4da..78aa1d79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SPShellAdmins - Fixed that the Member comparison was not case insensitive. +- SPSearchCrawlerImpactRule + - Ressource threw an error if the Crawler Impact Rule did not exist when + running the Get Method + ## [5.5.0] - 2024-04-22 ### Added diff --git a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 index 96a260f5b..8e391d29e 100644 --- a/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 +++ b/SharePointDsc/DSCResources/MSFT_SPSearchCrawlerImpactRule/MSFT_SPSearchCrawlerImpactRule.psm1 @@ -60,7 +60,7 @@ function Get-TargetResource } else { - $crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -Identity $params.Name -SearchService $params.ServiceAppName + $crawlerImpactRule = Get-SPEnterpriseSearchSiteHitRule -SearchService $params.ServiceAppName | Where-Object -FilterScript { $_.Site -eq $params.Name } if ($null -eq $crawlerImpactRule) { return $nullReturn From 77b6899730cb18fe96a59afd7406191b906ba7da Mon Sep 17 00:00:00 2001 From: "Hannappel, Christoph" Date: Mon, 23 Dec 2024 11:46:59 +0100 Subject: [PATCH 2/5] None: Markdown Syntax --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78aa1d79f..b8a5b0a6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed that the Member comparison was not case insensitive. - SPSearchCrawlerImpactRule - - Ressource threw an error if the Crawler Impact Rule did not exist when + - Ressource threw an error if the Crawler Impact Rule did not exist when running the Get Method ## [5.5.0] - 2024-04-22 From e887b198256a9ee8de075619710e3c46ee91f916 Mon Sep 17 00:00:00 2001 From: "Hannappel, Christoph" Date: Mon, 23 Dec 2024 15:03:34 +0100 Subject: [PATCH 3/5] Fix: Crawl Impact Rules do use the Schema --- ...intDsc.SPSearchCrawlerImpactRule.Tests.ps1 | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 index f5565e7a2..c07029e0b 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 @@ -49,7 +49,7 @@ try InModuleScope -ModuleName $script:DSCResourceFullName -ScriptBlock { Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { BeforeAll { - Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + Invoke-Command -Scriptblock $Global:SPDscHelper.InitializeScript -NoNewScope # Initialize tests $getTypeFullName = "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" @@ -61,16 +61,16 @@ try Mock -CommandName Get-SPServiceApplication -MockWith { return @( New-Object -TypeName "Object" | - Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru - } ` - -PassThru -Force) + Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru + } ` + -PassThru -Force) } function Add-SPDscEvent @@ -101,7 +101,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" RequestLimit = 8 Ensure = "Present" } @@ -135,7 +135,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" RequestLimit = 8 Ensure = "Present" } @@ -174,7 +174,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" Ensure = "Absent" } @@ -211,7 +211,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" Ensure = "Absent" } @@ -244,7 +244,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" Ensure = "Absent" } @@ -271,7 +271,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" RequestLimit = 8 WaitTime = 60 Ensure = "Present" @@ -290,7 +290,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" WaitTime = 300 Ensure = "Present" } @@ -324,7 +324,7 @@ try BeforeAll { $testParams = @{ ServiceAppName = "Search Service Application" - Name = "http://site.sharepoint.com" + Name = "site.sharepoint.com" WaitTime = 300 Ensure = "Present" } From 59005074e9e73374085f97a13c35cf54c460421c Mon Sep 17 00:00:00 2001 From: "Hannappel, Christoph" Date: Mon, 23 Dec 2024 15:17:22 +0100 Subject: [PATCH 4/5] Fix: Unit Tests --- ...intDsc.SPSearchCrawlerImpactRule.Tests.ps1 | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 index c07029e0b..2a148dc75 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 @@ -147,10 +147,10 @@ try } Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { - return @{ - Name = $testParams.Name + return [pscustomobject]@{ + Site = $testParams.Name HitRate = $testParams.RequestLimit - Behavior = "0" + Behavior = "SimultaneousRequests" } } } @@ -185,26 +185,17 @@ try } Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { - return @{ - Name = $testParams.Name - HitRate = $testParams.RequestLimit - } + return $null } } It "Should return present from the Get method" { - (Get-TargetResource @testParams).Ensure | Should -Be "Present" + (Get-TargetResource @testParams).Ensure | Should -Be "Absent" } It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should -Be $false } - - It "Should remove the search Site hit rule in the set method" { - Set-TargetResource @testParams - Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule - - } } Context -Name "When crawler impact requestlimit rule shouldn't exist and does exist" -Fixture { @@ -336,27 +327,21 @@ try } Mock -CommandName Get-SPEnterpriseSearchSiteHitRule -MockWith { - return @{ - Name = $testParams.Name + return [pscustomobject]@{ + Site = $testParams.Name HitRate = $testParams.WaitTime - Behavior = "1" + Behavior = "DelayBetweenRequests" } } } - It "Should return absent from the Get method" { + It "Should return Present from the Get method" { (Get-TargetResource @testParams).Ensure | Should -Be "Present" } It "Should return true when the Test method is called" { Test-TargetResource @testParams | Should -Be $true } - - It "Should update a new search Site hit rule in the set method" { - Set-TargetResource @testParams - Assert-MockCalled Remove-SPEnterpriseSearchSiteHitRule - Assert-MockCalled New-SPEnterpriseSearchSiteHitRule - } } } } From 9965010c4f567546084b916e881d36d512ddcfb3 Mon Sep 17 00:00:00 2001 From: "Hannappel, Christoph" Date: Fri, 27 Dec 2024 12:49:19 +0100 Subject: [PATCH 5/5] Fix: Unit Tests --- ...SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 index 2a148dc75..4d39b8a15 100644 --- a/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 +++ b/tests/Unit/SharePointDsc/SharePointDsc.SPSearchCrawlerImpactRule.Tests.ps1 @@ -32,7 +32,7 @@ function Invoke-TestSetup $script:testEnvironment = Initialize-TestEnvironment ` -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceFullName ` + -DscResourceName $script:DSCResourceFullName ` -ResourceType 'Mof' ` -TestType 'Unit' } @@ -150,12 +150,12 @@ try return [pscustomobject]@{ Site = $testParams.Name HitRate = $testParams.RequestLimit - Behavior = "SimultaneousRequests" + Behavior = 0 } } } - It "Should return absent from the Get method" { + It "Should return Present from the Get method" { (Get-TargetResource @testParams).Ensure | Should -Be "Present" } @@ -193,8 +193,8 @@ try (Get-TargetResource @testParams).Ensure | Should -Be "Absent" } - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should -Be $false + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should -Be $true } } @@ -330,7 +330,7 @@ try return [pscustomobject]@{ Site = $testParams.Name HitRate = $testParams.WaitTime - Behavior = "DelayBetweenRequests" + Behavior = 1 } } }