Skip to content

Commit

Permalink
Merge pull request #80 from BrianFarnhill/Bug-FixGetMethodReturnValues
Browse files Browse the repository at this point in the history
Review and repair Get methods on all resources, refactored for better mocking approaches
  • Loading branch information
BrianFarnhill committed Sep 26, 2015
2 parents 668e5c8 + 3fd03a4 commit 530f5ed
Show file tree
Hide file tree
Showing 66 changed files with 46,097 additions and 4,092 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,34 @@ function Get-TargetResource
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$Name,

[parameter(Mandatory = $true)]
[System.String]
$ApplicationPool,

[parameter(Mandatory = $true)]
[System.String]
$DatabaseName,

[parameter(Mandatory = $true)]
[System.String]
$DatabaseServer,

[parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
$InstallAccount
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.String] $ApplicationPool,
[parameter(Mandatory = $false)] [System.String] $DatabaseName,
[parameter(Mandatory = $false)] [System.String] $DatabaseServer,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Getting BCS service app '$Name'"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
try
{
$serviceApp = Get-xSharePointServiceApplication -Name $params.Name -TypeName BCS

If ($null -eq $serviceApp)
{
return @{}
}
else
{
return @{
Name = $serviceApp.DisplayName
ApplicationPool = $serviceApp.ApplicationPool.Name
}

$serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue
if ($null -eq $serviceApps) {
return $null
}
$serviceApp = $serviceApps | Where-Object { $_.TypeName -eq "Business Data Connectivity Service Application" }

If ($null -eq $serviceApp) {
return $null
} else {
$returnVal = @{
Name = $serviceApp.DisplayName
ApplicationPool = $serviceApp.ApplicationPool.Name
DatabaseName = $serviceApp.Database.Name
DatabaseServer = $serviceApp.Database.Server.Name
InstallAccount = $params.InstallAccount
}
}
catch
{
return @{ }
return $returnVal
}
}
return $result
Expand All @@ -59,25 +43,11 @@ function Set-TargetResource
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[System.String]
$Name,

[parameter(Mandatory = $true)]
[System.String]
$ApplicationPool,

[parameter(Mandatory = $true)]
[System.String]
$DatabaseName,

[parameter(Mandatory = $true)]
[System.String]
$DatabaseServer,

[parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
$InstallAccount
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.String] $ApplicationPool,
[parameter(Mandatory = $false)] [System.String] $DatabaseName,
[parameter(Mandatory = $false)] [System.String] $DatabaseServer,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

$result = Get-TargetResource @PSBoundParameters
Expand All @@ -86,27 +56,26 @@ function Set-TargetResource
Write-Verbose -Message "Creating BCS Service Application $Name"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
Invoke-xSharePointSPCmdlet -CmdletName "New-SPBusinessDataCatalogServiceApplication" -Arguments @{
Name = $params.Name
ApplicationPool = $params.ApplicationPool
DatabaseName = $params.DatabaseName
DatabaseServer = $params.DatabaseServer
}


New-SPBusinessDataCatalogServiceApplication -Name $params.Name `
-ApplicationPool $params.ApplicationPool `
-DatabaseName $params.DatabaseName `
-DatabaseServer $params.DatabaseServer
}
}
else {
if ($ApplicationPool -ne $result.ApplicationPool) {
Write-Verbose -Message "Updating BCS Service Application $Name"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
$serviceApp = Get-xSharePointServiceApplication -Name $params.Name -TypeName "BCS"
$appPool = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPServiceApplicationPool" @{
Identity = $params.ApplicationPool
}
Invoke-xSharePointSPCmdlet -CmdletName "Set-SPBusinessDataCatalogServiceApplication" -Arguments @{
Identity = $serviceApp
ApplicationPool = $appPool
}


$appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool

Get-SPServiceApplication -Name $params.Name `
| Where-Object { $_.TypeName -eq "Business Data Connectivity Service Application" } `
| Set-SPBusinessDataCatalogServiceApplication -ApplicationPool $appPool
}
}
}
Expand All @@ -118,34 +87,18 @@ function Test-TargetResource
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$Name,

[parameter(Mandatory = $true)]
[System.String]
$ApplicationPool,

[parameter(Mandatory = $true)]
[System.String]
$DatabaseName,

[parameter(Mandatory = $true)]
[System.String]
$DatabaseServer,

[parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
$InstallAccount
[parameter(Mandatory = $true)] [System.String] $Name,
[parameter(Mandatory = $true)] [System.String] $ApplicationPool,
[parameter(Mandatory = $false)] [System.String] $DatabaseName,
[parameter(Mandatory = $false)] [System.String] $DatabaseServer,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)
$result = Get-TargetResource @PSBoundParameters

Write-Verbose -Message "Testing for BCS Service Application '$Name'"
if ($result.Count -eq 0) { return $false }
else {
if ($ApplicationPool -ne $result.ApplicationPool) { return $false }
}
return $true
$CurrentValues = Get-TargetResource @PSBoundParameters

if ($null -eq $CurrentValues) { return $false }
return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("ApplicationPool")
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,35 @@ function Get-TargetResource
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$WebAppUrl,

[parameter(Mandatory = $true)]
[System.String]
$SuperUserAlias,

[parameter(Mandatory = $true)]
[System.String]
$SuperReaderAlias,

[parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
$InstallAccount
[parameter(Mandatory = $true)] [System.String] $WebAppUrl,
[parameter(Mandatory = $true)] [System.String] $SuperUserAlias,
[parameter(Mandatory = $true)] [System.String] $SuperReaderAlias,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Getting cache accounts for $WebAppUrl"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
$wa = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPWebApplication" -Arguments @{ Identity = $params.WebAppUrl } -ErrorAction SilentlyContinue


$wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue

if ($null -eq $wa) { return @{} }

$returnVal = @{}
$returnVal.Add("WebAppUrl", $params.WebAppUrl)
if ($wa.Properties.ContainsKey("portalsuperuseraccount")) {
$returnVal.Add("portalsuperuseraccount", $wa.Properties["portalsuperuseraccount"])
$returnVal.Add("SuperUserAlias", $wa.Properties["portalsuperuseraccount"])
} else {
$returnVal.Add("portalsuperuseraccount", "")
$returnVal.Add("SuperUserAlias", "")
}
if ($wa.Properties.ContainsKey("portalsuperreaderaccount")) {
$returnVal.Add("portalsuperreaderaccount", $wa.Properties["portalsuperreaderaccount"])
$returnVal.Add("SuperReaderAlias", $wa.Properties["portalsuperreaderaccount"])
} else {
$returnVal.Add("portalsuperreaderaccount", "")
$returnVal.Add("SuperReaderAlias", "")
}

$returnVal.Add("InstallAccount", $params.InstallAccount)
return $returnVal
}
return $result
Expand All @@ -53,29 +44,22 @@ function Set-TargetResource
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[System.String]
$WebAppUrl,

[parameter(Mandatory = $true)]
[System.String]
$SuperUserAlias,

[parameter(Mandatory = $true)]
[System.String]
$SuperReaderAlias,

[parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
$InstallAccount
[parameter(Mandatory = $true)] [System.String] $WebAppUrl,
[parameter(Mandatory = $true)] [System.String] $SuperUserAlias,
[parameter(Mandatory = $true)] [System.String] $SuperReaderAlias,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Setting cache accounts for $WebAppUrl"

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


$wa = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPWebApplication" -Arguments @{ Identity = $params.WebAppUrl }
$wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue
if ($null -eq $wa) {
throw [Exception] "The web applications $($params.WebAppUrl) can not be found to set cache accounts"
}

if ($wa.Properties.ContainsKey("portalsuperuseraccount")) {
$wa.Properties["portalsuperuseraccount"] = $params.SuperUserAlias
Expand All @@ -102,32 +86,16 @@ function Test-TargetResource
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$WebAppUrl,

[parameter(Mandatory = $true)]
[System.String]
$SuperUserAlias,

[parameter(Mandatory = $true)]
[System.String]
$SuperReaderAlias,

[parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
$InstallAccount
[parameter(Mandatory = $true)] [System.String] $WebAppUrl,
[parameter(Mandatory = $true)] [System.String] $SuperUserAlias,
[parameter(Mandatory = $true)] [System.String] $SuperReaderAlias,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

$result = Get-TargetResource @PSBoundParameters
$CurrentValues = Get-TargetResource @PSBoundParameters
Write-Verbose -Message "Testing cache accounts for $WebAppUrl"

if ($result.Count -eq 0) { return $false }
else {
if ($SuperUserAlias -ne $result.portalsuperuseraccount) { return $false }
if ($SuperReaderAlias -ne $result.portalsuperreaderaccount) { return $false }
}
return $true
if ($null -eq $CurrentValues) {return $false }
return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("SuperUserAlias", "SuperReaderAlias")
}

Export-ModuleMember -Function *-TargetResource
Loading

0 comments on commit 530f5ed

Please sign in to comment.