From 5c71ff367907d914d9f2f8fce83be98878a0da63 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Fri, 24 Apr 2015 23:52:15 +1000 Subject: [PATCH 01/15] Added global test for InstallAccount param --- Tests/Tests.pssproj | 37 ++++++++++++++++++ .../xSharePoint/xSharePoint.Global.Tests.ps1 | 39 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Tests/Tests.pssproj create mode 100644 Tests/xSharePoint/xSharePoint.Global.Tests.ps1 diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj new file mode 100644 index 000000000..e0cab79e5 --- /dev/null +++ b/Tests/Tests.pssproj @@ -0,0 +1,37 @@ + + + + Debug + 2.0 + 6CAFC0C6-A428-4d30-A9F9-700E829FEA51 + Exe + MyApplication + MyApplication + Tests + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 b/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 new file mode 100644 index 000000000..bb3853555 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 @@ -0,0 +1,39 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +Describe 'xSharePoint Global Tests' { + + $mofFiles = @(Get-ChildItem $RepoRoot -Recurse -Filter "*.schema.mof" -File | ? { + ($_.FullName -like "*\DscResources\*") + }) + + Context 'MOF schemas use InstallAccount' { + + It "Doesn't have an InstallAccount required parameter" { + $mofFilesWithNoInstallAccount = 0 + $mofFiles | % { + $fileHasInstallAccount = $false + Get-Content $_.FullName | % { + if ($_.IndexOf("[Required, EmbeddedInstance(`"MSFT_Credential`")] String InstallAccount;") -gt 0) { $fileHasInstallAccount = $true } + } + if (-not $fileHasInstallAccount -and $_.Name -ne "MSFT_xSPInstall.schema.mof" ` + -and $_.Name -ne "MSFT_xSPClearRemoteSessions.schema.mof" ` + -and $_.Name -ne "MSFT_xSPInstallPrereqs.schema.mof") { + $mofFilesWithNoInstallAccount += 1 + Write-Warning "File $($_.FullName) does not contain an InstallAccount parameter. All SharePoint specific resources should use this to impersonate as and access SharePoint resources" + } + } + $mofFilesWithNoInstallAccount | Should Be 0 + } + } +} \ No newline at end of file From 56e36825758a52adaf25eeb2d08ebf22cd448bc4 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Fri, 24 Apr 2015 23:56:53 +1000 Subject: [PATCH 02/15] Removed tabs from files --- .../xSharePoint/xSharePoint.Global.Tests.ps1 | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 b/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 index bb3853555..659d96db6 100644 --- a/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.Global.Tests.ps1 @@ -21,19 +21,19 @@ Describe 'xSharePoint Global Tests' { It "Doesn't have an InstallAccount required parameter" { $mofFilesWithNoInstallAccount = 0 - $mofFiles | % { - $fileHasInstallAccount = $false - Get-Content $_.FullName | % { - if ($_.IndexOf("[Required, EmbeddedInstance(`"MSFT_Credential`")] String InstallAccount;") -gt 0) { $fileHasInstallAccount = $true } - } - if (-not $fileHasInstallAccount -and $_.Name -ne "MSFT_xSPInstall.schema.mof" ` - -and $_.Name -ne "MSFT_xSPClearRemoteSessions.schema.mof" ` - -and $_.Name -ne "MSFT_xSPInstallPrereqs.schema.mof") { - $mofFilesWithNoInstallAccount += 1 - Write-Warning "File $($_.FullName) does not contain an InstallAccount parameter. All SharePoint specific resources should use this to impersonate as and access SharePoint resources" - } - } - $mofFilesWithNoInstallAccount | Should Be 0 + $mofFiles | % { + $fileHasInstallAccount = $false + Get-Content $_.FullName | % { + if ($_.IndexOf("[Required, EmbeddedInstance(`"MSFT_Credential`")] String InstallAccount;") -gt 0) { $fileHasInstallAccount = $true } + } + if (-not $fileHasInstallAccount -and $_.Name -ne "MSFT_xSPInstall.schema.mof" ` + -and $_.Name -ne "MSFT_xSPClearRemoteSessions.schema.mof" ` + -and $_.Name -ne "MSFT_xSPInstallPrereqs.schema.mof") { + $mofFilesWithNoInstallAccount += 1 + Write-Warning "File $($_.FullName) does not contain an InstallAccount parameter. All SharePoint specific resources should use this to impersonate as and access SharePoint resources" + } + } + $mofFilesWithNoInstallAccount | Should Be 0 } } } \ No newline at end of file From 1d08459a581ba7a294297b09d1e59038b38984f3 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 00:32:21 +1000 Subject: [PATCH 03/15] Added BCS service app tests --- .../xSharePoint.xSPBCSServiceApp.Tests.ps1 | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 diff --git a/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 new file mode 100644 index 000000000..61305d1ed --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 @@ -0,0 +1,50 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\MSFT_xSPBCSServiceApp\MSFT_xSPBCSServiceApp.psm1") + +Describe "xSPBCSServiceApp" { + + $testParams = @{ + Name = "Test App" + ApplicationPool = "Test App Pool" + DatabaseName = "Test_DB" + DatabaseServer = "TestServer\Instance" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + } + + Context "Validate test method" { + It "Fails when no service app exists" { + Mock Get-TargetResource { return @{} } -ModuleName MSFT_xSPBCSServiceApp + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the service app exists" { + Mock Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = $testParams.ApplicationPool + } + } -ModuleName MSFT_xSPBCSServiceApp + Test-TargetResource @testParams | Should Be $false + } + It "Fails when the service app exists but has the wrong app pool" { + Mock Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = "Wrong app pool " + } + } -ModuleName MSFT_xSPBCSServiceApp + Test-TargetResource @testParams | Should Be $false + } + } +} From 087438bf8c4216e2da3f5389705dd11f3ce369cf Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 00:33:32 +1000 Subject: [PATCH 04/15] Minor typo --- Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 index 61305d1ed..343d40e39 100644 --- a/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 @@ -41,10 +41,10 @@ Describe "xSPBCSServiceApp" { Mock Get-TargetResource { return @{ Name = $testParams.Name - ApplicationPool = "Wrong app pool " + ApplicationPool = "Wrong app pool" } } -ModuleName MSFT_xSPBCSServiceApp Test-TargetResource @testParams | Should Be $false } } -} +} \ No newline at end of file From 32ddca87ce47e0d49158c2a393413865976c1418 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 18:43:20 +1000 Subject: [PATCH 05/15] Added cache account tests, fixed BCS tests --- Tests/Tests.pssproj | 12 ++-- .../xSharePoint.xSPBCSServiceApp.Tests.ps1 | 62 ++++++++++--------- .../xSharePoint.xSPCacheAccounts.Tests.ps1 | 60 ++++++++++++++++++ xSharePoint.sln | 6 ++ 4 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 Tests/xSharePoint/xSharePoint.xSPCacheAccounts.Tests.ps1 diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj index e0cab79e5..2231e7604 100644 --- a/Tests/Tests.pssproj +++ b/Tests/Tests.pssproj @@ -3,7 +3,7 @@ Debug 2.0 - 6CAFC0C6-A428-4d30-A9F9-700E829FEA51 + {279294c4-e197-48cd-a1fb-263ce47dea4d} Exe MyApplication MyApplication @@ -26,11 +26,13 @@ prompt 4 - - - - + + + + + + diff --git a/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 index 343d40e39..dbf2952ac 100644 --- a/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 @@ -11,40 +11,42 @@ Set-StrictMode -Version latest $RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path -Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\MSFT_xSPBCSServiceApp\MSFT_xSPBCSServiceApp.psm1") +$ModuleName = "MSFT_xSPBCSServiceApp" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") Describe "xSPBCSServiceApp" { - - $testParams = @{ - Name = "Test App" - ApplicationPool = "Test App Pool" - DatabaseName = "Test_DB" - DatabaseServer = "TestServer\Instance" - InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) - } - - Context "Validate test method" { - It "Fails when no service app exists" { - Mock Get-TargetResource { return @{} } -ModuleName MSFT_xSPBCSServiceApp - Test-TargetResource @testParams | Should Be $false + InModuleScope $ModuleName { + $testParams = @{ + Name = "Test App" + ApplicationPool = "Test App Pool" + DatabaseName = "Test_DB" + DatabaseServer = "TestServer\Instance" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) } - It "Passes when the service app exists" { - Mock Get-TargetResource { - return @{ - Name = $testParams.Name - ApplicationPool = $testParams.ApplicationPool - } - } -ModuleName MSFT_xSPBCSServiceApp - Test-TargetResource @testParams | Should Be $false - } - It "Fails when the service app exists but has the wrong app pool" { - Mock Get-TargetResource { - return @{ - Name = $testParams.Name - ApplicationPool = "Wrong app pool" + + Context "Validate test method" { + It "Fails when no service app exists" { + Mock Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the service app exists" { + Mock Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = $testParams.ApplicationPool + } } - } -ModuleName MSFT_xSPBCSServiceApp - Test-TargetResource @testParams | Should Be $false + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the service app exists but has the wrong app pool" { + Mock Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = "Wrong app pool" + } + } + Test-TargetResource @testParams | Should Be $false + } } } } \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPCacheAccounts.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPCacheAccounts.Tests.ps1 new file mode 100644 index 000000000..a7fd48be8 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPCacheAccounts.Tests.ps1 @@ -0,0 +1,60 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPCacheAccounts" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPCacheAccounts" { + InModuleScope $ModuleName { + $testParams = @{ + WebAppUrl = "http://test.sharepoint.com" + SuperUserAlias = "DEMO\SuperUser" + SuperReaderAlias = "DEMO\SuperReader" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + } + + Context "Validate test method" { + It "Fails when no cache accounts exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the correct accounts are assigned" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + portalsuperuseraccount = $testParams.SuperUserAlias + portalsuperreaderaccount = $testParams.SuperReaderAlias + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the wrong super reader is defined" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + portalsuperuseraccount = $testParams.SuperUserAlias + portalsuperreaderaccount = "DEMO\WrongUser" + } + } + Test-TargetResource @testParams | Should Be $false + } + It "Fails when the wrong super user is defined" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + portalsuperuseraccount = "DEMO\WrongUser" + portalsuperreaderaccount = $testParams.SuperReaderAlias + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/xSharePoint.sln b/xSharePoint.sln index 4ecc04dbb..fd3694d59 100644 --- a/xSharePoint.sln +++ b/xSharePoint.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentat README.md = README.md EndProjectSection EndProject +Project("{F5034706-568F-408A-B7B3-4D38C6DB8A32}") = "Tests", "Tests\Tests.pssproj", "{279294C4-E197-48CD-A1FB-263CE47DEA4D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,6 +28,10 @@ Global {6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Debug|Any CPU.Build.0 = Debug|Any CPU {6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.ActiveCfg = Release|Any CPU {6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.Build.0 = Release|Any CPU + {279294C4-E197-48CD-A1FB-263CE47DEA4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {279294C4-E197-48CD-A1FB-263CE47DEA4D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {279294C4-E197-48CD-A1FB-263CE47DEA4D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {279294C4-E197-48CD-A1FB-263CE47DEA4D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 3be513b66946d6d770186ee8cd5fbefcadf9de0d Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 20:17:48 +1000 Subject: [PATCH 06/15] Added test for create farm and diagnostic logs --- .../MSFT_xSPDiagnosticLoggingSettings.psm1 | 2 +- .../xSharePoint.xSPCreateFarm.Tests.ps1 | 43 ++++++ ...int.xSPDiagnosticLoggingSettings.Tests.ps1 | 123 ++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 Tests/xSharePoint/xSharePoint.xSPCreateFarm.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 diff --git a/Modules/xSharePoint/DSCResources/MSFT_xSPDiagnosticLoggingSettings/MSFT_xSPDiagnosticLoggingSettings.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPDiagnosticLoggingSettings/MSFT_xSPDiagnosticLoggingSettings.psm1 index 8f168024e..3e1ec0a72 100644 --- a/Modules/xSharePoint/DSCResources/MSFT_xSPDiagnosticLoggingSettings/MSFT_xSPDiagnosticLoggingSettings.psm1 +++ b/Modules/xSharePoint/DSCResources/MSFT_xSPDiagnosticLoggingSettings/MSFT_xSPDiagnosticLoggingSettings.psm1 @@ -227,7 +227,7 @@ function Test-TargetResource if ($ErrorReportingAutomaticUploadEnabled -ne $null -and $ErrorReportingAutomaticUploadEnabled -ne $result.ErrorReportingAutomaticUploadEnabled) { return $false } if ($ErrorReportingEnabled -ne $null -and $ErrorReportingEnabled -ne $result.ErrorReportingEnabled) { return $false } if ($EventLogFloodProtectionEnabled -ne $null -and $EventLogFloodProtectionEnabled -ne $result.EventLogFloodProtectionEnabled) { return $false } - if ($EventLogFloodProtectionNotifyInterval -gt 0 -and $EventLogFloodProtectionNotifyInterval -ne $result.EventLogFloodProtectionNotifyInterval) {} return $false + if ($EventLogFloodProtectionNotifyInterval -gt 0 -and $EventLogFloodProtectionNotifyInterval -ne $result.EventLogFloodProtectionNotifyInterval) { return $false } if ($EventLogFloodProtectionQuietPeriod -gt 0 -and $EventLogFloodProtectionQuietPeriod -ne $result.EventLogFloodProtectionQuietPeriod) { return $false } if ($EventLogFloodProtectionThreshold -gt 0 -and $EventLogFloodProtectionThreshold -ne $result.EventLogFloodProtectionThreshold) { return $false } if ($EventLogFloodProtectionTriggerPeriod -gt 0 -and $EventLogFloodProtectionTriggerPeriod -ne $result.EventLogFloodProtectionTriggerPeriod) { return $false } diff --git a/Tests/xSharePoint/xSharePoint.xSPCreateFarm.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPCreateFarm.Tests.ps1 new file mode 100644 index 000000000..530206fdf --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPCreateFarm.Tests.ps1 @@ -0,0 +1,43 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPCreateFarm" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPCreateFarm" { + InModuleScope $ModuleName { + $testParams = @{ + FarmConfigDatabaseName = "SP_Config" + DatabaseServer = "DatabaseServer\Instance" + FarmAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + Passphrase = "passphrase" + AdminContentDatabaseName = "Admin_Content" + } + + Context "Validate test method" { + It "Fails when local server is not in a farm" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when local server is in a farm" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + FarmName = "SP_Config" + } + } + Test-TargetResource @testParams | Should Be $true + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 new file mode 100644 index 000000000..db37d0da1 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 @@ -0,0 +1,123 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPDiagnosticLoggingSettings" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") -Force + +Describe "xSPCreateFarm" { + InModuleScope $ModuleName { + $testParams = @{ + LogPath = "L:\ULSLogs" + LogSpaceInGB = 10 + AppAnalyticsAutomaticUploadEnabled = $true + CustomerExperienceImprovementProgramEnabled = $true + ErrorReportingEnabled = $true + ErrorReportingAutomaticUploadEnabled = $true + DownloadErrorReportingUpdatesEnabled = $true + DaysToKeepLogs = 7 + LogMaxDiskSpaceUsageEnabled = $true + LogCutInterval = 30 + EventLogFloodProtectionEnabled = $true + EventLogFloodProtectionThreshold = 10 + EventLogFloodProtectionTriggerPeriod = 10 + EventLogFloodProtectionQuietPeriod = 10 + EventLogFloodProtectionNotifyInterval = 10 + ScriptErrorReportingEnabled = $true + ScriptErrorReportingRequireAuth = $true + ScriptErrorReportingDelay = 5 + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + } + + Context "Validate test method" { + It "Fails logging settings can not be found" { + Mock Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when logging settings are applied correctly" { + Mock Get-TargetResource { + return @{ + AppAnalyticsAutomaticUploadEnabled = $testParams.AppAnalyticsAutomaticUploadEnabled + CustomerExperienceImprovementProgramEnabled = $testParams.CustomerExperienceImprovementProgramEnabled + ErrorReportingEnabled = $testParams.ErrorReportingEnabled + ErrorReportingAutomaticUploadEnabled = $testParams.ErrorReportingAutomaticUploadEnabled + DownloadErrorReportingUpdatesEnabled = $testParams.DownloadErrorReportingUpdatesEnabled + DaysToKeepLogs = $testParams.DaysToKeepLogs + LogMaxDiskSpaceUsageEnabled = $testParams.LogMaxDiskSpaceUsageEnabled + LogDiskSpaceUsageGB = $testParams.LogSpaceInGB + LogLocation = $testParams.LogPath + LogCutInterval = $testParams.LogCutInterval + EventLogFloodProtectionEnabled = $testParams.EventLogFloodProtectionEnabled + EventLogFloodProtectionThreshold = $testParams.EventLogFloodProtectionThreshold + EventLogFloodProtectionTriggerPeriod = $testParams.EventLogFloodProtectionTriggerPeriod + EventLogFloodProtectionQuietPeriod = $testParams.EventLogFloodProtectionQuietPeriod + EventLogFloodProtectionNotifyInterval = $testParams.EventLogFloodProtectionNotifyInterval + ScriptErrorReportingEnabled = $testParams.ScriptErrorReportingEnabled + ScriptErrorReportingRequireAuth = $testParams.ScriptErrorReportingRequireAuth + ScriptErrorReportingDelay = $testParams.ScriptErrorReportingDelay + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when disk location is incorrect" { + Mock Get-TargetResource { + return @{ + AppAnalyticsAutomaticUploadEnabled = $testParams.AppAnalyticsAutomaticUploadEnabled + CustomerExperienceImprovementProgramEnabled = $testParams.CustomerExperienceImprovementProgramEnabled + ErrorReportingEnabled = $testParams.ErrorReportingEnabled + ErrorReportingAutomaticUploadEnabled = $testParams.ErrorReportingAutomaticUploadEnabled + DownloadErrorReportingUpdatesEnabled = $testParams.DownloadErrorReportingUpdatesEnabled + DaysToKeepLogs = $testParams.DaysToKeepLogs + LogMaxDiskSpaceUsageEnabled = $testParams.LogMaxDiskSpaceUsageEnabled + LogDiskSpaceUsageGB = $testParams.LogSpaceInGB + LogLocation = "C:\logs" + LogCutInterval = $testParams.LogCutInterval + EventLogFloodProtectionEnabled = $testParams.EventLogFloodProtectionEnabled + EventLogFloodProtectionThreshold = $testParams.EventLogFloodProtectionThreshold + EventLogFloodProtectionTriggerPeriod = $testParams.EventLogFloodProtectionTriggerPeriod + EventLogFloodProtectionQuietPeriod = $testParams.EventLogFloodProtectionQuietPeriod + EventLogFloodProtectionNotifyInterval = $testParams.EventLogFloodProtectionNotifyInterval + ScriptErrorReportingEnabled = $testParams.ScriptErrorReportingEnabled + ScriptErrorReportingRequireAuth = $testParams.ScriptErrorReportingRequireAuth + ScriptErrorReportingDelay = $testParams.ScriptErrorReportingDelay + } + } + Test-TargetResource @testParams | Should Be $false + } + It "Fails when log size is incorrect" { + Mock Get-TargetResource { + return @{ + AppAnalyticsAutomaticUploadEnabled = $testParams.AppAnalyticsAutomaticUploadEnabled + CustomerExperienceImprovementProgramEnabled = $testParams.CustomerExperienceImprovementProgramEnabled + ErrorReportingEnabled = $testParams.ErrorReportingEnabled + ErrorReportingAutomaticUploadEnabled = $testParams.ErrorReportingAutomaticUploadEnabled + DownloadErrorReportingUpdatesEnabled = $testParams.DownloadErrorReportingUpdatesEnabled + DaysToKeepLogs = $testParams.DaysToKeepLogs + LogMaxDiskSpaceUsageEnabled = $testParams.LogMaxDiskSpaceUsageEnabled + LogDiskSpaceUsageGB = 1 + LogLocation = $testParams.LogPath + LogCutInterval = $testParams.LogCutInterval + EventLogFloodProtectionEnabled = $testParams.EventLogFloodProtectionEnabled + EventLogFloodProtectionThreshold = $testParams.EventLogFloodProtectionThreshold + EventLogFloodProtectionTriggerPeriod = $testParams.EventLogFloodProtectionTriggerPeriod + EventLogFloodProtectionQuietPeriod = $testParams.EventLogFloodProtectionQuietPeriod + EventLogFloodProtectionNotifyInterval = $testParams.EventLogFloodProtectionNotifyInterval + ScriptErrorReportingEnabled = $testParams.ScriptErrorReportingEnabled + ScriptErrorReportingRequireAuth = $testParams.ScriptErrorReportingRequireAuth + ScriptErrorReportingDelay = $testParams.ScriptErrorReportingDelay + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file From 31ba5627800a3d0c97a4d09a8811cdbca56f9562 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 20:21:48 +1000 Subject: [PATCH 07/15] Updated VS project file with new files --- Tests/Tests.pssproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj index 2231e7604..390367d53 100644 --- a/Tests/Tests.pssproj +++ b/Tests/Tests.pssproj @@ -31,6 +31,8 @@ + + From 0ad6305c47d00bfaf38a62bd3a9398955be6c60e Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 23:31:15 +1000 Subject: [PATCH 08/15] Added more tests to cover further test methods --- .../MSFT_xSPFeature/MSFT_xSPFeature.psm1 | 8 +- ...int.xSPDiagnosticLoggingSettings.Tests.ps1 | 2 +- ...Point.xSPDistributedCacheService.Tests.ps1 | 74 ++++++++++ .../xSharePoint.xSPFeature.Tests.ps1 | 132 ++++++++++++++++++ .../xSharePoint.xSPInstall.Tests.ps1 | 43 ++++++ .../xSharePoint.xSPInstallPrereqs.Tests.ps1 | 81 +++++++++++ 6 files changed, 335 insertions(+), 5 deletions(-) create mode 100644 Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPInstallPrereqs.Tests.ps1 diff --git a/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 index cae7eface..9131b7c86 100644 --- a/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 +++ b/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 @@ -52,7 +52,6 @@ function Get-TargetResource Name = $params.Name Id = $feature.Id Version = $feature.Version - PathType = $path.Type Enabled = $enabled } } @@ -138,11 +137,12 @@ function Test-TargetResource $Ensure ) - $result = Get-TargetResource -Name $Name -FeatureScope $FeatureScope -Url $Url -InstallAccount $InstallAccount + $result = Get-TargetResource -Name $Name -FeatureScope $FeatureScope -Url $Url -InstallAccount $InstallAccount -Ensure $Ensure Write-Verbose "Testing for feature $Name at $FeatureScope scope" - if ($result.Count -eq 0) { return $false } - else { + if ($result.Count -eq 0) { + throw "Unable to locate feature '$Name' in the current SharePoint farm, check that the name is correct and that the feature has been deployed to the file system." + } else { if ($Ensure -eq "Present" -and $result.Enabled -eq $false) { return $false } if ($Ensure -eq "Absent" -and $result.Enabled -eq $true) { return $false } } diff --git a/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 index db37d0da1..4d1569206 100644 --- a/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1 @@ -14,7 +14,7 @@ $RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path $ModuleName = "MSFT_xSPDiagnosticLoggingSettings" Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") -Force -Describe "xSPCreateFarm" { +Describe "xSPDiagnosticLoggingSettings" { InModuleScope $ModuleName { $testParams = @{ LogPath = "L:\ULSLogs" diff --git a/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 new file mode 100644 index 000000000..1b6959eec --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 @@ -0,0 +1,74 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPDistributedCacheService" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPDistributedCacheService" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "AppFabricCache" + Ensure = "Present" + CacheSizeInMB = 1024 + ServiceAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + createFirewallRules = $true + } + + Context "Validate test method" { + It "Fails when no cache is present locally but should be" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when cache is present and size is correct" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + HostName = $env:COMPUTERNAME + Port = 22233 + CacheSizeInMB = $testParams.CacheSizeInMB + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when cache is present but size is not correct" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + HostName = $env:COMPUTERNAME + Port = 22233 + CacheSizeInMB = 1 + } + } + Test-TargetResource @testParams | Should Be $false + } + + $testParams.ENsure = "Absent" + + It "Fails when cache is present but not should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + HostName = $env:COMPUTERNAME + Port = 22233 + CacheSizeInMB = 1 + } + } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when cache is not present and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ } + } + Test-TargetResource @testParams | Should Be $true + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 new file mode 100644 index 000000000..8d3837851 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 @@ -0,0 +1,132 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPFeature" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPFeature" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "DemoFeature" + FeatureScope = "Farm" + Url = "http://site.sharepoint.com" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + Ensure = "Present" + } + + Context "Validate test method" { + It "Throws when a feature is not installed in the farm" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + { Test-TargetResource @testParams } | Should Throw "Unable to locate feature" + } + It "Passes when a farm feature is enabaled and should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $true + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when a farm feature is not enabaled and should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $false + } + } + Test-TargetResource @testParams | Should Be $false + } + + $testParams.Ensure = "Absent" + + It "Passes when a farm feature is not enabaled and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $false + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when a farm feature is enabaled and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $true + } + } + Test-TargetResource @testParams | Should Be $false + } + + $testParams.Ensure = "Present" + $testParams.FeatureScope = "Site" + + It "Passes when a site feature is enabaled and should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $true + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when a site feature is not enabaled and should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $false + } + } + Test-TargetResource @testParams | Should Be $false + } + + $testParams.Ensure = "Absent" + + It "Passes when a site feature is not enabaled and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $false + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when a site feature is enabaled and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Id = [Guid]::NewGuid() + Version = "1.0" + Enabled = $true + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 new file mode 100644 index 000000000..6951b651f --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 @@ -0,0 +1,43 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPInstall" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPInstall" { + InModuleScope $ModuleName { + $testParams = @{ + BinaryDir = "C:\SPInstall" + ProductKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" + } + + Context "Validate test method" { + It "Passes when SharePoint is installed" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + SharePointInstalled = $true + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when SharePoint is not installed" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + SharePointInstalled = $false + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPInstallPrereqs.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPInstallPrereqs.Tests.ps1 new file mode 100644 index 000000000..6c458ae4e --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPInstallPrereqs.Tests.ps1 @@ -0,0 +1,81 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPInstallPrereqs" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPInstallPrereqs" { + InModuleScope $ModuleName { + $testParams = @{ + InstallerPath = "C:\SPInstall" + OnlineMode = $true + } + + Context "Validate test method" { + It "Passes when all Prereqs are installed" { + Mock -ModuleName $ModuleName Get-TargetResource { + $returnValue = @{} + foreach($feature in "Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer".Split(",")) { + $returnValue.Add($feature, $true) + } + $returnValue.Add("Microsoft SQL Server 2008 R2 Native Client", $true) + $returnValue.Add("Microsoft Sync Framework Runtime v1.0 SP1 (x64)", $true) + $returnValue.Add("AppFabric 1.1 for Windows Server", $true) + $returnValue.Add("Microsoft Identity Extensions", $true) + $returnValue.Add("Active Directory Rights Management Services Client 2.0", $true) + $returnValue.Add("WCF Data Services 5.0 (for OData v3) Primary Components", $true) + $returnValue.Add("WCF Data Services 5.6.0 Runtime", $true) + $returnValue.Add("Microsoft CCR and DSS Runtime 2008 R3", $true) + return $returnValue + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when there are Windows Features missing" { + Mock -ModuleName $ModuleName Get-TargetResource { + $returnValue = @{} + foreach($feature in "Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer".Split(",")) { + $returnValue.Add($feature, $false) + } + $returnValue.Add("Microsoft SQL Server 2008 R2 Native Client", $true) + $returnValue.Add("Microsoft Sync Framework Runtime v1.0 SP1 (x64)", $true) + $returnValue.Add("AppFabric 1.1 for Windows Server", $true) + $returnValue.Add("Microsoft Identity Extensions", $true) + $returnValue.Add("Active Directory Rights Management Services Client 2.0", $true) + $returnValue.Add("WCF Data Services 5.0 (for OData v3) Primary Components", $true) + $returnValue.Add("WCF Data Services 5.6.0 Runtime", $true) + $returnValue.Add("Microsoft CCR and DSS Runtime 2008 R3", $true) + return $returnValue + } + Test-TargetResource @testParams | Should Be $false + } + It "Fails when there are software prereqs missing" { + Mock -ModuleName $ModuleName Get-TargetResource { + $returnValue = @{} + foreach($feature in "Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer".Split(",")) { + $returnValue.Add($feature, $false) + } + $returnValue.Add("Microsoft SQL Server 2008 R2 Native Client", $false) + $returnValue.Add("Microsoft Sync Framework Runtime v1.0 SP1 (x64)", $false) + $returnValue.Add("AppFabric 1.1 for Windows Server", $false) + $returnValue.Add("Microsoft Identity Extensions", $false) + $returnValue.Add("Active Directory Rights Management Services Client 2.0", $false) + $returnValue.Add("WCF Data Services 5.0 (for OData v3) Primary Components", $false) + $returnValue.Add("WCF Data Services 5.6.0 Runtime", $false) + $returnValue.Add("Microsoft CCR and DSS Runtime 2008 R3", $false) + return $returnValue + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file From 36cccda012e802755b2d0d6854f6062a7dec1a25 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 23:36:42 +1000 Subject: [PATCH 09/15] Fixing tabs in documents --- .../MSFT_xSPFeature/MSFT_xSPFeature.psm1 | 4 +-- ...Point.xSPDistributedCacheService.Tests.ps1 | 30 +++++++++---------- .../xSharePoint.xSPFeature.Tests.ps1 | 6 ++-- .../xSharePoint.xSPInstall.Tests.ps1 | 4 +-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 index 9131b7c86..9fda023c4 100644 --- a/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 +++ b/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 @@ -141,8 +141,8 @@ function Test-TargetResource Write-Verbose "Testing for feature $Name at $FeatureScope scope" if ($result.Count -eq 0) { - throw "Unable to locate feature '$Name' in the current SharePoint farm, check that the name is correct and that the feature has been deployed to the file system." - } else { + throw "Unable to locate feature '$Name' in the current SharePoint farm, check that the name is correct and that the feature has been deployed to the file system." + } else { if ($Ensure -eq "Present" -and $result.Enabled -eq $false) { return $false } if ($Ensure -eq "Absent" -and $result.Enabled -eq $true) { return $false } } diff --git a/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 index 1b6959eec..6fa0f575b 100644 --- a/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 @@ -18,11 +18,11 @@ Describe "xSPDistributedCacheService" { InModuleScope $ModuleName { $testParams = @{ Name = "AppFabricCache" - Ensure = "Present" - CacheSizeInMB = 1024 - ServiceAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) - InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) - createFirewallRules = $true + Ensure = "Present" + CacheSizeInMB = 1024 + ServiceAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + createFirewallRules = $true } Context "Validate test method" { @@ -34,36 +34,36 @@ Describe "xSPDistributedCacheService" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ HostName = $env:COMPUTERNAME - Port = 22233 - CacheSizeInMB = $testParams.CacheSizeInMB + Port = 22233 + CacheSizeInMB = $testParams.CacheSizeInMB } } Test-TargetResource @testParams | Should Be $true } - It "Fails when cache is present but size is not correct" { + It "Fails when cache is present but size is not correct" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ HostName = $env:COMPUTERNAME - Port = 22233 - CacheSizeInMB = 1 + Port = 22233 + CacheSizeInMB = 1 } } Test-TargetResource @testParams | Should Be $false } - $testParams.ENsure = "Absent" + $testParams.ENsure = "Absent" - It "Fails when cache is present but not should be" { + It "Fails when cache is present but not should be" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ HostName = $env:COMPUTERNAME - Port = 22233 - CacheSizeInMB = 1 + Port = 22233 + CacheSizeInMB = 1 } } Test-TargetResource @testParams | Should Be $false } - It "Passes when cache is not present and should not be" { + It "Passes when cache is not present and should not be" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ } } diff --git a/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 index 8d3837851..08fe3b5b0 100644 --- a/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPFeature.Tests.ps1 @@ -77,10 +77,10 @@ Describe "xSPFeature" { Test-TargetResource @testParams | Should Be $false } - $testParams.Ensure = "Present" - $testParams.FeatureScope = "Site" + $testParams.Ensure = "Present" + $testParams.FeatureScope = "Site" - It "Passes when a site feature is enabaled and should be" { + It "Passes when a site feature is enabaled and should be" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name diff --git a/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 index 6951b651f..42b4f5b6e 100644 --- a/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPInstall.Tests.ps1 @@ -18,7 +18,7 @@ Describe "xSPInstall" { InModuleScope $ModuleName { $testParams = @{ BinaryDir = "C:\SPInstall" - ProductKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" + ProductKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" } Context "Validate test method" { @@ -30,7 +30,7 @@ Describe "xSPInstall" { } Test-TargetResource @testParams | Should Be $true } - It "Fails when SharePoint is not installed" { + It "Fails when SharePoint is not installed" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ SharePointInstalled = $false From 3c7648f35784ed6fef200d688b7fa4cc8219e8a0 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sat, 25 Apr 2015 23:43:28 +1000 Subject: [PATCH 10/15] Added join farm test, updated VS proj --- Tests/Tests.pssproj | 5 +++ .../xSharePoint.xSPJoinFarm.Tests.ps1 | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Tests/xSharePoint/xSharePoint.xSPJoinFarm.Tests.ps1 diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj index 390367d53..4b0c56e4d 100644 --- a/Tests/Tests.pssproj +++ b/Tests/Tests.pssproj @@ -31,6 +31,11 @@ + + + + + diff --git a/Tests/xSharePoint/xSharePoint.xSPJoinFarm.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPJoinFarm.Tests.ps1 new file mode 100644 index 000000000..93eda2d79 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPJoinFarm.Tests.ps1 @@ -0,0 +1,44 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPJoinFarm" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPJoinFarm" { + InModuleScope $ModuleName { + $testParams = @{ + FarmConfigDatabaseName = "SP_Config" + DatabaseServer = "DatabaseServer\Instance" + FarmAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + Passphrase = "passphrase" + WaitTime = 60 + WaitCount = 60 + } + + Context "Validate test method" { + It "Fails when local server is not in a farm" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when local server is in a farm" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + FarmName = "SP_Config" + } + } + Test-TargetResource @testParams | Should Be $true + } + } + } +} \ No newline at end of file From 8004dc764193eeb5222eb6c81c8e6190a1efc84b Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sun, 26 Apr 2015 12:13:49 +1000 Subject: [PATCH 11/15] Tests for managed account, MMS and managed paths --- Tests/Tests.pssproj | 3 + .../xSharePoint.xSPManagedAccount.Tests.ps1 | 71 +++++++++++++++++++ ...int.xSPManagedMetadataServiceApp.Tests.ps1 | 52 ++++++++++++++ .../xSharePoint.xSPManagedPath.Tests.ps1 | 52 ++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 Tests/xSharePoint/xSharePoint.xSPManagedAccount.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPManagedMetadataServiceApp.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPManagedPath.Tests.ps1 diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj index 4b0c56e4d..132aa2938 100644 --- a/Tests/Tests.pssproj +++ b/Tests/Tests.pssproj @@ -31,6 +31,9 @@ + + + diff --git a/Tests/xSharePoint/xSharePoint.xSPManagedAccount.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPManagedAccount.Tests.ps1 new file mode 100644 index 000000000..d3a6d379e --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPManagedAccount.Tests.ps1 @@ -0,0 +1,71 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPManagedAccount" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPManagedAccount" { + InModuleScope $ModuleName { + $testParams = @{ + Account = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + EmailNotification = 7 + PreExpireDays = 7 + Schedule = "" + AccountName = "username" + } + + Context "Validate test method" { + It "Fails when managed account does not exist in the farm" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the account exists and has correct settings" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + AccountName = $testParams.AccountName + AutomaticChange = $false + DaysBeforeChangeToEmail = $testParams.EmailNotification + DaysBeforeExpiryToChange = $testParams.PreExpireDays + ChangeSchedule = $testParams.Schedule + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the account exists and the schedule doesnt match" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + AccountName = $testParams.AccountName + AutomaticChange = $true + DaysBeforeChangeToEmail = $testParams.EmailNotification + DaysBeforeExpiryToChange = $testParams.PreExpireDays + ChangeSchedule = "Weekly Friday between 01:00 and 02:00" + } + } + Test-TargetResource @testParams | Should Be $false + } + It "Fails when the account exists and the email settings dont match" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + AccountName = $testParams.AccountName + AutomaticChange = $true + DaysBeforeChangeToEmail = 0 + DaysBeforeExpiryToChange = 0 + ChangeSchedule = $testParams.Schedule + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPManagedMetadataServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPManagedMetadataServiceApp.Tests.ps1 new file mode 100644 index 000000000..f45ba8368 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPManagedMetadataServiceApp.Tests.ps1 @@ -0,0 +1,52 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPManagedMetaDataServiceApp" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPManagedMetaDataServiceApp" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Managed Metadata Service App" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + } + + Context "Validate test method" { + It "Fails when MMS service app doesn't exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the app exists and uses the correct app pool" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = $testParams.ApplicationPool + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the app exists but uses the wrong app pool" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = "wrong pool" + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPManagedPath.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPManagedPath.Tests.ps1 new file mode 100644 index 000000000..2e55533e3 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPManagedPath.Tests.ps1 @@ -0,0 +1,52 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPManagedPath" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPManagedPath" { + InModuleScope $ModuleName { + $testParams = @{ + WebAppUrl = "http://sites.sharepoint.com" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + RelativeUrl = "teams" + Explicit = $false + HostHeader = $false + } + + Context "Validate test method" { + It "Fails when path is not found" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the path is found and is the correct type" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.RelativeUrl + PathType = "WildcardInclusion" + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the path is found and is not the correct type" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.RelativeUrl + PathType = "ExplicitInclusion" + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file From 305497287cdde4e81dcf4757fc5d4c43df9fdf3f Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sun, 26 Apr 2015 12:46:47 +1000 Subject: [PATCH 12/15] Tests for search service app and service app pool --- .../xSharePoint.xSPSearchServiceApp.Tests.ps1 | 50 +++++++++++++++++++ .../xSharePoint.xSPServiceAppPool.Tests.ps1 | 50 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 Tests/xSharePoint/xSharePoint.xSPSearchServiceApp.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPServiceAppPool.Tests.ps1 diff --git a/Tests/xSharePoint/xSharePoint.xSPSearchServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPSearchServiceApp.Tests.ps1 new file mode 100644 index 000000000..b965d9f8b --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPSearchServiceApp.Tests.ps1 @@ -0,0 +1,50 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPSearchServiceApp" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPSearchServiceApp" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Search Service Application" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + ApplicationPool = "SharePoint Search Services" + } + + Context "Validate test method" { + It "Fails when service app is not found" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the path is found and is the correct type" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = $testParams.ApplicationPool + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the service app is found but uses the wrong app pool" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = "Wrong App Pool" + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPServiceAppPool.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPServiceAppPool.Tests.ps1 new file mode 100644 index 000000000..015d24025 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPServiceAppPool.Tests.ps1 @@ -0,0 +1,50 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPServiceAppPool" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPServiceAppPool" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Service pool" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + ServiceAccount = "DEMO\svcSPServiceApps" + } + + Context "Validate test method" { + It "Fails when service app pool is not found" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the pool exists and has the correct service account" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ProcessAccountName = $testParams.ServiceAccount + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the service app pool is found but uses the wrong service account" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ProcessAccountName = "Wrong account name" + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file From 7b935bd903315e1654a3254592ccd199e30776f1 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sun, 26 Apr 2015 15:02:18 +1000 Subject: [PATCH 13/15] Added more tests and fixed bug in usage app --- .../MSFT_xSPUsageApplication.psm1 | 22 +++-- Tests/Tests.pssproj | 6 ++ .../xSharePoint.xSPServiceInstance.Tests.ps1 | 71 +++++++++++++++ .../xSharePoint/xSharePoint.xSPSite.Tests.ps1 | 41 +++++++++ .../xSharePoint.xSPStateServiceApp.Tests.ps1 | 39 ++++++++ .../xSharePoint.xSPusageApplication.Tests.ps1 | 89 +++++++++++++++++++ 6 files changed, 256 insertions(+), 12 deletions(-) create mode 100644 Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPStateServiceApp.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 diff --git a/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 index c673bb8ee..0eb1800bc 100644 --- a/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 +++ b/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 @@ -27,8 +27,13 @@ function Get-TargetResource } else { + $service = Get-SPUsageService return @{ Name = $serviceApp.DisplayName + UsageLogCutTime = $service.UsageLogCutTime + UsageLogDir = $service.UsageLogDir + UsageLogMaxFileSize = $service.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $service.UsageLogMaxSpaceGB } } } @@ -157,19 +162,12 @@ function Test-TargetResource Write-Verbose "Testing for usage application '$Name'" if ($result.Count -eq 0) { return $false } else { - $session = Get-xSharePointAuthenticatedPSSession $InstallAccount - $returnVal = Invoke-Command -Session $session -ArgumentList $PSBoundParameters -ScriptBlock { - $params = $args[0] - - $service = Get-SPUsageService - if ($params.ContainsKey("UsageLogCutTime") -and $service.UsageLogCutTime -ne $params.UsageLogCutTime) { return $false } - if ($params.ContainsKey("UsageLogLocation") -and $service.UsageLogDir -ne $params.UsageLogLocation) { return $false } - if ($params.ContainsKey("UsageLogMaxFileSizeKB") -and $service.UsageLogMaxFileSize -ne $params.UsageLogMaxFileSizeKB) { return $false } - if ($params.ContainsKey("UsageLogMaxSpaceGB") -and $service.UsageLogMaxSpaceGB -ne $params.UsageLogMaxSpaceGB) { return $false } - return $true - } - return $returnVal + if ($PSBoundParameters.ContainsKey("UsageLogCutTime") -and $result.UsageLogCutTime -ne $UsageLogCutTime) { return $false } + if ($PSBoundParameters.ContainsKey("UsageLogLocation") -and $result.UsageLogDir -ne $UsageLogLocation) { return $false } + if ($PSBoundParameters.ContainsKey("UsageLogMaxFileSizeKB") -and $result.UsageLogMaxFileSize -ne $UsageLogMaxFileSizeKB) { return $false } + if ($PSBoundParameters.ContainsKey("UsageLogMaxSpaceGB") -and $result.UsageLogMaxSpaceGB -ne $UsageLogMaxSpaceGB) { return $false } } + return $true } diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj index 132aa2938..90d2c7ebd 100644 --- a/Tests/Tests.pssproj +++ b/Tests/Tests.pssproj @@ -31,6 +31,12 @@ + + + + + + diff --git a/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 new file mode 100644 index 000000000..9e51f8575 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 @@ -0,0 +1,71 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPServiceInstance" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPServiceInstance" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Service pool" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + Ensure = "Present" + } + + Context "Validate test method" { + It "Fails when service instance is not found at all" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the service instance is running and it should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Status = "Online" + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the service instance isn't running and it should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Status = "Disabled" + } + } + Test-TargetResource @testParams | Should Be $false + } + + $testParams.Ensure = "Absent" + + It "Fails when the service instance is running and it should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Status = "Online" + } + } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the service instance isn't running and it should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + Status = "Disabled" + } + } + Test-TargetResource @testParams | Should Be $true + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 new file mode 100644 index 000000000..aac34714e --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 @@ -0,0 +1,41 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPSite" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPSite" { + InModuleScope $ModuleName { + $testParams = @{ + Url = "http://site.sharepoint.com" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + OwnerAlias = "DEMO\User" + } + + Context "Validate test method" { + It "Fails when site collection isn't found" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the site collection is found" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Url = $testParams.Url + OwnerAlias = $testParams.OwnerAlias + } + } + Test-TargetResource @testParams | Should Be $true + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPStateServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPStateServiceApp.Tests.ps1 new file mode 100644 index 000000000..6a8979e8e --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPStateServiceApp.Tests.ps1 @@ -0,0 +1,39 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPStateServiceApp" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPStateServiceApp" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "State Service App" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + } + + Context "Validate test method" { + It "Fails when state service app doesn't exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the state service app exists" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + } + } + Test-TargetResource @testParams | Should Be $true + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 new file mode 100644 index 000000000..4a27e0242 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 @@ -0,0 +1,89 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPUsageApplication" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPUsageApplication" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Managed Metadata Service App" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + UsageLogCutTime = 60 + UsageLogLocation = "L:\UsageLogs" + UsageLogMaxFileSize = 1024 + UsageLogMaxSpaceGB = 10 + } + + Context "Validate test method" { + It "Fails when state service app doesn't exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the state service app exists and settings are corrent" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the state service app exists and settings are wrong" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = "C:\WrongPath" + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + } + } + Test-TargetResource @testParams | Should Be $false + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + UsageLogCutTime = 0 + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + } + } + Test-TargetResource @testParams | Should Be $false + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = 0 + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + } + } + Test-TargetResource @testParams | Should Be $false + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = 0 + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file From fed7060d10ac35007d8108c5eec74061fb18592b Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sun, 26 Apr 2015 15:34:09 +1000 Subject: [PATCH 14/15] Added last of the initial cut of unit tests --- .../MSFT_xSPUsageApplication.psm1 | 14 ++-- .../MSFT_xSPUserProfileSyncService.psm1 | 4 +- Tests/Tests.pssproj | 3 + .../xSharePoint/xSharePoint.xSPSite.Tests.ps1 | 2 +- ...rePoint.xSPUserProfileServiceApp.Tests.ps1 | 51 ++++++++++++++ ...ePoint.xSPUserProfileSyncService.Tests.ps1 | 69 +++++++++++++++++++ .../xSharePoint.xSPWebApplication.Tests.ps1 | 54 +++++++++++++++ .../xSharePoint.xSPusageApplication.Tests.ps1 | 56 +++++++-------- 8 files changed, 215 insertions(+), 38 deletions(-) create mode 100644 Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPUserProfileSyncService.Tests.ps1 create mode 100644 Tests/xSharePoint/xSharePoint.xSPWebApplication.Tests.ps1 diff --git a/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 index 0eb1800bc..a95722a35 100644 --- a/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 +++ b/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 @@ -27,13 +27,13 @@ function Get-TargetResource } else { - $service = Get-SPUsageService + $service = Get-SPUsageService return @{ Name = $serviceApp.DisplayName - UsageLogCutTime = $service.UsageLogCutTime - UsageLogDir = $service.UsageLogDir - UsageLogMaxFileSize = $service.UsageLogMaxFileSize - UsageLogMaxSpaceGB = $service.UsageLogMaxSpaceGB + UsageLogCutTime = $service.UsageLogCutTime + UsageLogDir = $service.UsageLogDir + UsageLogMaxFileSize = $service.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $service.UsageLogMaxSpaceGB } } } @@ -163,11 +163,11 @@ function Test-TargetResource if ($result.Count -eq 0) { return $false } else { if ($PSBoundParameters.ContainsKey("UsageLogCutTime") -and $result.UsageLogCutTime -ne $UsageLogCutTime) { return $false } - if ($PSBoundParameters.ContainsKey("UsageLogLocation") -and $result.UsageLogDir -ne $UsageLogLocation) { return $false } + if ($PSBoundParameters.ContainsKey("UsageLogLocation") -and $result.UsageLogDir -ne $UsageLogLocation) { return $false } if ($PSBoundParameters.ContainsKey("UsageLogMaxFileSizeKB") -and $result.UsageLogMaxFileSize -ne $UsageLogMaxFileSizeKB) { return $false } if ($PSBoundParameters.ContainsKey("UsageLogMaxSpaceGB") -and $result.UsageLogMaxSpaceGB -ne $UsageLogMaxSpaceGB) { return $false } } - return $true + return $true } diff --git a/Modules/xSharePoint/DSCResources/MSFT_xSPUserProfileSyncService/MSFT_xSPUserProfileSyncService.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPUserProfileSyncService/MSFT_xSPUserProfileSyncService.psm1 index 1f31e6aed..3ed9b3687 100644 --- a/Modules/xSharePoint/DSCResources/MSFT_xSPUserProfileSyncService/MSFT_xSPUserProfileSyncService.psm1 +++ b/Modules/xSharePoint/DSCResources/MSFT_xSPUserProfileSyncService/MSFT_xSPUserProfileSyncService.psm1 @@ -159,8 +159,8 @@ function Test-TargetResource Write-Verbose "Testing for User Profile Synchronization Service" if ($result.Count -eq 0) { return $false } else { - if (($syncService.Status -eq "Online") -and ($Ensure -ne "Present")) { return $false } - if (($syncService.Status -eq "Disabled") -and ($Ensure -ne "Absent")) { return $false } + if (($result.Status -eq "Online") -and ($Ensure -ne "Present")) { return $false } + if (($result.Status -eq "Disabled") -and ($Ensure -ne "Absent")) { return $false } } return $true } diff --git a/Tests/Tests.pssproj b/Tests/Tests.pssproj index 90d2c7ebd..7693ddab6 100644 --- a/Tests/Tests.pssproj +++ b/Tests/Tests.pssproj @@ -31,6 +31,9 @@ + + + diff --git a/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 index aac34714e..ef8aaaccc 100644 --- a/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPSite.Tests.ps1 @@ -31,7 +31,7 @@ Describe "xSPSite" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Url = $testParams.Url - OwnerAlias = $testParams.OwnerAlias + OwnerAlias = $testParams.OwnerAlias } } Test-TargetResource @testParams | Should Be $true diff --git a/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 new file mode 100644 index 000000000..b885dc275 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 @@ -0,0 +1,51 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPUserProfileServiceApp" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPUserProfileServiceApp" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Managed Metadata Service App" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + ApplicationPool = "SharePoint Service Applications" + FarmAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + } + + Context "Validate test method" { + It "Fails when user profile service app doesn't exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the user profile service app exists and uses the correct app pool" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = $testParams.ApplicationPool + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the user profile service app exists but uses the wrong app pool" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = "wrong pool" + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPUserProfileSyncService.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPUserProfileSyncService.Tests.ps1 new file mode 100644 index 000000000..9f65a2153 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPUserProfileSyncService.Tests.ps1 @@ -0,0 +1,69 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPUserProfileSyncService" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPUserProfileSyncService" { + InModuleScope $ModuleName { + $testParams = @{ + UserProfileServiceAppName = "Managed Metadata Service App" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + FarmAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + Ensure = "Present" + } + + Context "Validate test method" { + It "Fails when user profile sync service doesn't exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the user profile sync service is running and should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Status = "Online" + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the user profile sync service is not running and should be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Status = "Disabled" + } + } + Test-TargetResource @testParams | Should Be $false + } + + $testParams.Ensure = "Absent" + + It "Fails when the user profile sync service is running and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Status = "Online" + } + } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the user profile sync service is not running and should not be" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Status = "Disabled" + } + } + Test-TargetResource @testParams | Should Be $true + } + + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPWebApplication.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPWebApplication.Tests.ps1 new file mode 100644 index 000000000..0fbc8ea68 --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPWebApplication.Tests.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +param() + +if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 +{ + $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) +} + +$ErrorActionPreference = 'stop' +Set-StrictMode -Version latest + +$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path + +$ModuleName = "MSFT_xSPWebApplication" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPWebApplication" { + InModuleScope $ModuleName { + $testParams = @{ + Name = "Managed Metadata Service App" + InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + ApplicationPool = "SharePoint Web Apps" + ApplicationPoolAccount = "DEMO\ServiceAccount" + Url = "http://sites.sharepoint.com" + } + + Context "Validate test method" { + It "Fails when web app doesn't exist" { + Mock -ModuleName $ModuleName Get-TargetResource { return @{} } + Test-TargetResource @testParams | Should Be $false + } + It "Passes when the web app exists and has correct settings" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = $testParams.ApplicationPool + ApplicationPoolAccount = $testParams.ApplicationPoolAccount + } + } + Test-TargetResource @testParams | Should Be $true + } + It "Fails when the web app exists and has the wrong app pool" { + Mock -ModuleName $ModuleName Get-TargetResource { + return @{ + Name = $testParams.Name + ApplicationPool = "Wrong app pool" + ApplicationPoolAccount = $testParams.ApplicationPoolAccount + } + } + Test-TargetResource @testParams | Should Be $false + } + } + } +} \ No newline at end of file diff --git a/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 index 4a27e0242..b5767a52a 100644 --- a/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPusageApplication.Tests.ps1 @@ -19,10 +19,10 @@ Describe "xSPUsageApplication" { $testParams = @{ Name = "Managed Metadata Service App" InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) - UsageLogCutTime = 60 - UsageLogLocation = "L:\UsageLogs" - UsageLogMaxFileSize = 1024 - UsageLogMaxSpaceGB = 10 + UsageLogCutTime = 60 + UsageLogLocation = "L:\UsageLogs" + UsageLogMaxFileSize = 1024 + UsageLogMaxSpaceGB = 10 } Context "Validate test method" { @@ -34,52 +34,52 @@ Describe "xSPUsageApplication" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - UsageLogCutTime = $testParams.UsageLogCutTime - UsageLogDir = $testParams.UsageLogLocation - UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize - UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB } } Test-TargetResource @testParams | Should Be $true } - It "Fails when the state service app exists and settings are wrong" { + It "Fails when the state service app exists and settings are wrong" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - UsageLogCutTime = $testParams.UsageLogCutTime - UsageLogDir = "C:\WrongPath" - UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize - UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = "C:\WrongPath" + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB } } Test-TargetResource @testParams | Should Be $false - Mock -ModuleName $ModuleName Get-TargetResource { + Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - UsageLogCutTime = 0 - UsageLogDir = $testParams.UsageLogLocation - UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize - UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + UsageLogCutTime = 0 + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB } } Test-TargetResource @testParams | Should Be $false - Mock -ModuleName $ModuleName Get-TargetResource { + Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - UsageLogCutTime = $testParams.UsageLogCutTime - UsageLogDir = $testParams.UsageLogLocation - UsageLogMaxFileSize = 0 - UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = 0 + UsageLogMaxSpaceGB = $testParams.UsageLogMaxSpaceGB } } Test-TargetResource @testParams | Should Be $false - Mock -ModuleName $ModuleName Get-TargetResource { + Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - UsageLogCutTime = $testParams.UsageLogCutTime - UsageLogDir = $testParams.UsageLogLocation - UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize - UsageLogMaxSpaceGB = 0 + UsageLogCutTime = $testParams.UsageLogCutTime + UsageLogDir = $testParams.UsageLogLocation + UsageLogMaxFileSize = $testParams.UsageLogMaxFileSize + UsageLogMaxSpaceGB = 0 } } Test-TargetResource @testParams | Should Be $false From 16264350c68c6b484a7eaca1500756dbd684b5a7 Mon Sep 17 00:00:00 2001 From: Brian Farnhill Date: Sun, 26 Apr 2015 15:37:25 +1000 Subject: [PATCH 15/15] Removing spaces to pass formatting tests --- .../xSharePoint.xSPServiceInstance.Tests.ps1 | 12 ++++++------ .../xSharePoint.xSPUserProfileServiceApp.Tests.ps1 | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 index 9e51f8575..9d4816d92 100644 --- a/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 @@ -31,7 +31,7 @@ Describe "xSPServiceInstance" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - Status = "Online" + Status = "Online" } } Test-TargetResource @testParams | Should Be $true @@ -40,19 +40,19 @@ Describe "xSPServiceInstance" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - Status = "Disabled" + Status = "Disabled" } } Test-TargetResource @testParams | Should Be $false } - $testParams.Ensure = "Absent" + $testParams.Ensure = "Absent" - It "Fails when the service instance is running and it should not be" { + It "Fails when the service instance is running and it should not be" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - Status = "Online" + Status = "Online" } } Test-TargetResource @testParams | Should Be $false @@ -61,7 +61,7 @@ Describe "xSPServiceInstance" { Mock -ModuleName $ModuleName Get-TargetResource { return @{ Name = $testParams.Name - Status = "Disabled" + Status = "Disabled" } } Test-TargetResource @testParams | Should Be $true diff --git a/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 index b885dc275..4eda24896 100644 --- a/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 +++ b/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 @@ -20,7 +20,7 @@ Describe "xSPUserProfileServiceApp" { Name = "Managed Metadata Service App" InstallAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) ApplicationPool = "SharePoint Service Applications" - FarmAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) + FarmAccount = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) } Context "Validate test method" {