1+ $here = Split-Path - Parent $MyInvocation.MyCommand.Path
2+ . " $here \7Zip.ps1"
3+
4+
5+ Describe " Test-7ZipInstall" {
6+
7+ It " Try to download utill when it doesnt exit" {
8+
9+ Mock - CommandName Receive-File - MockWith {}
10+ Mock - CommandName Extract- ZipFile - MockWith {}
11+ Mock - CommandName Get-TempFileName - MockWith { return " ${pwd} /7Zip.ps1" }
12+
13+ Test-7ZipInstall
14+
15+ Assert-MockCalled Receive-File 1
16+ Assert-MockCalled Extract- ZipFile 1
17+ Assert-MockCalled Get-TempFileName 1
18+ }
19+ }
20+
21+
22+ Describe " Start-7Zip" {
23+
24+ It " Starts 7zip process" {
25+
26+ Mock - CommandName Test-7ZipInstall - MockWith {}
27+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
28+ $script :_7zPath = " ${pwd} /7Zip.ps1"
29+
30+ Start-7Zip " ${pwd} /7Zip.ps1"
31+
32+ Assert-MockCalled Start-Process 1
33+ Assert-MockCalled Test-7ZipInstall 1
34+ }
35+
36+ It " Should throw on not zero exit code" {
37+
38+ Mock - CommandName Test-7ZipInstall - MockWith {}
39+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 3 }}
40+ $script :_7zPath = " ${pwd} /7Zip.ps1"
41+
42+ $exception = $null
43+ try {
44+ Start-7Zip " ${pwd} /7Zip.ps1"
45+
46+ }
47+ catch {
48+ $exception = $_
49+ }
50+
51+
52+ $exception.Count | Should - Be 1
53+
54+ $exception | Should BeOfType System.Management.Automation.ErrorRecord
55+ $exception.Exception | Should BeOfType System.Management.Automation.RuntimeException
56+
57+
58+ Assert-MockCalled Start-Process 1
59+ Assert-MockCalled Test-7ZipInstall 1
60+ }
61+ }
62+
63+ Describe " Read-ZipFile" {
64+
65+ It " Check weither 7zip bin exist, execute 7zip worker and check file hash" {
66+
67+ Mock - CommandName Test-7ZipInstall - MockWith {}
68+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
69+ $script :_7zPath = " ${pwd} /7Zip.ps1"
70+
71+ Read-ZipFile - ArchiveName " ${pwd} /7Zip.ps1"
72+
73+ Assert-MockCalled Start-Process 1
74+ Assert-MockCalled Test-7ZipInstall 1
75+ }
76+ }
77+
78+ Describe " Add-ZipFileContent" {
79+
80+ It " Check weither 7zip bin exist, create hash and starts worker" {
81+
82+ Mock - CommandName Test-7ZipInstall - MockWith {}
83+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
84+ # Mock -CommandName Get-FileHash -MockWith { "hash"}
85+
86+ $script :_7zPath = " ${pwd} /7Zip.ps1"
87+
88+ Add-ZipFileContent - ArchiveName " ${pwd} /7Zip.ps1" - FileName " ${pwd} /7Zip.ps1"
89+
90+ Assert-MockCalled Start-Process 1
91+ # Assert-MockCalled Get-FileHash 1
92+ Assert-MockCalled Test-7ZipInstall 1
93+ }
94+ }
95+
96+ Describe " Remove-ZipFileContent" {
97+
98+ It " Check weither 7zip bin exist, starts worker and remove hash" {
99+
100+ Mock - CommandName Test-7ZipInstall - MockWith {}
101+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
102+ # Mock -CommandName Remove-Hash -MockWith { "hash"}
103+
104+ $script :_7zPath = " ${pwd} /7Zip.ps1"
105+
106+ Remove-ZipFileContent - ArchiveName " ${pwd} /7Zip.ps1" - FileName " ${pwd} /7Zip.ps1"
107+
108+ Assert-MockCalled Start-Process 1
109+ # Assert-MockCalled Remove-Hash 1
110+ Assert-MockCalled Test-7ZipInstall 1
111+ }
112+ }
113+
114+
115+ Describe " New-ZipFile" {
116+
117+ It " Check weither 7zip bin exist, create hash and starts worker" {
118+
119+ Mock - CommandName Test-7ZipInstall - MockWith {}
120+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
121+ # Mock -CommandName WriteHash -MockWith { "hash"}
122+
123+ $script :_7zPath = " ${pwd} /7Zip.ps1"
124+
125+ New-ZipFile - ArchiveName " ${pwd} /7Zip.ps1" - Filenames " ${pwd} /7Zip.ps1" , " ${pwd} /7Zip.ps1" , " ${pwd} /7Zip.ps1"
126+
127+ Assert-MockCalled Start-Process 1
128+ # Assert-MockCalled WriteHash 1
129+ Assert-MockCalled Test-7ZipInstall 1
130+ }
131+ }
132+
133+
134+ Describe " Get-ZipFileContent" {
135+
136+ It " Check weither 7zip bin exist, create hash and starts worker" {
137+
138+ Mock - CommandName Test-7ZipInstall - MockWith {}
139+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
140+ # Mock -CommandName Check-Hash -MockWith { $true}
141+
142+ $script :_7zPath = " ${pwd} /7Zip.ps1"
143+
144+ Get-ZipFileContent - ArchiveName " ${pwd} /7Zip.ps1" - FileName " ${pwd} /7Zip.ps1"
145+
146+ Assert-MockCalled Start-Process 1
147+ # Assert-MockCalled Check-Hash 1
148+ Assert-MockCalled Test-7ZipInstall 1
149+ }
150+ }
151+
152+ Describe " Test-ZipFileContent" {
153+
154+ It " Check weither 7zip bin exist, create hash and starts worker" {
155+
156+ Mock - CommandName Test-7ZipInstall - MockWith {}
157+ Mock - CommandName Start-Process - MockWith { @ {ExitCode = 0 }}
158+ # Mock -CommandName Check-Hash -MockWith { $true}
159+
160+ $script :_7zPath = " ${pwd} /7Zip.ps1"
161+
162+ Test-ZipFileContent - ArchiveName " ${pwd} /7Zip.ps1" - FileName " ${pwd} /7Zip.ps1"
163+
164+ Assert-MockCalled Start-Process 1
165+ # Assert-MockCalled Check-Hash 1
166+ Assert-MockCalled Test-7ZipInstall 1
167+ }
168+ }
0 commit comments