-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathModule.TestAliases.Tests.ps1
64 lines (51 loc) · 1.97 KB
/
Module.TestAliases.Tests.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.123
Created on: 6/27/2016 4:49 PM
Created by: June Blender
Organization: SAPIEN Technologies, Inc.
Filename:
===========================================================================
.DESCRIPTION
ModulesA description of the file.
#>
Param
(
[Parameter(Mandatory = $true)]
[ValidateScript({ Get-Module -ListAvailable -Name $_ })]
[string]$ModuleName = 'BetterCredentials',
[Parameter(Mandatory = $false)]
[System.Version]$RequiredVersion
)
#Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '3.4.0'}
if (!$RequiredVersion)
{
$RequiredVersion = (Get-Module $ModuleName -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1).Version
}
if ($ExportedAliases = (Get-Module -ListAvailable -FullyQualifiedName @{ ModuleName = $ModuleName; RequiredVersion = $RequiredVersion }).ExportedAliases.Values.Name)
{
# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $ModuleName | Remove-Module
# Import the required version
Import-Module $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop
foreach ($ExportedAlias in $ExportedAliases)
{
Describe "Testing exported aliases" {
$script:AliasInSession = $null
It "Get-Alias should not error out: $ExportedAlias" {
{ $script:AliasInSession = Get-Alias $ExportedAlias -ErrorAction Stop } | Should Not Throw
}
It "Get-Alias should find alias in session: $ExportedAlias" {
$script:AliasInSession.Name | Should Be $ExportedAlias
}
It "Get-Alias should find value: $ExportedAlias" {
$script:AliasInSession.ResolvedCommandName -or $script:AliasInSession.Definition | Should Be $True
}
}
}
}
else
{
Write-Host "Module.TestAliases.Tests.ps1: $ModuleName ($RequiredVersion) does not export any aliases."
}