Timezone.Tests.ps1
#Requires -Module Pester if ((Get-Module).Name -contains 'Timezone') { Remove-Module -Name Timezone } Import-Module "$PSScriptRoot\Timezone.psm1" Describe 'Get-Timezone' { Context 'UTC' { It 'Returns the current Timezone object' { $timezone = Get-Timezone $timezone.Timezone | Should Not Be $null $timezone.UTCOffset | Should Not Be $null $timezone.ExampleLocation | Should Not Be $null } } Context 'Ahead of GMT timezone' { It 'Returns a Singapore (UTC+08:00) Timezone object' { $timezone = (Get-Timezone -Timezone 'Singapore Standard Time') $timezone.Timezone | Should Be 'Singapore Standard Time' $timezone.UTCOffset | Should Be '+08:00' $timezone.ExampleLocation | Should Be '(UTC+08:00) Kuala Lumpur, Singapore' } } Context 'Behind GMT timezone' { It 'Returns a Central America (UTC-06:00) Timezone object' { $timezone = (Get-Timezone -Timezone 'Central America Standard Time') $timezone.Timezone | Should Be 'Central America Standard Time' $timezone.UTCOffset | Should Be '-06:00' $timezone.ExampleLocation | Should Be '(UTC-06:00) Central America' } } Context 'All' { It 'Checks all timezones for consistency with individual data return' { $timezone = Get-Timezone -All Get-Timezone -All | Get-Timezone | ForEach-Object { $timezone.Timezone -contains $_.Timezone | Should Be $true $timezone.UTCOffset -contains $_.UTCOffset | Should Be $true $timezone.ExampleLocation -contains $_.ExampleLocation | Should Be $true } } } Context 'Multiple' { It 'Returns multiple individual timezones' { { Get-Timezone -Timezone 'Eastern Standard Time', 'SA Pacific Standard Time' } | Should Not Throw } } Context 'PipelineInput' { It 'Returns a timezone from pipeline data by value' { 'UTC' | Get-Timezone | Should Not Be $null 'utc' | Get-Timezone | Should Not Be $null } It 'Returns a timezone from pipeline data by property name' { Get-Timezone -Timezone 'Pacific Standard Time' | Get-Timezone | Should Not Be $null } } Context 'Validation' { It 'Tries to get an invalid timezone' { { Get-Timezone -Timezone 'My First Timezone' } | Should Throw { Get-Timezone -Timezone 0 } | Should Throw { Get-Timezone -Timezone 19:00 } | Should Throw } } } Describe 'Set-Timezone-UTC' { Context 'Standard' { It 'Sets the timezone to UTC' { Set-Timezone -Timezone 'UTC' -WhatIf | Should Be $null } } Context 'PipelineInput' { It 'Sets the timezone from pipeline data' { 'Dateline Standard Time' | Set-Timezone -WhatIf | Should Be $null } It 'Returns a timezone from pipeline data by property name' { Get-Timezone -Timezone 'Hawaiian Standard Time' | Set-Timezone -WhatIf | Should Be $null } } Context 'Validation' { It 'Tries to set an invalid timezone' { { Set-Timezone -Timezone 'My First Timezone' } | Should Throw } } } Remove-Module -Name Timezone |