From 5e58e30d20458d1478edf260a15215f835db173f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 23 Apr 2019 13:31:20 -0700 Subject: [PATCH] Move warning message to EndProcessing so it only shows up once (#9385) --- .../EnableDisableExperimentalFeatureCommand.cs | 10 ++++++++-- .../EnableDisable-ExperimentalFeature.Tests.ps1 | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/ExperimentalFeature/EnableDisableExperimentalFeatureCommand.cs b/src/System.Management.Automation/engine/ExperimentalFeature/EnableDisableExperimentalFeatureCommand.cs index 2c9763dcd..35a404b67 100644 --- a/src/System.Management.Automation/engine/ExperimentalFeature/EnableDisableExperimentalFeatureCommand.cs +++ b/src/System.Management.Automation/engine/ExperimentalFeature/EnableDisableExperimentalFeatureCommand.cs @@ -30,6 +30,14 @@ namespace Microsoft.PowerShell.Commands /// [Parameter] public ConfigScope Scope { get; set; } = ConfigScope.CurrentUser; + + /// + /// EndProcessing method. + /// + protected override void EndProcessing() + { + WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending); + } } /// @@ -87,8 +95,6 @@ namespace Microsoft.PowerShell.Commands cmdlet.WriteError(new ErrorRecord(new ItemNotFoundException(errMsg), "ItemNotFoundException", ErrorCategory.ObjectNotFound, name)); return; } - - cmdlet.WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending); } } diff --git a/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 b/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 index 75f0fa49d..35792753f 100644 --- a/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 +++ b/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 @@ -94,4 +94,14 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag & $cmdlet ExpTest.FeatureOne -WarningVariable warning -WarningAction SilentlyContinue $warning | Should -Not -BeNullOrEmpty -Because "A warning message is always given indicating restart is required" } + + It "Multiple features enabled will only output one warning message for " -TestCases @( + @{ cmdlet = "Enable-ExperimentalFeature" }, + @{ cmdlet = "Disable-Experimentalfeature" } + ) { + param ($cmdlet) + + Get-ExperimentalFeature | & $cmdlet -WarningAction SilentlyContinue -WarningVariable warning + $warning | Should -HaveCount 1 + } }