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/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPFeature/MSFT_xSPFeature.psm1 index cae7eface..9fda023c4 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/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 b/Modules/xSharePoint/DSCResources/MSFT_xSPUsageApplication/MSFT_xSPUsageApplication.psm1 index c673bb8ee..a95722a35 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/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 new file mode 100644 index 000000000..7693ddab6 --- /dev/null +++ b/Tests/Tests.pssproj @@ -0,0 +1,58 @@ + + + + Debug + 2.0 + {279294c4-e197-48cd-a1fb-263ce47dea4d} + 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..659d96db6 --- /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 diff --git a/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1 new file mode 100644 index 000000000..dbf2952ac --- /dev/null +++ b/Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.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_xSPBCSServiceApp" +Import-Module (Join-Path $RepoRoot "Modules\xSharePoint\DSCResources\$ModuleName\$ModuleName.psm1") + +Describe "xSPBCSServiceApp" { + 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)) + } + + 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 + } + } + 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/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..4d1569206 --- /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 "xSPDiagnosticLoggingSettings" { + 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 diff --git a/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPDistributedCacheService.Tests.ps1 new file mode 100644 index 000000000..6fa0f575b --- /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..08fe3b5b0 --- /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..42b4f5b6e --- /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 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 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 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 diff --git a/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPServiceInstance.Tests.ps1 new file mode 100644 index 000000000..9d4816d92 --- /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..ef8aaaccc --- /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.xSPUserProfileServiceApp.Tests.ps1 b/Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1 new file mode 100644 index 000000000..4eda24896 --- /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 new file mode 100644 index 000000000..b5767a52a --- /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 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