Tests/PesterHelper.class.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
Class PesterHelper { [String]$WordirLocation [String]$ModuleManifest [String]$ModuleName [String]$TmpLocation PesterHelper() { $this.WordirLocation = Get-Location $this.ModuleManifest = $this.GetModuleInfo().FullName $this.ModuleName = $this.GetModuleInfo().BaseName $this.TmpLocation = $this.CreateTmpFolder() } [Object] GetModuleInfo(){ $ModulePath = (get-item -Path $PSScriptRoot).parent.FullName return Get-ChildItem -Path "$ModulePath\*.psd1" } [String] CreateTmpFolder(){ $Parent = [System.IO.Path]::GetTempPath() $Name = [System.IO.Path]::GetRandomFileName() $TmpFolder = Join-Path -Path $Parent -ChildPath $Name New-Item -ItemType Directory -Path $TmpFolder return $TmpFolder } [Void] RemoveTmpFolder(){ Remove-Item -Path $this.TmpLocation -Force -Recurse -Confirm:$false } [Void] LoadModule() { Set-Location $this.TmpLocation Microsoft.PowerShell.Core\Import-Module $this.ModuleManifest -Global } [Void] UnloadModule() { Set-Location $this.WordirLocation $this.RemoveTmpFolder Microsoft.PowerShell.Core\Remove-Module $this.ModuleName } } |