Skip to content

Commit bd5f226

Browse files
committed
FW: Fixing minor issues in the code, changing the return type of the Get-UsageMetrics Cmdlet.
1 parent 4d0d4bf commit bd5f226

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/ResourceManager/Insights/Commands.Insights.Test/UsageMetrics/GetUsageMetricsCommandTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public GetUsageMetricsCommandTests()
4949

5050
response = Utilities.InitializeUsageMetricResponse();
5151

52-
insightsUsageMetricOperationsMock.Setup(f => f.ListAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
52+
insightsUsageMetricOperationsMock
53+
.Setup(f => f.ListAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
5354
.Returns(Task.FromResult<UsageMetricListResponse>(response))
5455
.Callback((string f, string s, string a, CancellationToken t) =>
5556
{
@@ -58,7 +59,9 @@ public GetUsageMetricsCommandTests()
5859
apiVersion = a;
5960
});
6061

61-
insightsClientMock.SetupGet(f => f.UsageMetricOperations).Returns(this.insightsUsageMetricOperationsMock.Object);
62+
insightsClientMock
63+
.SetupGet(f => f.UsageMetricOperations)
64+
.Returns(this.insightsUsageMetricOperationsMock.Object);
6265
}
6366

6467
private void CleanParamVariables()

src/ResourceManager/Insights/Commands.Insights/UsageMetrics/GetUsageMetricsCommand.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ namespace Microsoft.Azure.Commands.Insights.UsageMetrics
2525
/// <summary>
2626
/// Get the list of usage metrics for a resource.
2727
/// </summary>
28-
[Cmdlet(VerbsCommon.Get, "UsageMetrics"), OutputType(typeof(UsageMetric[]))]
28+
[Cmdlet(VerbsCommon.Get, "UsageMetrics"), OutputType(typeof(PSUsageMetric[]))]
2929
public class GetUsageMetricsCommand : InsightsClientCmdletBase
3030
{
3131
/// <summary>
3232
/// Default value of the timerange to search for usage metrics
3333
/// </summary>
3434
public static readonly TimeSpan DefaultTimeRange = TimeSpan.FromHours(1);
3535

36+
/// <summary>
37+
/// Default API version string for the underlying RP.
38+
/// The Insights backend gets the data from the RPs, and the RPs don not necessarily use the same API version.
39+
/// </summary>
3640
public static readonly string DefaultApiVersion = "2014-04-01";
3741

3842
/// <summary>
@@ -77,7 +81,9 @@ protected string ProcessParameters()
7781
var buffer = new StringBuilder();
7882
if (this.MetricNames != null)
7983
{
80-
var metrics = this.MetricNames.Select(n => string.Concat("name.value eq '", n, "'")).Aggregate((a, b) => string.Concat(a, " or ", b));
84+
var metrics = this.MetricNames
85+
.Select(n => string.Concat("name.value eq '", n, "'"))
86+
.Aggregate((a, b) => string.Concat(a, " or ", b));
8187

8288
buffer.Append("(");
8389
buffer.Append(metrics);
@@ -120,8 +126,12 @@ protected override void ExecuteCmdletInternal()
120126

121127
// Call the proper API methods to return a list of raw records.
122128
// If fullDetails is present full details of the records displayed, otherwise only a summary of the values is displayed
123-
UsageMetricListResponse response = this.InsightsClient.UsageMetricOperations.ListAsync(resourceUri: this.ResourceId, filterString: queryFilter, apiVersion: apiVersion, cancellationToken: CancellationToken.None).Result;
124-
var records = response.UsageMetricCollection.Value.Select(e => new PSUsageMetric(e)).ToArray();
129+
UsageMetricListResponse response = this.InsightsClient.UsageMetricOperations
130+
.ListAsync(resourceUri: this.ResourceId, filterString: queryFilter, apiVersion: apiVersion, cancellationToken: CancellationToken.None)
131+
.Result;
132+
var records = response.UsageMetricCollection.Value
133+
.Select(e => new PSUsageMetric(e))
134+
.ToArray();
125135

126136
WriteObject(sendToPipeline: records);
127137
}

0 commit comments

Comments
 (0)