Tests/PesterHelper.class.ps1
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 } } |