|
13 | 13 | // ----------------------------------------------------------------------------------
|
14 | 14 |
|
15 | 15 | using Microsoft.Azure.PowerShell.Tools.AzPredictor.Test.Mocks;
|
16 |
| -using Microsoft.Azure.PowerShell.Tools.AzPredictor.Utilities; |
17 | 16 | using System;
|
18 | 17 | using System.Collections.Generic;
|
19 | 18 | using System.Linq;
|
@@ -204,6 +203,25 @@ public void VerifyIncompleteParameterInMiddel(string inputData)
|
204 | 203 | Assert.Throws<CommandLineException>(() => new ParameterSet(commandAst, _azContext));
|
205 | 204 | }
|
206 | 205 |
|
| 206 | + /// <summary> |
| 207 | + /// Verify that we can parse the - in the parameter value. |
| 208 | + /// </summary> |
| 209 | + [Fact] |
| 210 | + public void VerifyMinusInParameterValue() |
| 211 | + { |
| 212 | + var inputData = "Set-Date -Adjust -0:10:0 -DisplayHint Time"; |
| 213 | + var predictionContext = PredictionContext.Create(inputData); |
| 214 | + var commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 215 | + var expected = new List<Parameter>() |
| 216 | + { |
| 217 | + new Parameter("Adjust", "-0:10:0", false), |
| 218 | + new Parameter("DisplayHint", "Time", false), |
| 219 | + }; |
| 220 | + |
| 221 | + var parameterSet = new ParameterSet(commandAst, _azContext); |
| 222 | + Assert.Equal(expected, parameterSet.Parameters); |
| 223 | + } |
| 224 | + |
207 | 225 | /// <summary>
|
208 | 226 | /// Verify that the one positional parameter can be parsed.
|
209 | 227 | /// </summary>
|
@@ -298,5 +316,90 @@ public void VerifyPositionalParametersAfterNamedParameters()
|
298 | 316 | var commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault();
|
299 | 317 | Assert.Throws<CommandLineException>(() => new ParameterSet(commandAst, _azContext));
|
300 | 318 | }
|
| 319 | + |
| 320 | + /// <summary> |
| 321 | + /// Verify that we can parse the @ in the parameter names/values. |
| 322 | + /// </summary> |
| 323 | + [Fact] |
| 324 | + public void VerifyParameterValuesWithAtSymbol() |
| 325 | + { |
| 326 | + // We should be able to parse the @ symbol when it's used as the parameter value. |
| 327 | + var inputData = "New-AzWebApp -Location westus -ResourceGroupName webappGroup -Name webappname -AppServicePlan appServicePlan -Force -Tag @{ Name1 = \"value\"; Name2 = \"Value2\" }"; |
| 328 | + var predictionContext = PredictionContext.Create(inputData); |
| 329 | + var commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 330 | + var expected = new List<Parameter>() |
| 331 | + { |
| 332 | + new Parameter("Location", "westus", false), |
| 333 | + new Parameter("ResourceGroupName", "webappGroup", false), |
| 334 | + new Parameter("Name", "webappname", false), |
| 335 | + new Parameter("AppServicePlan", "appServicePlan", false), |
| 336 | + new Parameter("Force", null, false), |
| 337 | + new Parameter("Tag", "@{ Name1 = \"value\"; Name2 = \"Value2\" }", false), |
| 338 | + }; |
| 339 | + |
| 340 | + var parameterSet = new ParameterSet(commandAst, _azContext); |
| 341 | + Assert.Equal(expected, parameterSet.Parameters); |
| 342 | + |
| 343 | + // We should be able to parse the @ symbol when it's used as the parameter value. |
| 344 | + inputData = "Invoke-AzMLWorkspaceDiagnose -ResourceGroupName ml-rg-test -Name mlworkspace-cli01 -ApplicationInsightId @{'key1'=\"/subscriptions/xxxx-xxxxx-xxxxxxxxx-xxxx/resourceGroups/ml-rg-test/providers/Microsoft.insights/components/xxxxxxxxxxx\"}"; |
| 345 | + predictionContext = PredictionContext.Create(inputData); |
| 346 | + commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 347 | + expected = new List<Parameter>() |
| 348 | + { |
| 349 | + new Parameter("ResourceGroupName", "ml-rg-test", false), |
| 350 | + new Parameter("Name", "mlworkspace-cli01", false), |
| 351 | + new Parameter("ApplicationInsightId", "@{'key1'=\"/subscriptions/xxxx-xxxxx-xxxxxxxxx-xxxx/resourceGroups/ml-rg-test/providers/Microsoft.insights/components/xxxxxxxxxxx\"}", false), |
| 352 | + }; |
| 353 | + |
| 354 | + parameterSet = new ParameterSet(commandAst, _azContext); |
| 355 | + Assert.Equal(expected, parameterSet.Parameters); |
| 356 | + |
| 357 | + inputData = "New-AzActivityLogAlertActionGroupObject -Id $ActionGroupResourceId -WebhookProperty @{\"sampleWebhookProperty\"=\"SamplePropertyValue\"}"; |
| 358 | + predictionContext = PredictionContext.Create(inputData); |
| 359 | + commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 360 | + expected = new List<Parameter>() |
| 361 | + { |
| 362 | + new Parameter("Id", "$ActionGroupResourceId", false), |
| 363 | + new Parameter("WebhookProperty", "@{\"sampleWebhookProperty\"=\"SamplePropertyValue\"}", false), |
| 364 | + }; |
| 365 | + |
| 366 | + parameterSet = new ParameterSet(commandAst, _azContext); |
| 367 | + Assert.Equal(expected, parameterSet.Parameters); |
| 368 | + |
| 369 | + inputData = "New-AzAutoscaleWebhookNotificationObject -Property @{} -ServiceUri \"http://myservice.com\""; |
| 370 | + predictionContext = PredictionContext.Create(inputData); |
| 371 | + commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 372 | + expected = new List<Parameter>() |
| 373 | + { |
| 374 | + new Parameter("Property", "@{}", false), |
| 375 | + new Parameter("ServiceUri", "\"http://myservice.com\"", false), |
| 376 | + }; |
| 377 | + |
| 378 | + parameterSet = new ParameterSet(commandAst, _azContext); |
| 379 | + Assert.Equal(expected, parameterSet.Parameters); |
| 380 | + |
| 381 | + inputData = "New-AzCommunicationServiceKey -CommunicationServiceName ContosoAcsResource1 -ResourceGroupName ContosoResourceProvider1 -Parameter @{KeyType=\"Primary\"}"; |
| 382 | + predictionContext = PredictionContext.Create(inputData); |
| 383 | + commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 384 | + expected = new List<Parameter>() |
| 385 | + { |
| 386 | + new Parameter("CommunicationServiceName", "ContosoAcsResource1", false), |
| 387 | + new Parameter("ResourceGroupName", "ContosoResourceProvider1", false), |
| 388 | + new Parameter("Parameter", "@{KeyType=\"Primary\"}", false), |
| 389 | + }; |
| 390 | + |
| 391 | + parameterSet = new ParameterSet(commandAst, _azContext); |
| 392 | + Assert.Equal(expected, parameterSet.Parameters); |
| 393 | + |
| 394 | + parameterSet = new ParameterSet(commandAst, _azContext); |
| 395 | + Assert.Equal(expected, parameterSet.Parameters); |
| 396 | + |
| 397 | + // When @ is used to indicate the variable for the parameter name/value pair, we throw the exception since we |
| 398 | + // don't want to provide that as the suggestion. |
| 399 | + inputData = "New-ScriptFileInfo @newScriptInfo"; |
| 400 | + predictionContext = PredictionContext.Create(inputData); |
| 401 | + commandAst = predictionContext.RelatedAsts.OfType<CommandAst>().LastOrDefault(); |
| 402 | + Assert.Throws<CommandLineException>(() => new ParameterSet(commandAst, _azContext)); |
| 403 | + } |
301 | 404 | }
|
302 | 405 | }
|
0 commit comments