Move warning message to EndProcessing so it only shows up once (#9385)

This commit is contained in:
Steve Lee 2019-04-23 13:31:20 -07:00 committed by Andrew
parent 600a93750e
commit 5e58e30d20
2 changed files with 18 additions and 2 deletions

View file

@ -30,6 +30,14 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
[Parameter]
public ConfigScope Scope { get; set; } = ConfigScope.CurrentUser;
/// <summary>
/// EndProcessing method.
/// </summary>
protected override void EndProcessing()
{
WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending);
}
}
/// <summary>
@ -87,8 +95,6 @@ namespace Microsoft.PowerShell.Commands
cmdlet.WriteError(new ErrorRecord(new ItemNotFoundException(errMsg), "ItemNotFoundException", ErrorCategory.ObjectNotFound, name));
return;
}
cmdlet.WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending);
}
}

View file

@ -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 <cmdlet>" -TestCases @(
@{ cmdlet = "Enable-ExperimentalFeature" },
@{ cmdlet = "Disable-Experimentalfeature" }
) {
param ($cmdlet)
Get-ExperimentalFeature | & $cmdlet -WarningAction SilentlyContinue -WarningVariable warning
$warning | Should -HaveCount 1
}
}