From fdd7e2b52c92fd70011f1cc7bc31736d811152a1 Mon Sep 17 00:00:00 2001 From: stknohg Date: Wed, 24 Jan 2018 16:49:56 +0900 Subject: [PATCH 1/3] Change Microsoft.PowerShell.Commands.SetDateCommand.SystemTime to struct. --- .../commands/utility/SetDateCommand.cs | 2 +- .../Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs index 11e6b12d4ed..1f7e91e8230 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs @@ -117,7 +117,7 @@ protected override void ProcessRecord() internal static class NativeMethods { [StructLayout(LayoutKind.Sequential)] - public class SystemTime + public struct SystemTime { public UInt16 Year; public UInt16 Month; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index c313ac4965d..6a599377d76 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -10,6 +10,12 @@ Describe "Set-Date" -Tag "CI" { { get-date | set-date } | Should not throw } + It "Set-Date should be able to set the date with -Date parameter" -Skip:(! $IsElevated) { + $target = Get-Date + $expected = $target + Set-Date -Date $target | Should be $expected + } + It "Set-Date should produce an error in a non-elevated context" -Skip:($IsElevated) { { get-date | set-date} | should throw $Error[0].FullyQualifiedErrorId | should be "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" From 7ea25512b9b14227ecf6b226c16a866b21bfd405 Mon Sep 17 00:00:00 2001 From: stknohg Date: Wed, 24 Jan 2018 19:08:36 +0900 Subject: [PATCH 2/3] fix casing of cmdlet, pester operators. --- .../Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index 6a599377d76..48504953fb6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -7,17 +7,17 @@ Describe "Set-Date" -Tag "CI" { } It "Set-Date should be able to set the date in an elevated context" -Skip:(! $IsElevated) { - { get-date | set-date } | Should not throw + { Get-Date | Set-Date } | Should Not Throw } It "Set-Date should be able to set the date with -Date parameter" -Skip:(! $IsElevated) { $target = Get-Date $expected = $target - Set-Date -Date $target | Should be $expected + Set-Date -Date $target | Should Be $expected } It "Set-Date should produce an error in a non-elevated context" -Skip:($IsElevated) { - { get-date | set-date} | should throw - $Error[0].FullyQualifiedErrorId | should be "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" + { Get-Date | Set-Date } | Should Throw + $Error[0].FullyQualifiedErrorId | Should Be "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" } } From b77658552cb5d15c792d1b0fdc0cde5d27e7a3c3 Mon Sep 17 00:00:00 2001 From: stknohg Date: Wed, 24 Jan 2018 22:55:43 +0900 Subject: [PATCH 3/3] Use ShouldBeErrorId helper to check error. --- .../Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 index 48504953fb6..8a7f664e854 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 @@ -17,7 +17,6 @@ Describe "Set-Date" -Tag "CI" { } It "Set-Date should produce an error in a non-elevated context" -Skip:($IsElevated) { - { Get-Date | Set-Date } | Should Throw - $Error[0].FullyQualifiedErrorId | Should Be "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" + { Get-Date | Set-Date } | ShouldBeErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand" } }