Skip to content

Commit

Permalink
Merge pull request #82 from BrianFarnhill/Bug-FixGetMethodReturnValues
Browse files Browse the repository at this point in the history
Minor bug fixes for SP2016
  • Loading branch information
BrianFarnhill committed Sep 27, 2015
2 parents 530f5ed + 98d527f commit e3e0232
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ function Set-TargetResource
[parameter(Mandatory = $false)] [System.String] $Schedule,
[parameter(Mandatory = $true)] [System.String] $AccountName
)

Write-Verbose -Message "Setting managed account $AccountName"

Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


$current = Get-TargetResource @params
if ($current.Count -eq 0) {
if ($null -eq (Get-TargetResource @PSBoundParameters)) {
Write-Verbose "Creating a new managed account"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
New-SPManagedAccount -Credential $params.Account
}
}

Write-Verbose -Message "Updating settings for managed account"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

$updateParams = @{
Identity = $params.Account.UserName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,36 @@ function Set-TargetResource
)

$result = Get-TargetResource @PSBoundParameters
$params = $PSBoundParameters

switch((Get-xSharePointInstalledProductVersion).FileMajorPart) {
16 {
$hasOptionalParams = $false
@("AuditlogMaxSize","DatabaseName","DatabasePassword","DatabaseServer","DatabaseUsername", `
"FailoverDatabaseServer","PartitionMode","Sharing","DatabaseCredentials") | ForEach-Object {
if ($PSBoundParameters.ContainsKey($_) -eq $true) { $hasOptionalParams = $true }
}
if ($hasOptionalParams -eq $false) {
# Add the MinDB param to ensure that the cmdlet call gets differentiated without the optional params being set
$params.Add("EnableMinDB", $false)
}
}
}

if ($result.Count -eq 0) {
if ($null -eq $result) {
Write-Verbose -Message "Creating Secure Store Service Application $Name"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $params -ScriptBlock {
$params = $args[0]


if ($params.ContainsKey("InstallAccount")) { $params.Remove("InstallAccount") | Out-Null }

switch((Get-xSharePointInstalledProductVersion).FileMajorPart) {
15 {
$app = New-SPSecureStoreServiceApplication @params
}
16 {
$app = New-SPSecureStoreServiceApplication @params -EnableMinDB:$false
}
Default {
throw [Exception] "An unknown version of SharePoint (Major version $_) was detected. Only versions 15 (SharePoint 2013) or 16 (SharePoint 2016) are supported."
}
}
if ($app) {
New-SPSecureStoreServiceApplicationProxy -Name "$($params.Name) Proxy" -ServiceApplication $app
}
New-SPSecureStoreServiceApplication @params | New-SPSecureStoreServiceApplicationProxy -Name "$($params.Name) Proxy"
}
} else {
if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false -and $ApplicationPool -ne $result.ApplicationPool) {
Write-Verbose -Message "Updating Secure Store Service Application $Name"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


$serviceApp = Get-SPServiceApplication -Name $params.Name | Where-Object { $_.TypeName -eq "Secure Store Service Application" }
$appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ function Get-TargetResource
}
else
{
$databases = Get-UserProfileServiceProperties $serviceApp
$databases = @{}
$propData = $serviceApp.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic)

$socialProp = $propData | Where-Object {$_.Name -eq "SocialDatabase"}
$databases.Add("SocialDatabase", $socialProp.GetValue($serviceApp))

$profileProp = $propData | Where-Object {$_.Name -eq "ProfileDatabase"}
$databases.Add("ProfileDatabase", $profileProp.GetValue($serviceApp))

$syncProp = $propData | Where-Object {$_.Name -eq "SynchronizationDatabase"}
$databases.Add("SynchronizationDatabase", $syncProp.GetValue($serviceApp))

$spFarm = Get-SPFarm

if ($params.FarmAccount.UserName -eq $spFarm.DefaultServiceAccount.Name) {
Expand All @@ -62,28 +73,6 @@ function Get-TargetResource
return $result
}

function Get-UserProfileServiceProperties() {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)] [System.String] $serviceApp
)
$results = @{}
$propData = $serviceApp.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic)

$socialProp = $propData | Where-Object {$_.Name -eq "SocialDatabase"}
$results.Add("SocialDatabase", $socialProp.GetValue($serviceApp))

$profileProp = $propData | Where-Object {$_.Name -eq "ProfileDatabase"}
$results.Add("ProfileDatabase", $profileProp.GetValue($serviceApp))

$syncProp = $propData | Where-Object {$_.Name -eq "SynchronizationDatabase"}
$results.Add("SynchronizationDatabase", $syncProp.GetValue($serviceApp))

return $results
}

function Set-TargetResource
{
[CmdletBinding()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function Get-TargetResource
[parameter(Mandatory = $true)] [System.Management.Automation.PSCredential] $FarmAccount,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

if ((Get-xSharePointInstalledProductVersion).FileMajorPart -ne 15) {
throw [Exception] "Only SharePoint 2013 is supported to deploy the user profile sync service via DSC, as 2016 does not use the FIM based sync service."
}

Write-Verbose -Message "Getting the local user profile sync service instance"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
Expand Down Expand Up @@ -59,6 +64,10 @@ function Set-TargetResource
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

if ((Get-xSharePointInstalledProductVersion).FileMajorPart -ne 15) {
throw [Exception] "Only SharePoint 2013 is supported to deploy the user profile sync service via DSC, as 2016 does not use the FIM based sync service."
}

Write-Verbose -Message "Setting User Profile Synchronization Service"

# Add the FarmAccount to the local Admins group, if it's not already there
Expand Down Expand Up @@ -129,6 +138,10 @@ function Test-TargetResource
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

if ((Get-xSharePointInstalledProductVersion).FileMajorPart -ne 15) {
throw [Exception] "Only SharePoint 2013 is supported to deploy the user profile sync service via DSC, as 2016 does not use the FIM based sync service."
}

$CurrentValues = Get-TargetResource @PSBoundParameters
Write-Verbose -Message "Testing for User Profile Synchronization Service"
return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Ensure")
Expand Down
15 changes: 14 additions & 1 deletion Tests/xSharePoint/xSharePoint.xSPBCSServiceApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Describe "xSPBCSServiceApp" {

Import-Module $Global:CurrentSharePointStubModule -WarningAction SilentlyContinue

Context "When no service application exists in the current farm" {
Context "When no service applications exist in the current farm" {

Mock Get-SPServiceApplication { return $null }
Mock New-SPBusinessDataCatalogServiceApplication { }
Expand All @@ -54,6 +54,19 @@ Describe "xSPBCSServiceApp" {
}
}

Context "When service applications exist in the current farm but the specific BCS app does not" {

Mock Get-SPServiceApplication { return @(@{
TypeName = "Some other service app type"
}) }

It "returns null from the Get method" {
Get-TargetResource @testParams | Should BeNullOrEmpty
Assert-MockCalled Get-SPServiceApplication -ParameterFilter { $Name -eq $testParams.Name }
}

}

Context "When a service application exists and is configured correctly" {
Mock Get-SPServiceApplication {
return @(@{
Expand Down
61 changes: 42 additions & 19 deletions Tests/xSharePoint/xSharePoint.xSPUserProfileServiceApp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ Describe "xSPUserProfileServiceApp" {

Import-Module $Global:CurrentSharePointStubModule -WarningAction SilentlyContinue

Mock Get-UserProfileServiceProperties { return @{
ProfileDatabase = @{
Name = "SP_ProfileDB"
Server = @{ Name = "SQL.domain.local" }
}
SocialDatabase = @{
Name = "SP_SocialDB"
Server = @{ Name = "SQL.domain.local" }
}
SynchronizationDatabase = @{
Name = "SP_SyncDB"
Server = @{ Name = "SQL.domain.local" }
}
}}
Mock Get-SPFarm { return @{
DefaultServiceAccount = @{ Name = $testParams.FarmAccount.Username }
}}
Expand Down Expand Up @@ -72,11 +58,48 @@ Describe "xSPUserProfileServiceApp" {

Context "When a service application exists and is configured correctly" {
Mock Get-SPServiceApplication {
return @(@{
TypeName = "User Profile Service Application"
DisplayName = $testParams.Name
ApplicationPool = @{ Name = $testParams.ApplicationPool }
})
return @(
New-Object Object |
Add-Member NoteProperty TypeName "User Profile Service Application" -PassThru |
Add-Member NoteProperty DisplayName $testParams.Name -PassThru |
Add-Member NoteProperty ApplicationPool @{ Name = $testParams.ApplicationPool } -PassThru |
Add-Member ScriptMethod GetType {
New-Object Object |
Add-Member ScriptMethod GetProperties {
param($x)
return @(
(New-Object Object |
Add-Member NoteProperty Name "SocialDatabase" -PassThru |
Add-Member ScriptMethod GetValue {
param($x)
return @{
Name = "SP_SocialDB"
Server = @{ Name = "SQL.domain.local" }
}
} -PassThru
),
(New-Object Object |
Add-Member NoteProperty Name "ProfileDatabase" -PassThru |
Add-Member ScriptMethod GetValue {
return @{
Name = "SP_ProfileDB"
Server = @{ Name = "SQL.domain.local" }
}
} -PassThru
),
(New-Object Object |
Add-Member NoteProperty Name "SynchronizationDatabase" -PassThru |
Add-Member ScriptMethod GetValue {
return @{
Name = "SP_ProfileSyncDB"
Server = @{ Name = "SQL.domain.local" }
}
} -PassThru
)
)
} -PassThru
} -PassThru -Force
)
}

It "returns values from the get method" {
Expand Down
Loading

0 comments on commit e3e0232

Please sign in to comment.