Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit c3be6db

Browse files
committed
Complete tests
1 parent cf8bd9f commit c3be6db

File tree

1 file changed

+110
-4
lines changed

1 file changed

+110
-4
lines changed

Tests/Unit/DscResource.DocumentationHelper.Tests.ps1

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ Configuration CertificateExport_CertByFriendlyName_Config
924924
$mockGitUserEmail = '[email protected]'
925925
$mockGitUserName = 'mock'
926926
$mockGithubAccessToken = '1234567890'
927-
$mockPath = "C:\Windows\Temp"
927+
$mockPath = $env:temp
928928
$mockJobId = 'imy2wgh1ylo9qcpb'
929929
$mockBuildVersion = '2.1.456.0'
930930
$mockapiUrl = 'https://ci.appveyor.com/api'
@@ -1383,6 +1383,7 @@ Configuration Example
13831383
$script:mockReadmePath = Join-Path -Path $script:mockSchemaFolder -ChildPath 'readme.md'
13841384
$script:mockOutputFile = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
13851385
$script:mockSavePath = Join-Path -Path $script:mockModulePath -ChildPath "DscResources\$($script:mockResourceName)\en-US\about_$($script:mockResourceName).help.txt"
1386+
$script:mockOutputSavePath = Join-Path -Path $script:mockOutputPath -ChildPath "about_$($script:mockResourceName).help.txt"
13861387
$script:mockGetContentReadme = '# Description
13871388
13881389
The description of the resource.'
@@ -1455,6 +1456,10 @@ Configuration Example
14551456
$InputObject -eq $script:mockPowerShellHelpOutput -and
14561457
$FilePath -eq $script:mockSavePath
14571458
}
1459+
$script:outFileOutputInputObject_parameterFilter = {
1460+
$InputObject -eq $script:mockPowerShellHelpOutput -and
1461+
$FilePath -eq $script:mockOutputSavePath
1462+
}
14581463
$script:writeWarningDescription_parameterFilter = {
14591464
$Message -eq ($script:localizedData.NoDescriptionFileFoundWarning -f $mockResourceName)
14601465
}
@@ -1465,6 +1470,10 @@ Configuration Example
14651470
$script:newDscResourcePowerShellHelp_parameters = @{
14661471
ModulePath = $script:mockModulePath
14671472
}
1473+
$script:newDscResourcePowerShellHelpOutput_parameters = @{
1474+
ModulePath = $script:mockModulePath
1475+
OutputPath = $script:mockOutputPath
1476+
}
14681477

14691478
Context 'When there is no schemas found in the module folder' {
14701479
BeforeAll {
@@ -1621,7 +1630,7 @@ Configuration Example
16211630
}
16221631
}
16231632

