This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMyAlbum.Tests.ps1
101 lines (68 loc) · 3.07 KB
/
MyAlbum.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$DestiantionPath = "$env:tmp\MyAlbumTests\InstallPackage"
$SavePath = "$env:tmp\MyAlbumTests\ForSavePackage"
Describe "MyAlblum Test Cases" -Tags @('BVT', 'DRT') {
BeforeAll {
# Make sure that Pester testing tool is installed and loaded
Find-Module Pester | Install-Module Pester
Import-Module Pester
# Make sure that my provider is loaded
Import-PackageProvider myalbum
$modulePath = Get-Module -Name "MyAlbum" -ListAvailable
$LocalRepositoryPath = Join-Path $modulePath.ModuleBase -ChildPath "Test\Localrepository"
if(Test-Path -Path $LocalRepositoryPath)
{
Register-PackageSource -Name album -ProviderName myalbum -Location $LocalRepositoryPath -ErrorAction SilentlyContinue
}
else
{
throw "Path $LocalRepositoryPath does not exist"
}
}
AfterAll {
UnRegister-PackageSource -Name album -ProviderName myalbum
if( test-path $DestiantionPath ) {
rmdir -recurse -force $DestiantionPath -ea silentlycontinue
}
if( test-path $SavePath ) {
rmdir -recurse -force $SavePath -ea silentlycontinue
}
}
It "Find-Package -Source parameter, Expect succeed" {
$results = Find-Package -Source 'Album'
$results.Name -contains "Seattle.png" | should be $true
$results.Name -contains "Happy.png" | should be $true
$results.Name -contains "Nice.png" | should be $true
}
It "Find-Package -Name parameter, Expect succeed" {
$results = Find-Package -Source 'Album' -Name 'Seattle'
$results.Name -contains "Seattle.png" | should be $true
$results.Name -contains "Happy.png" | should be $false
}
It "Install-UnInstall-Package, Expect succeed" {
$a = (Install-Package -Name Nice -RequiredVersion 1.0 -Destination $DestiantionPath -source album -force).name
$a | should match "Nice"
$results = Get-Package -Destination $DestiantionPath
$results.Name -contains "Nice.png" | should be $true
UnInstall-Package -Name Nice -Destination $DestiantionPath
$results = Get-Package -Destination $DestiantionPath -ErrorAction SilentlyContinue
$results.Count -eq 0 | should be $true
}
It "Save-Package, Expect succeed" {
if(-not (Test-Path -Path $SavePath))
{
New-Item -Path $SavePath -ItemType Directory -Force
}
$a = (Save-Package -Name Nice -Source Album -Path $SavePath -force).name
$a | should match "Nice"
}
}
Describe "MyAlblum Error Cases" -Tags @('BVT', 'DRT') {
BeforeAll {
# Make sure that my provider is loaded
Import-PackageProvider myalbum
}
It "Find-Package -Source parameter, Expect succeed" {
$results = Find-Package -Source 'DONOTEXIST' -ErrorAction SilentlyContinue -ErrorVariable theError
$theError.FullyQualifiedErrorId | should be "SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage"
}
}