-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMock.ps1
48 lines (41 loc) · 933 Bytes
/
TestMock.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
function Get-RandomNumber
{
return Get-Random -Maximum 10 -Minimum 1
}
function Get-RandomNumberPlus1
{
return (Get-RandomNumber) + 1
}
Describe "How to mock a function" {
Mock Get-RandomNumber { } # doesnt return anything
it "should return 1" {
Get-RandomNumberPlus1 | Should -be 1
}
}
function Test-LocalFile
{
param (
[string]
$filepath
)
try
{
$FileInfo = Get-Item -Path $filepath -ErrorAction SilentlyContinue
if ( $FileInfo.GetType().Name -eq "FileInfo")
{
return $true
}
}
catch
{
Write-Error -Message " Exception Type: $($_.Exception.GetType().FullName) $($_.Exception.Message)"
}
}
Describe "How to mock a function" {
Mock Get-Item {
New-MockObject -Type "System.IO.Directory"
}
it "return txt" {
Test-LocalFile -filepath hans.vla | Should -BeTrue
}
}