From 8a4d5cbabf6b3f91a1fd19d954f707a90b623add Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 24 Oct 2017 10:37:51 +0200 Subject: [PATCH 01/12] Remove regions in HistoryInfo class --- .../engine/hostifaces/History.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 785c34a89e3..96f53e2f610 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -19,8 +19,6 @@ namespace Microsoft.PowerShell.Commands /// public class HistoryInfo { - #region constuctor - /// /// Constructor /// @@ -56,9 +54,6 @@ private HistoryInfo(HistoryInfo history) _cleared = history._cleared; } - #endregion constructor - - #region public /// /// Id of this history entry. /// @@ -135,10 +130,6 @@ public override string ToString() } } - #endregion public - - #region internal - /// /// Cleared status of an entry /// @@ -191,10 +182,6 @@ internal void SetCommand(string command) _cmdline = command; } - #endregion internal - - #region private - /// /// Id of the pipeline corresponding to this history entry /// @@ -231,10 +218,6 @@ internal void SetCommand(string command) private bool _cleared = false; - #endregion private - - #region ICloneable Members - /// /// Returns a clone of this object /// @@ -243,8 +226,6 @@ public HistoryInfo Clone() { return new HistoryInfo(this); } - - #endregion } /// From 3afd37431c4d018779df2b82c6e30bd9d203f1f9 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 24 Oct 2017 10:39:22 +0200 Subject: [PATCH 02/12] Auto properties refactoring in HistoryInfo --- .../engine/hostifaces/History.cs | 116 ++++-------------- 1 file changed, 23 insertions(+), 93 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 96f53e2f610..513317dc362 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -32,11 +32,11 @@ internal HistoryInfo(long pipelineId, string cmdline, PipelineState status, Date { Dbg.Assert(cmdline != null, "caller should validate the parameter"); _pipelineId = pipelineId; - _cmdline = cmdline; - _status = status; - _startTime = startTime; - _endTime = endTime; - _cleared = false; + CommandLine = cmdline; + ExecutionStatus = status; + StartExecutionTime = startTime; + EndExecutionTime = endTime; + Cleared = false; } /// @@ -45,74 +45,44 @@ internal HistoryInfo(long pipelineId, string cmdline, PipelineState status, Date /// private HistoryInfo(HistoryInfo history) { - _id = history._id; + Id = history.Id; _pipelineId = history._pipelineId; - _cmdline = history._cmdline; - _status = history._status; - _startTime = history._startTime; - _endTime = history._endTime; - _cleared = history._cleared; + CommandLine = history.CommandLine; + ExecutionStatus = history.ExecutionStatus; + StartExecutionTime = history.StartExecutionTime; + EndExecutionTime = history.EndExecutionTime; + Cleared = history.Cleared; } /// /// Id of this history entry. /// /// - public long Id - { - get - { - return _id; - } - } + public long Id { get; private set; } /// /// CommandLine string /// /// - public string CommandLine - { - get - { - return _cmdline; - } - } + public string CommandLine { get; private set; } /// /// Execution status of associated pipeline /// /// - public PipelineState ExecutionStatus - { - get - { - return _status; - } - } + public PipelineState ExecutionStatus { get; private set; } /// /// Start time of execution of associated pipeline /// /// - public DateTime StartExecutionTime - { - get - { - return _startTime; - } - } + public DateTime StartExecutionTime { get; } /// /// End time of execution of associated pipeline /// /// - public DateTime EndExecutionTime - { - get - { - return _endTime; - } - } + public DateTime EndExecutionTime { get; private set; } /// /// Override for ToString() method @@ -120,13 +90,13 @@ public DateTime EndExecutionTime /// public override string ToString() { - if (string.IsNullOrEmpty(_cmdline)) + if (string.IsNullOrEmpty(CommandLine)) { return base.ToString(); } else { - return _cmdline; + return CommandLine; } } @@ -134,17 +104,7 @@ public override string ToString() /// Cleared status of an entry /// - internal bool Cleared - { - get - { - return _cleared; - } - set - { - _cleared = value; - } - } + internal bool Cleared { get; set; } = false; /// /// Sets Id @@ -152,7 +112,7 @@ internal bool Cleared /// internal void SetId(long id) { - _id = id; + Id = id; } /// @@ -161,7 +121,7 @@ internal void SetId(long id) /// internal void SetStatus(PipelineState status) { - _status = status; + ExecutionStatus = status; } /// @@ -170,7 +130,7 @@ internal void SetStatus(PipelineState status) /// internal void SetEndTime(DateTime endTime) { - _endTime = endTime; + EndExecutionTime = endTime; } /// @@ -179,7 +139,7 @@ internal void SetEndTime(DateTime endTime) /// internal void SetCommand(string command) { - _cmdline = command; + CommandLine = command; } /// @@ -187,36 +147,6 @@ internal void SetCommand(string command) /// private long _pipelineId; - /// - /// Id of the history entry - /// - private long _id; - - /// - /// CommandLine string - /// - private string _cmdline; - - /// - /// ExecutionStatus of execution - /// - private PipelineState _status; - - /// - /// Start time of execution - /// - private DateTime _startTime; - - /// - ///End time of execution - /// - private DateTime _endTime; - - /// - /// Flag indicating an entry is present/cleared - /// - - private bool _cleared = false; /// /// Returns a clone of this object From 1a2b81ed62cc6ec1be4afbfa8e49abcdb385dea3 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 24 Oct 2017 10:41:57 +0200 Subject: [PATCH 03/12] Adding ExecutionTime property to HistoryInfo --- .../engine/hostifaces/History.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 513317dc362..e09f2577e8d 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -84,6 +84,11 @@ private HistoryInfo(HistoryInfo history) /// public DateTime EndExecutionTime { get; private set; } + /// + /// The time it took to execute the associeated pipeline + /// + public TimeSpan ExecutionTime => EndExecutionTime - StartExecutionTime; + /// /// Override for ToString() method /// From 82e8b7f148590e5dd0451b4d037a228ffa72af44 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 24 Oct 2017 11:15:21 +0200 Subject: [PATCH 04/12] Adding formatting table view "time" for historyInfo This adds the property ExecutionTime to the table view --- .../PowerShellCore_format_ps1xml.cs | 12 ++++++++++++ .../engine/hostifaces/History.cs | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 682acddb14d..282df539bbe 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -340,6 +340,18 @@ private static IEnumerable ViewsOf_Microsoft_PowerShell_Co .EndRowDefinition() .EndTable()); + yield return new FormatViewDefinition("time", + TableControl.Create() + .AddHeader(Alignment.Right, width: 4) + .AddHeader(Alignment.Right, width: 13, label: "ExecutionTime") + .AddHeader() + .StartRowDefinition() + .AddPropertyColumn("Id") + .AddScriptBlockColumn("$_.GetExecutionTimeString()") + .AddPropertyColumn("CommandLine") + .EndRowDefinition() + .EndTable()); + yield return new FormatViewDefinition("history", WideControl.Create() .AddPropertyEntry("CommandLine") diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index e09f2577e8d..8bdc59e2594 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -152,6 +152,23 @@ internal void SetCommand(string command) /// private long _pipelineId; + /// + /// Gets a string representation of the execution time + /// + /// + public string GetExecutionTimeString() + { + var executionTime = ExecutionTime; + if (executionTime.Days > 0) + { + return $@"{executionTime:d\.hh\:mm\:ss}"; + } + if (executionTime.Hours > 1) + { + return $@"{executionTime:hh\:mm\:ss}"; + } + return $@"{executionTime:mm\:ss\.fff}"; + } /// /// Returns a clone of this object From c89be3a78b253448442eed946fc8933ad455d7fd Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 24 Oct 2017 14:53:17 +0200 Subject: [PATCH 05/12] Rename ExecutionTime => Duration --- .../PowerShellCore_format_ps1xml.cs | 2 +- .../engine/hostifaces/History.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 282df539bbe..111f12c9560 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -343,7 +343,7 @@ private static IEnumerable ViewsOf_Microsoft_PowerShell_Co yield return new FormatViewDefinition("time", TableControl.Create() .AddHeader(Alignment.Right, width: 4) - .AddHeader(Alignment.Right, width: 13, label: "ExecutionTime") + .AddHeader(Alignment.Right, width: 13, label: "Duration") .AddHeader() .StartRowDefinition() .AddPropertyColumn("Id") diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 8bdc59e2594..6c35d89fc32 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -87,7 +87,7 @@ private HistoryInfo(HistoryInfo history) /// /// The time it took to execute the associeated pipeline /// - public TimeSpan ExecutionTime => EndExecutionTime - StartExecutionTime; + public TimeSpan Duration => EndExecutionTime - StartExecutionTime; /// /// Override for ToString() method @@ -158,16 +158,16 @@ internal void SetCommand(string command) /// public string GetExecutionTimeString() { - var executionTime = ExecutionTime; - if (executionTime.Days > 0) + var duration = Duration; + if (duration.Days > 0) { - return $@"{executionTime:d\.hh\:mm\:ss}"; + return $@"{duration:d\.hh\:mm\:ss}"; } - if (executionTime.Hours > 1) + if (duration.Hours > 1) { - return $@"{executionTime:hh\:mm\:ss}"; + return $@"{duration:hh\:mm\:ss}"; } - return $@"{executionTime:mm\:ss\.fff}"; + return $@"{duration:mm\:ss\.fff}"; } /// From bea8bd5a75b3d477a59e99fdbb5cb40e14078fd5 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Fri, 27 Oct 2017 20:19:57 +0200 Subject: [PATCH 06/12] Adding test for time table view --- .../Modules/Microsoft.PowerShell.Core/History.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 index 199c6f11a2d..0b4151300a9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 @@ -110,4 +110,10 @@ Describe "History cmdlet test cases" -Tags "CI" { $errorResult | Should -BeExactly 'CommandNotFoundException' } + + It "Has time view in table format" { + $null = Get-ChildItem + Get-History | Format-Table -View time -ErrorVariable ftError | Out-Null + $ftError.Count | Should Be 0 + } } From 34cc89a3c4c7eb01f9b787a01c31ac9b42382552 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Wed, 8 Nov 2017 19:53:52 +0100 Subject: [PATCH 07/12] Adding tests Renaming GetExecutionTimeString() -> GetDurationString() --- .../PowerShellCore_format_ps1xml.cs | 4 ++-- .../engine/hostifaces/History.cs | 17 ----------------- .../Microsoft.PowerShell.Core/History.Tests.ps1 | 9 +++++++++ 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 111f12c9560..99dd3822279 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -343,11 +343,11 @@ private static IEnumerable ViewsOf_Microsoft_PowerShell_Co yield return new FormatViewDefinition("time", TableControl.Create() .AddHeader(Alignment.Right, width: 4) - .AddHeader(Alignment.Right, width: 13, label: "Duration") + .AddHeader(Alignment.Right, width: 13) .AddHeader() .StartRowDefinition() .AddPropertyColumn("Id") - .AddScriptBlockColumn("$_.GetExecutionTimeString()") + .AddPropertyColumn("Duration") .AddPropertyColumn("CommandLine") .EndRowDefinition() .EndTable()); diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 6c35d89fc32..1e3fb899aa6 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -152,23 +152,6 @@ internal void SetCommand(string command) /// private long _pipelineId; - /// - /// Gets a string representation of the execution time - /// - /// - public string GetExecutionTimeString() - { - var duration = Duration; - if (duration.Days > 0) - { - return $@"{duration:d\.hh\:mm\:ss}"; - } - if (duration.Hours > 1) - { - return $@"{duration:hh\:mm\:ss}"; - } - return $@"{duration:mm\:ss\.fff}"; - } /// /// Returns a clone of this object diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 index 0b4151300a9..8de0bda5e5c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 @@ -116,4 +116,13 @@ Describe "History cmdlet test cases" -Tags "CI" { Get-History | Format-Table -View time -ErrorVariable ftError | Out-Null $ftError.Count | Should Be 0 } + + It "HistoryInfo calculates Duration" { + $ctor = [Microsoft.PowerShell.Commands.HistoryInfo].GetConstructors([Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance).Where{$_.GetParameters().Length -eq 5} + $start = [datetime]::new(2001, 01, 01, 10, 01, 01) + $duration = [timespan] "1:2:21" + $end = $start + $duration + $hi = $ctor.Invoke((1, "command", [Management.Automation.Runspaces.PipelineState]::Completed, $start, $end)) + $hi.Duration | Should Be $duration + } } From 3a42a4bdaef5305a0a730acd9315b1604cf35c8e Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Wed, 21 Feb 2018 22:07:05 +0100 Subject: [PATCH 08/12] Single line methods to expression bodys --- .../engine/hostifaces/History.cs | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/History.cs b/src/System.Management.Automation/engine/hostifaces/History.cs index 1e3fb899aa6..7ab120d3065 100644 --- a/src/System.Management.Automation/engine/hostifaces/History.cs +++ b/src/System.Management.Automation/engine/hostifaces/History.cs @@ -115,37 +115,25 @@ public override string ToString() /// Sets Id /// /// - internal void SetId(long id) - { - Id = id; - } + internal void SetId(long id) => Id = id; /// /// Set status /// /// - internal void SetStatus(PipelineState status) - { - ExecutionStatus = status; - } + internal void SetStatus(PipelineState status) => ExecutionStatus = status; /// /// Set endtime /// /// - internal void SetEndTime(DateTime endTime) - { - EndExecutionTime = endTime; - } + internal void SetEndTime(DateTime endTime) => EndExecutionTime = endTime; /// /// Sets command /// /// - internal void SetCommand(string command) - { - CommandLine = command; - } + internal void SetCommand(string command) => CommandLine = command; /// /// Id of the pipeline corresponding to this history entry From 84f69499238a511aca0a0286e9cf7609420bcf7f Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Mon, 18 Jun 2018 23:01:07 +0200 Subject: [PATCH 09/12] Removing time view --- .../PowerShellCore_format_ps1xml.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 99dd3822279..682acddb14d 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -340,18 +340,6 @@ private static IEnumerable ViewsOf_Microsoft_PowerShell_Co .EndRowDefinition() .EndTable()); - yield return new FormatViewDefinition("time", - TableControl.Create() - .AddHeader(Alignment.Right, width: 4) - .AddHeader(Alignment.Right, width: 13) - .AddHeader() - .StartRowDefinition() - .AddPropertyColumn("Id") - .AddPropertyColumn("Duration") - .AddPropertyColumn("CommandLine") - .EndRowDefinition() - .EndTable()); - yield return new FormatViewDefinition("history", WideControl.Create() .AddPropertyEntry("CommandLine") From 10c882d87f5f64ee442517bf34bb38e03afddc61 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 19 Jun 2018 22:23:47 +0200 Subject: [PATCH 10/12] Removing obsolete test --- .../History.Tests.ps1 | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 index 8de0bda5e5c..27e2ec4fe5c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 @@ -8,11 +8,11 @@ Describe "History cmdlet test cases" -Tags "CI" { $ps = [PowerShell]::Create("NewRunspace") # we need to be sure that history is added, so use the proper # Invoke variant - $null = $ps.addcommand("Get-Date").Invoke($null,$setting) + $null = $ps.addcommand("Get-Date").Invoke($null, $setting) $ps.commands.clear() - $null = $ps.addscript("1+1").Invoke($null,$setting) + $null = $ps.addscript("1+1").Invoke($null, $setting) $ps.commands.clear() - $null = $ps.addcommand("Get-Location").Invoke($null,$setting) + $null = $ps.addcommand("Get-Location").Invoke($null, $setting) $ps.commands.clear() } AfterEach { @@ -38,18 +38,18 @@ Describe "History cmdlet test cases" -Tags "CI" { } It "Add-History actually adds to history" { # add this invocation to history - $ps.AddScript("Get-History|Add-History").Invoke($null,$setting) + $ps.AddScript("Get-History|Add-History").Invoke($null, $setting) # that's 4 history lines * 2 $ps.Commands.Clear() $result = $ps.AddCommand("Get-History").Invoke() $result.Count | Should -Be 8 - for($i = 0; $i -lt 4; $i++) { - $result[$i+4].CommandLine | Should -BeExactly $result[$i].CommandLine + for ($i = 0; $i -lt 4; $i++) { + $result[$i + 4].CommandLine | Should -BeExactly $result[$i].CommandLine } } } - It "Tests Invoke-History on a cmdlet that generates output on all streams" { + It "Tests Invoke-History on a cmdlet that generates output on all streams" { $streamSpammer = ' function StreamSpammer { @@ -93,7 +93,7 @@ Describe "History cmdlet test cases" -Tags "CI" { $outputCount | Should -Be 12 } - It "Tests Invoke-History on a private command" { + It "Tests Invoke-History on a private command" { $invocationSettings = New-Object System.Management.Automation.PSInvocationSettings $invocationSettings.AddToHistory = $true @@ -111,12 +111,6 @@ Describe "History cmdlet test cases" -Tags "CI" { $errorResult | Should -BeExactly 'CommandNotFoundException' } - It "Has time view in table format" { - $null = Get-ChildItem - Get-History | Format-Table -View time -ErrorVariable ftError | Out-Null - $ftError.Count | Should Be 0 - } - It "HistoryInfo calculates Duration" { $ctor = [Microsoft.PowerShell.Commands.HistoryInfo].GetConstructors([Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance).Where{$_.GetParameters().Length -eq 5} $start = [datetime]::new(2001, 01, 01, 10, 01, 01) From 666a425a77ccb524e9baf52931e5d68a48b96bb6 Mon Sep 17 00:00:00 2001 From: "Gustafsson, Staffan" Date: Tue, 31 Jul 2018 13:29:37 +0200 Subject: [PATCH 11/12] Using Add-History to test Duration property --- .../Microsoft.PowerShell.Core/History.Tests.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 index 27e2ec4fe5c..7f1e6c63d49 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 @@ -112,11 +112,17 @@ Describe "History cmdlet test cases" -Tags "CI" { } It "HistoryInfo calculates Duration" { - $ctor = [Microsoft.PowerShell.Commands.HistoryInfo].GetConstructors([Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance).Where{$_.GetParameters().Length -eq 5} $start = [datetime]::new(2001, 01, 01, 10, 01, 01) $duration = [timespan] "1:2:21" $end = $start + $duration - $hi = $ctor.Invoke((1, "command", [Management.Automation.Runspaces.PipelineState]::Completed, $start, $end)) - $hi.Duration | Should Be $duration + $history = [PSCustomObject] @{ + CommandLine="command" + ExecutionStatus=[Management.Automation.Runspaces.PipelineState]::Completed + StartExecutionTime=$start + EndExecutionTime=$end + } + $history | Add-History + $h = Get-History -count 1 + $h.Duration | Should Be $duration } } From 5e5af803e5a0728595fc1fce2a22d727d975c70b Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Mon, 27 Aug 2018 21:46:21 +0200 Subject: [PATCH 12/12] Be -> -Be --- .../Microsoft.PowerShell.Core/History.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 index 7f1e6c63d49..4e2f1004bd1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1 @@ -116,13 +116,13 @@ Describe "History cmdlet test cases" -Tags "CI" { $duration = [timespan] "1:2:21" $end = $start + $duration $history = [PSCustomObject] @{ - CommandLine="command" - ExecutionStatus=[Management.Automation.Runspaces.PipelineState]::Completed - StartExecutionTime=$start - EndExecutionTime=$end + CommandLine = "command" + ExecutionStatus = [Management.Automation.Runspaces.PipelineState]::Completed + StartExecutionTime = $start + EndExecutionTime = $end } $history | Add-History $h = Get-History -count 1 - $h.Duration | Should Be $duration + $h.Duration | Should -Be $duration } }