-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from BrianFarnhill/feature-SharePointTests
Added tests for all DSC resource "test" methods
- Loading branch information
Showing
28 changed files
with
1,461 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{279294c4-e197-48cd-a1fb-263ce47dea4d}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>MyApplication</RootNamespace> | ||
<AssemblyName>MyApplication</AssemblyName> | ||
<Name>Tests</Name> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Folder Include="xSharePoint\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="xSharePoint\xSharePoint.Global.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPWebApplication.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPUserProfileSyncService.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPUserProfileServiceApp.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPusageApplication.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPStateServiceApp.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPSite.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPServiceInstance.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPServiceAppPool.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPSearchServiceApp.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPManagedPath.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPManagedMetadataServiceApp.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPManagedAccount.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPJoinFarm.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPInstallPrereqs.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPInstall.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPFeature.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPDistributedCacheService.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPDiagnosticLoggingSettings.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPCreateFarm.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPCacheAccounts.Tests.ps1" /> | ||
<Content Include="xSharePoint\xSharePoint.xSPBCSServiceApp.Tests.ps1" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="Build" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.