WindowsAid.Tests.ps1
Describe "Module WindowsAid" -Tag 'Compliance' { Context 'Basis Modul Testing' { $testCases = Get-ChildItem "$PSScriptRoot\Public\*.ps1" -File -Force | ForEach-Object -Process { return @{ Path=$_.FullName } } It "Skript '<Path>' enthält keine Fehler." -TestCases $testCases { $contents = Get-Content -Path $Path -ErrorAction Stop $errors = $null $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) $errors.Count | Should -Be 0 } It "Das Modul WindowsAid kann ohne Probleme importiert werden." { Remove-Module -Name 'WindowsAid' -Force -ErrorAction Ignore -WarningAction Ignore { Import-Module -Name "$PSScriptRoot\WindowsAid.psd1" -Force } | Should -Not -Throw } It "Das Module WindowsAid kann ohne Probleme entladen werden." { Import-Module -Name "$PSScriptRoot\WindowsAid.psd1" -Force { Remove-Module -Name 'WindowsAid' -Force } | Should -Not -Throw } } Context 'Modul-Manifest Tests' { It 'Module Manifest ist erfolgreich validiert.' { { Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" -ErrorAction Stop -WarningAction SilentlyContinue } | Should -Not -Throw } It 'Modul-Name ist WindowsAid.' { Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty Name | Should -Be 'WindowsAid' } It 'Modul-Version ist Neu' { Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty Version | Should -BeExactly '1.0' } It 'Modul-Description ist vorhanden.' { Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty Description | Should -Not -BeNullOrEmpty } It 'Module-Root steht auf WindowsAid.psm1.' { Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty RootModule | Should -Be 'WindowsAid.psm1' } It 'Ist die Modul GUID korrekt.' { Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty Guid | Should -Be 'a0937110-6265-4dff-b670-1b319edeebad' } } Context 'Exported Functions' { BeforeAll { Import-Module -Name $PSScriptRoot $Script:Manifest = Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" } AfterAll { Remove-Module -Name 'WindowsAid' -Force -ErrorAction Ignore } It "Function Public\<FunctionName>.ps1 als ExportedFunction <FunctionName> im Manifest hinterlegt." -TestCases ( Get-ChildItem -Path "$PSScriptRoot\Public\*.ps1" -Exclude '*.Tests.ps1' | Select-Object -ExpandProperty Name | Foreach-Object -Process { @{ FunctionName = $_.Replace('.ps1', '' ) } }) { $ManifestFunctions = Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty ExportedFunctions | Select-Object -ExpandProperty Keys $FunctionName -in $ManifestFunctions | Should -Be $true } It "Ist die <FunctionName> im function:\-Laufwerk enthalten?" -TestCases (Get-Command -Module 'WindowsAid' -CommandType Function | ForEach-Object -Process { @{ FunctionName = $_.Name } }) { param( $FunctionName ) Get-Item -Path "function:\$FunctionName" | Select-Object -ExpandProperty Name | Should -BeExactly $FunctionName } It "Ist die Manifest-Funktion <FunctionName> als Public\<FunctionName>.ps1 enthalten?" -TestCases ( Test-ModuleManifest -Path "$PSScriptRoot\WindowsAid.psd1" | Select-Object -ExpandProperty ExportedFunctions | Select-Object -ExpandProperty Keys | ForEach-Object -Process { @{ FunctionName = $_ } } ) { param( $FunctionName ) Test-Path -Path "$PSScriptRoot\Public\$FunctionName.ps1" | Should -BeTrue } } } |