Skip to content

Commit

Permalink
Fix test and added Export test
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Apr 6, 2021
1 parent 8cf6d64 commit 759aa49
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function Export-TargetResource
$currentBlock = Convert-DSCStringParamToVariable -DSCBlock $currentBlock -ParameterName "PsDscRunAsCredential"

$PartialContent += $currentBlock
$PartialContent += " }`r`n`r`n"
$PartialContent += " }`r`n"
$Content += $PartialContent
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ try

if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -ne 15)
{
$testParams.UsageDatabaseEnabled = $false
$testParams.UsageDatabaseEnabled = $true
}
}

Expand Down Expand Up @@ -228,6 +228,65 @@ try
{ Set-TargetResource @testParams } | Should -Throw "This resource cannot remove a Usage Definition. Please use ensure equals Present."
}
}

Context -Name "Running ReverseDsc Export" -Fixture {
BeforeAll {
Import-Module (Join-Path -Path (Split-Path -Path (Get-Module SharePointDsc -ListAvailable).Path -Parent) -ChildPath "Modules\SharePointDSC.Reverse\SharePointDSC.Reverse.psm1")

Mock -CommandName Write-Host -MockWith { }

Mock -CommandName Get-TargetResource -MockWith {
return @{
Name = "Administrative Actions"
DaysRetained = 14
DaysToKeepUsageFiles = 1
MaxTotalSizeInBytes = 10000000000000
Enabled = $true
Ensure = "Present"
}
}

if ($null -eq (Get-Variable -Name 'spFarmAccount' -ErrorAction SilentlyContinue))
{
$mockPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
$Global:spFarmAccount = New-Object -TypeName System.Management.Automation.PSCredential ("contoso\spfarm", $mockPassword)
}

if ($null -eq (Get-Variable -Name 'DynamicCompilation' -ErrorAction SilentlyContinue))
{
$DynamicCompilation = $false
}

if ($null -eq (Get-Variable -Name 'StandAlone' -ErrorAction SilentlyContinue))
{
$StandAlone = $true
}

if ($null -eq (Get-Variable -Name 'ExtractionModeValue' -ErrorAction SilentlyContinue))
{
$Global:ExtractionModeValue = 2
$Global:ComponentsToExtract = @('SPFarm')
}

$result = @'
SPUsageDefinition UsageDefinition_AdministrativeActions
{
DaysRetained = 14;
DaysToKeepUsageFiles = 1;
Enabled = $True;
Ensure = "Present";
MaxTotalSizeInBytes = 10000000000000;
Name = "Administrative Actions";
PsDscRunAsCredential = $Credsspfarm;
}
'@
}

It "Should return valid DSC block from the Export method" {
Export-TargetResource | Should -Be $result
}
}
}
}
}
Expand Down

0 comments on commit 759aa49

Please sign in to comment.