From 11afac883fd90ccbe1315ae41d8b4916a56f43bd Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Wed, 6 Apr 2016 01:14:14 -0700 Subject: [PATCH 1/4] Add Unit Test for GetDateTest.cs --- test/powershell/Get-Date.Tests.ps1 | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/test/powershell/Get-Date.Tests.ps1 b/test/powershell/Get-Date.Tests.ps1 index 16f3a98a3ff..584cd129d86 100644 --- a/test/powershell/Get-Date.Tests.ps1 +++ b/test/powershell/Get-Date.Tests.ps1 @@ -1,3 +1,86 @@ +Describe "Get-Date DRT Unit Tests" -Tags DRT { + It "Get-Date with all parameters returns proper results" { + $date = [datetime]::Now + ([timespan]::new(0,0,30)) + $result = Get-Date -Date $date -Year 1973 -Month 2 -Day 22 -Hour 15 -Minute 40 -Second 10 -Millisecond 200 + $result.GetType() | Should be ([Datetime]) + $result.Year | Should be 1973 + $result.Month| Should be 2 + $result.Day | Should be 22 + $result.Hour | Should be 15 + $result.Minute | Should be 40 + $result.Second | Should be 10 + $result.Millisecond | Should be 200 + } + + It "using -displayhint produces the correct output" { + Get-date -Date:"Jan 1, 2020" -DisplayHint:$([Microsoft.PowerShell.Commands.DisplayHintType]::Date) | Out-String | Should be "`nWednesday, January 1, 2020`n`n`n" + } + + It "using -format produces the correct output" { + Get-date -Date:"Jan 1, 2020" -Format:"MMM-dd-yy" | Should be "Jan-01-20" + } + + It "using -uformat produces the correct output" { + Get-date -Date:"Jan 1, 2020" -UFormat:"%s" | Should be "1577836800" + } + + It "using -uformat 'ymdH' produces the correct output" { + Get-date -Date 0030-01-01T00:00:00 -uformat %y/%m/%d-%H | Should be "30/01/01-00" + } + + It "using -uformat 'aAbBcCdDehHIjmMpr' produces the correct output" { + Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM" + } + + It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { + #ToDo + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%Z%% | Should be "0000:00:002012001/01/3000:00:00300030-07%" + } + + It "Get-date works with pipeline input" { + $x = new-object System.Management.Automation.PSObject + $x | add-member NoteProperty Date ([DateTime]::Now) + $y = @($x,$x) + ($y | Get-date).Length | Should be 2 + } + + It "the LastWriteTime alias works with pipeline input" { + $folder = "GetDateTest" + $tempPath = $PSScriptRoot + $pathString = Join-Path -Path $tempPath -ChildPath $folder + New-Item -Path $tempPath -Name $folder -ItemType directory -Force + for($i = 0; $i -lt 10; $i++) + { + $temp = [guid]::NewGuid() + $pathString2 = Join-Path -Path $pathString -ChildPath $temp + New-Item -Path $pathString -Name $temp -ItemType file -Force + + for($j = 0; $j -lt 100; $j++) + { + Add-Content -Path $pathString2 -Value $j + } + + } + + $result1 = get-childitem -path $pathString | get-date + $result2 = get-childitem -path $pathString | get-date + + $result1.Length | Should be 10 + $result1.Length -eq $result2.Length | Should be $true + + for($i = 0; $i -lt $result1.Length; $i++) + { + $result1[$i] -eq $result2[$i] | Should be $true + } + + Get-ChildItem -Path $pathString | Remove-Item + Remove-Item -Path $pathString -Force -Recurse + } + + +} + + Describe "Get-Date" { It "Should return a DateTime object upon being called" { (Get-Date).GetType().Name.Equals('DateTime') | Should Be $true From 4a4994ba2d0b026171c18cf03ee596ebcd935132 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Wed, 6 Apr 2016 01:17:27 -0700 Subject: [PATCH 2/4] Add Unit Test for StartSleepTest.cs --- test/powershell/Start-Sleep.Tests.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/powershell/Start-Sleep.Tests.ps1 b/test/powershell/Start-Sleep.Tests.ps1 index b5136932abd..4699bb53693 100644 --- a/test/powershell/Start-Sleep.Tests.ps1 +++ b/test/powershell/Start-Sleep.Tests.ps1 @@ -1,3 +1,22 @@ +Describe "Start-Sleep DRT Unit Tests" -Tags DRT{ + It "Shoule be works properly when sleeping with Second" { + $dtStart = [DateTime]::Now + Start-Sleep -Seconds 1 + $dtEnd = [DateTime]::Now + $millseconds = (New-TimeSpan -Start $dtStart -End $dtEnd).TotalMilliseconds + $millseconds | Should BeGreaterThan 1000 + } + + It "Shoule be works properly when sleeping with Second" { + $dtStart = [DateTime]::Now + Start-Sleep -Milliseconds 1000 + $dtEnd = [DateTime]::Now + $millseconds = (New-TimeSpan -Start $dtStart -End $dtEnd).TotalMilliseconds + $millseconds | Should BeGreaterThan 1000 + } + +} + Describe "Start-Sleep" { Context "Validate Start-Sleep works properly" { From 63f8782d05ae0ca8f4cdeaf90d933f67a3b70c7c Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 7 Apr 2016 00:15:50 -0700 Subject: [PATCH 3/4] Improve Unit Test for Get-Date --- test/powershell/Get-Date.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/powershell/Get-Date.Tests.ps1 b/test/powershell/Get-Date.Tests.ps1 index 584cd129d86..0f481bdae16 100644 --- a/test/powershell/Get-Date.Tests.ps1 +++ b/test/powershell/Get-Date.Tests.ps1 @@ -13,7 +13,8 @@ Describe "Get-Date DRT Unit Tests" -Tags DRT { } It "using -displayhint produces the correct output" { - Get-date -Date:"Jan 1, 2020" -DisplayHint:$([Microsoft.PowerShell.Commands.DisplayHintType]::Date) | Out-String | Should be "`nWednesday, January 1, 2020`n`n`n" + $newLine = [Environment]::NewLine + Get-date -Date:"Jan 1, 2020" -DisplayHint:$([Microsoft.PowerShell.Commands.DisplayHintType]::Date) | Out-String | Should be $newLine"Wednesday, January 1, 2020$newLine$newLine$newLine" } It "using -format produces the correct output" { @@ -32,9 +33,8 @@ Describe "Get-Date DRT Unit Tests" -Tags DRT { Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM" } - It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { - #ToDo - Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%Z%% | Should be "0000:00:002012001/01/3000:00:00300030-07%" + It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" { + Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%" } It "Get-date works with pipeline input" { From 757724abf5b92df276a5032dfabc08d3c5611ab8 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 7 Apr 2016 20:27:04 -0700 Subject: [PATCH 4/4] fix the issue of review --- test/powershell/Get-Date.Tests.ps1 | 10 +++++----- test/powershell/Start-Sleep.Tests.ps1 | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/powershell/Get-Date.Tests.ps1 b/test/powershell/Get-Date.Tests.ps1 index 0f481bdae16..7b643de09a6 100644 --- a/test/powershell/Get-Date.Tests.ps1 +++ b/test/powershell/Get-Date.Tests.ps1 @@ -13,8 +13,8 @@ Describe "Get-Date DRT Unit Tests" -Tags DRT { } It "using -displayhint produces the correct output" { - $newLine = [Environment]::NewLine - Get-date -Date:"Jan 1, 2020" -DisplayHint:$([Microsoft.PowerShell.Commands.DisplayHintType]::Date) | Out-String | Should be $newLine"Wednesday, January 1, 2020$newLine$newLine$newLine" + $d = Get-date -Date:"Jan 1, 2020" -DisplayHint Date | Out-String + $d.Trim() | Should be "Wednesday, January 1, 2020" } It "using -format produces the correct output" { @@ -46,9 +46,9 @@ Describe "Get-Date DRT Unit Tests" -Tags DRT { It "the LastWriteTime alias works with pipeline input" { $folder = "GetDateTest" - $tempPath = $PSScriptRoot - $pathString = Join-Path -Path $tempPath -ChildPath $folder - New-Item -Path $tempPath -Name $folder -ItemType directory -Force + #$tempPath = $TestDrive + $pathString = Join-Path -Path $TestDrive -ChildPath $folder + New-Item -Path $TestDrive -Name $folder -ItemType directory -Force for($i = 0; $i -lt 10; $i++) { $temp = [guid]::NewGuid() diff --git a/test/powershell/Start-Sleep.Tests.ps1 b/test/powershell/Start-Sleep.Tests.ps1 index 4699bb53693..e97cfad808e 100644 --- a/test/powershell/Start-Sleep.Tests.ps1 +++ b/test/powershell/Start-Sleep.Tests.ps1 @@ -1,5 +1,5 @@ Describe "Start-Sleep DRT Unit Tests" -Tags DRT{ - It "Shoule be works properly when sleeping with Second" { + It "Should be works properly when sleeping with Second" { $dtStart = [DateTime]::Now Start-Sleep -Seconds 1 $dtEnd = [DateTime]::Now @@ -7,7 +7,7 @@ Describe "Start-Sleep DRT Unit Tests" -Tags DRT{ $millseconds | Should BeGreaterThan 1000 } - It "Shoule be works properly when sleeping with Second" { + It "Should be works properly when sleeping with Milliseconds" { $dtStart = [DateTime]::Now Start-Sleep -Milliseconds 1000 $dtEnd = [DateTime]::Now