forked from pspete/psPAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertTo-UnixTime.Tests.ps1
More file actions
105 lines (69 loc) · 3.11 KB
/
ConvertTo-UnixTime.Tests.ps1
File metadata and controls
105 lines (69 loc) · 3.11 KB
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
102
103
104
105
Describe $($PSCommandPath -Replace '.Tests.ps1') {
BeforeAll {
#Get Current Directory
$Here = Split-Path -Parent $PSCommandPath
#Assume ModuleName from Repository Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf
#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"
#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"
if ( -not (Get-Module -Name $ModuleName -All)) {
Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop
}
$Script:RequestBody = $null
$psPASSession = [ordered]@{
BaseURI = 'https://SomeURL/SomeApp'
User = $null
ExternalVersion = [System.Version]'0.0'
WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
StartTime = $null
ElapsedTime = $null
LastCommand = $null
LastCommandTime = $null
LastCommandResults = $null
}
New-Variable -Name psPASSession -Value $psPASSession -Scope Script -Force
}
AfterAll {
$Script:RequestBody = $null
}
InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) {
Context 'Mandatory Parameters' {
$Parameters = @{Parameter = 'Date' }
It 'specifies parameter <Parameter> as mandatory' -TestCases $Parameters {
param($Parameter)
(Get-Command ConvertTo-UnixTime).Parameters["$Parameter"].Attributes.Mandatory | Should -Be $true
}
}
Context 'General' {
It 'Converts date from pipeline' {
$(Get-Date -Year 2020 -Month 01 -Day 01 -Hour 0 -Minute 0 -Second 0 -Millisecond 0) | ConvertTo-UnixTime | Should -Be 1577836800
}
It 'Converts date' {
$date = $(Get-Date -Year 2020 -Month 01 -Day 01 -Hour 0 -Minute 0 -Second 0 -Millisecond 0)
ConvertTo-UnixTime -Date $date | Should -Be 1577836800
}
It 'converts date to expected unixtime' {
ConvertTo-UnixTime -Date $(Get-Date 1/1/2020) | Should -Be 1577836800
}
It 'converts date to expected unixtime in milliseconds' {
ConvertTo-UnixTime -Date $(Get-Date 1/1/2020) -Milliseconds | Should -Be 1577836800000
}
It 'converts date to expected unixtime in milliseconds, even when locale is not en-US' {
$currentCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
[System.Threading.Thread]::CurrentThread.CurrentCulture = 'nl-NL'
ConvertTo-UnixTime -Date $(Get-Date 1/1/2020) -Milliseconds | Should -Be 1577836800000
[System.Threading.Thread]::CurrentThread.CurrentCulture = $currentCulture
}
It 'converts date to expected unixtime in milliseconds, even when locale is "SomeLocale"' {
$currentCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $(Get-Culture -ListAvailable |
Select-Object -Index (Get-Random -Maximum $((Get-Culture -ListAvailable).Count)) |
Select-Object -ExpandProperty Name)
ConvertTo-UnixTime -Date $(Get-Date 1/1/2020) -Milliseconds | Should -Be 1577836800000
[System.Threading.Thread]::CurrentThread.CurrentCulture = $currentCulture
}
}
}
}