1624-
Context 'When there is one schema found in the module folder and one example using .EXAMPLE' {
1633+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is specified' {
16251634
BeforeAll {
16261635
Mock `
16271636
-CommandName Get-ChildItem `
@@ -1654,8 +1663,105 @@ Configuration Example
16541663
-MockWith { $script:mockExampleContent }
16551664

16561665
Mock `
1666+
-CommandName Out-File
1667+
1668+
Mock `
1669+
-CommandName Write-Warning `
1670+
-ParameterFilter $script:writeWarningExample_parameterFilter
1671+
1672+
Mock `
1673+
-CommandName Write-Warning `
1674+
-ParameterFilter $script:writeWarningDescription_parameterFilter
1675+
}
1676+
1677+
It 'Should not throw an exception' {
1678+
{ New-DscResourcePowerShellHelp @script:newDscResourcePowerShellHelpOutput_parameters } | Should -Not -Throw
1679+
}
1680+
1681+
It 'Should produce the correct output' {
1682+
Assert-MockCalled `
16571683
-CommandName Out-File `
1658-
-ParameterFilter $script:outFile_parameterFilter
1684+
-ParameterFilter $script:outFileOutputInputObject_parameterFilter `
1685+
-Exactly -Times 1
1686+
}
1687+
1688+
It 'Should call the expected mocks ' {
1689+
Assert-MockCalled `
1690+
-CommandName Get-ChildItem `
1691+
-ParameterFilter $script:getChildItemSchema_parameterFilter `
1692+
-Exactly -Times 1
1693+
1694+
Assert-MockCalled `
1695+
-CommandName Get-MofSchemaObject `
1696+
-ParameterFilter $script:getMofSchemaObjectSchema_parameterfilter `
1697+
-Exactly -Times 1
1698+
1699+
Assert-MockCalled `
1700+
-CommandName Test-Path `
1701+
-ParameterFilter $script:getTestPathReadme_parameterFilter `
1702+
-Exactly -Times 1
1703+
1704+
Assert-MockCalled `
1705+
-CommandName Get-Content `
1706+
-ParameterFilter $script:getContentReadme_parameterFilter `
1707+
-Exactly -Times 1
1708+
1709+
Assert-MockCalled `
1710+
-CommandName Get-ChildItem `
1711+
-ParameterFilter $script:getChildItemExample_parameterFilter `
1712+
-Exactly -Times 1
1713+
1714+
Assert-MockCalled `
1715+
-CommandName Get-DscResourceHelpExampleContent `
1716+
-ParameterFilter $script:getDscResourceHelpExampleContent_parameterFilter `
1717+
-Exactly -Times 1
1718+
1719+
Assert-MockCalled `
1720+
-CommandName Write-Warning `
1721+
-ParameterFilter $script:writeWarningExample_parameterFilter `
1722+
-Exactly -Times 0
1723+
1724+
Assert-MockCalled `
1725+
-CommandName Write-Warning `
1726+
-ParameterFilter $script:writeWarningDescription_parameterFilter `
1727+
-Exactly -Times 0
1728+
}
1729+
}
1730+
1731+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is not specified' {
1732+
BeforeAll {
1733+
Mock `
1734+
-CommandName Get-ChildItem `
1735+
-ParameterFilter $script:getChildItemSchema_parameterFilter `
1736+
-MockWith { $script:mockSchemaFiles }
1737+
1738+
Mock `
1739+
-CommandName Get-MofSchemaObject `
1740+
-ParameterFilter $script:getMofSchemaObjectSchema_parameterfilter `
1741+
-MockWith { $script:mockGetMofSchemaObject }
1742+
1743+
Mock `
1744+
-CommandName Test-Path `
1745+
-ParameterFilter $script:getTestPathReadme_parameterFilter `
1746+
-MockWith { $true }
1747+
1748+
Mock `
1749+
-CommandName Get-Content `
1750+
-ParameterFilter $script:getContentReadme_parameterFilter `
1751+
-MockWith { $script:mockGetContentReadme }
1752+
1753+
Mock `
1754+
-CommandName Get-ChildItem `
1755+
-ParameterFilter $script:getChildItemExample_parameterFilter `
1756+
-MockWith { $script:mockExampleFiles }
1757+
1758+
Mock `
1759+
-CommandName Get-DscResourceHelpExampleContent `
1760+
-ParameterFilter $script:getDscResourceHelpExampleContent_parameterFilter `
1761+
-MockWith { $script:mockExampleContent }
1762+
1763+
Mock `
1764+
-CommandName Out-File
16591765

16601766
Mock `
16611767
-CommandName Write-Warning `
@@ -1693,7 +1799,7 @@ Configuration Example
16931799
-ParameterFilter $script:getTestPathReadme_parameterFilter `
16941800
-Exactly -Times 1
16951801

1696-
Assert-MockCalled `
1802+
Assert-MockCalled `
16971803
-CommandName Get-Content `
16981804
-ParameterFilter $script:getContentReadme_parameterFilter `
16991805
-Exactly -Times 1

0 commit comments

Comments
 (0)