Fetch resource string correctly (#5114)

This commit is contained in:
Dongbo Wang 2017-10-18 11:36:25 -07:00 committed by Aditya Patwardhan
parent db6aec0850
commit 2ceec725f6
3 changed files with 10 additions and 4 deletions

View file

@ -514,7 +514,7 @@ namespace Microsoft.PowerShell.Commands
private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args)
{
ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly,
"AddMember", resourceId, args);
"Microsoft.PowerShell.Commands.Utility.resources.AddMember", resourceId, args);
ErrorRecord errorRecord = new ErrorRecord(
new InvalidOperationException(details.Message),
errorId,

View file

@ -381,10 +381,8 @@ namespace Microsoft.PowerShell.Commands
private ErrorRecord NewError()
{
ErrorDetails details = new ErrorDetails(this.GetType().GetTypeInfo().Assembly,
"WebCmdletStrings", "JsonStringInBadFormat");
ErrorRecord errorRecord = new ErrorRecord(
new InvalidOperationException(details.Message),
new InvalidOperationException(WebCmdletStrings.JsonStringInBadFormat),
"JsonStringInBadFormat",
ErrorCategory.InvalidOperation,
InputObject);

View file

@ -276,6 +276,14 @@
$results = add-member -InputObject a 16 sp {1+1} -passthru
$results.sp | Should Be 2
}
It "Verify Add-Member error message is not empty" {
$object = @(1,2)
Add-Member -InputObject $object "ABC" "Value1"
Add-Member -InputObject $object "ABC" "Value2" -ErrorVariable errorVar -ErrorAction SilentlyContinue
$errorVar.Exception | Should BeOfType "System.InvalidOperationException"
$errorVar.Exception.Message | Should Not BeNullOrEmpty
}
}
Describe "Add-Member" -Tags "CI" {