16
16
using System . Collections . Generic ;
17
17
using System . Xml ;
18
18
using Microsoft . Azure . Commands . Insights . Metrics ;
19
- using Microsoft . Azure . Insights . Legacy ;
20
- using Microsoft . Azure . Insights . Legacy . Models ;
19
+ using Microsoft . Azure . Insights ;
20
+ using Microsoft . Azure . Insights . Models ;
21
21
using Microsoft . Rest . Azure . OData ;
22
22
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
23
23
using Moq ;
@@ -33,84 +33,96 @@ public class GetAzureRmMetricTests
33
33
{
34
34
private readonly GetAzureRmMetricCommand cmdlet ;
35
35
private readonly Mock < InsightsClient > insightsClientMock ;
36
- private readonly Mock < IMetricOperations > insightsMetricOperationsMock ;
36
+ private readonly Mock < IMetricsOperations > insightsMetricOperationsMock ;
37
37
private Mock < ICommandRuntime > commandRuntimeMock ;
38
- private MetricListResponse response ;
38
+ private Microsoft . Rest . Azure . AzureOperationResponse < IEnumerable < Metric > > response ;
39
39
private string resourceId ;
40
- private string filter ;
40
+ private ODataQuery < Metric > filter ;
41
41
42
42
public GetAzureRmMetricTests ( Xunit . Abstractions . ITestOutputHelper output )
43
43
{
44
44
ServiceManagemenet . Common . Models . XunitTracingInterceptor . AddToContext ( new ServiceManagemenet . Common . Models . XunitTracingInterceptor ( output ) ) ;
45
- insightsMetricOperationsMock = new Mock < IMetricOperations > ( ) ;
45
+ insightsMetricOperationsMock = new Mock < IMetricsOperations > ( ) ;
46
46
insightsClientMock = new Mock < InsightsClient > ( ) ;
47
47
commandRuntimeMock = new Mock < ICommandRuntime > ( ) ;
48
48
cmdlet = new GetAzureRmMetricCommand ( )
49
49
{
50
50
CommandRuntime = commandRuntimeMock . Object ,
51
- // InsightsClient = insightsClientMock.Object
51
+ InsightsClient = insightsClientMock . Object
52
52
} ;
53
53
54
- response = Utilities . InitializeMetricResponse ( ) ;
54
+ response = new Microsoft . Rest . Azure . AzureOperationResponse < IEnumerable < Metric > > ( )
55
+ {
56
+ Body = new List < Metric > ( )
57
+ } ;
55
58
56
- insightsMetricOperationsMock . Setup ( f => f . GetMetricsAsync ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
57
- . Returns ( Task . FromResult < MetricListResponse > ( response ) )
58
- . Callback ( ( string f , string s , CancellationToken t ) =>
59
+ insightsMetricOperationsMock . Setup ( f => f . ListWithHttpMessagesAsync ( It . IsAny < string > ( ) , It . IsAny < ODataQuery < Metric > > ( ) , It . IsAny < Dictionary < string , List < string > > > ( ) , It . IsAny < CancellationToken > ( ) ) )
60
+ . Returns ( Task . FromResult < Microsoft . Rest . Azure . AzureOperationResponse < IEnumerable < Metric > > > ( response ) )
61
+ . Callback ( ( string r , ODataQuery < Metric > s , Dictionary < string , List < string > > headers , CancellationToken t ) =>
59
62
{
60
- resourceId = f ;
63
+ resourceId = r ;
61
64
filter = s ;
62
65
} ) ;
63
66
64
- insightsClientMock . SetupGet ( f => f . MetricOperations ) . Returns ( this . insightsMetricOperationsMock . Object ) ;
67
+ insightsClientMock . SetupGet ( f => f . Metrics ) . Returns ( this . insightsMetricOperationsMock . Object ) ;
65
68
}
66
69
67
- [ Fact ( Skip = "Disable this release since there are conflicts between DLL versions" ) ]
70
+ [ Fact ] // (Skip = "Disable this release since there are conflicts between DLL versions")]
68
71
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
69
72
public void GetMetricsCommandParametersProcessing ( )
70
73
{
71
74
// Testting defaults and required parameters
72
75
cmdlet . ResourceId = Utilities . ResourceUri ;
73
- cmdlet . TimeGrain = TimeSpan . FromMinutes ( 1 ) ;
74
76
75
77
cmdlet . ExecuteCmdlet ( ) ;
76
- Assert . True ( filter != null && filter . Contains ( "timeGrain eq duration'PT1M'" ) && filter . Contains ( " and startTime eq " ) && filter . Contains ( " and endTime eq " ) ) ;
78
+ Assert . True ( filter != null && filter . Filter == null ) ;
77
79
Assert . Equal ( Utilities . ResourceUri , resourceId ) ;
78
80
79
- cmdlet . TimeGrain = TimeSpan . FromMinutes ( 5 ) ;
81
+ cmdlet . MetricNames = new [ ] { "n1" , "n2" } ;
82
+ cmdlet . ExecuteCmdlet ( ) ;
83
+ Assert . True ( filter != null ) ;
84
+ Assert . True ( filter . Filter . Contains ( "(name.value eq 'n1' or name.value eq 'n2')" ) ) ;
85
+ Assert . Equal ( Utilities . ResourceUri , resourceId ) ;
80
86
87
+ cmdlet . AggregationType = AggregationType . Total ;
81
88
cmdlet . ExecuteCmdlet ( ) ;
82
- Assert . True ( filter != null && filter . Contains ( "timeGrain eq duration'PT5M'" ) && filter . Contains ( " and startTime eq " ) && filter . Contains ( " and endTime eq " ) ) ;
89
+ Assert . True ( filter != null ) ;
90
+ Assert . True ( filter . Filter . Contains ( "aggregationType eq 'Total'" ) ) ;
91
+ Assert . True ( filter . Filter . Contains ( "(name.value eq 'n1' or name.value eq 'n2')" ) ) ;
83
92
Assert . Equal ( Utilities . ResourceUri , resourceId ) ;
84
93
85
- var endDate = DateTime . Now . AddMinutes ( - 1 ) ;
86
- cmdlet . TimeGrain = TimeSpan . FromMinutes ( 5 ) ;
94
+ var endDate = DateTime . UtcNow . AddMinutes ( - 1 ) ;
95
+ cmdlet . AggregationType = AggregationType . Average ;
87
96
cmdlet . EndTime = endDate ;
88
97
89
- var startTime = endDate . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . ToString ( "O" ) ;
90
- var endTime = endDate . ToString ( "O" ) ;
91
- var expected = "timeGrain eq duration'PT5M' and startTime eq " + startTime + " and endTime eq " + endTime ;
92
-
93
98
// Remove the value assigned in the last execution
94
99
cmdlet . StartTime = default ( DateTime ) ;
95
-
96
100
cmdlet . ExecuteCmdlet ( ) ;
97
- Assert . Equal ( expected , filter ) ;
101
+ Assert . True ( filter != null ) ;
102
+ Assert . True ( filter . Filter . Contains ( "aggregationType eq 'Average'" ) ) ;
103
+ Assert . True ( filter . Filter . Contains ( "(name.value eq 'n1' or name.value eq 'n2')" ) ) ;
104
+ Assert . True ( filter . Filter . Contains ( "startTime eq " + endDate . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . ToString ( "O" ) ) ) ;
105
+ Assert . True ( filter . Filter . Contains ( "endTime eq " + endDate . ToString ( "O" ) ) ) ;
98
106
Assert . Equal ( Utilities . ResourceUri , resourceId ) ;
99
107
100
108
cmdlet . StartTime = endDate . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) ;
101
- startTime = cmdlet . StartTime . ToString ( "O" ) ;
102
- expected = "timeGrain eq duration'PT5M' and startTime eq " + startTime + " and endTime eq " + endTime ;
103
-
104
109
cmdlet . ExecuteCmdlet ( ) ;
105
- Assert . Equal ( expected , filter ) ;
110
+ Assert . True ( filter != null ) ;
111
+ Assert . True ( filter . Filter . Contains ( "aggregationType eq 'Average'" ) ) ;
112
+ Assert . True ( filter . Filter . Contains ( "(name.value eq 'n1' or name.value eq 'n2')" ) ) ;
113
+ Assert . True ( filter . Filter . Contains ( "startTime eq " + endDate . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . ToString ( "O" ) ) ) ;
114
+ Assert . True ( filter . Filter . Contains ( "endTime eq " + endDate . ToString ( "O" ) ) ) ;
106
115
Assert . Equal ( Utilities . ResourceUri , resourceId ) ;
107
116
108
- // Testing with optional parameters
109
- cmdlet . MetricNames = new [ ] { "n1" , "n2" } ;
110
- expected = "(name.value eq 'n1' or name.value eq 'n2') and " + expected ;
111
-
117
+ cmdlet . AggregationType = AggregationType . Maximum ;
118
+ cmdlet . TimeGrain = TimeSpan . FromMinutes ( 5 ) ;
112
119
cmdlet . ExecuteCmdlet ( ) ;
113
- Assert . Equal ( expected , filter ) ;
120
+ Assert . True ( filter != null ) ;
121
+ Assert . True ( filter . Filter . Contains ( "aggregationType eq 'Maximum'" ) ) ;
122
+ Assert . True ( filter . Filter . Contains ( "(name.value eq 'n1' or name.value eq 'n2')" ) ) ;
123
+ Assert . True ( filter . Filter . Contains ( "startTime eq " + endDate . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . Subtract ( GetAzureRmMetricCommand . DefaultTimeRange ) . ToString ( "O" ) ) ) ;
124
+ Assert . True ( filter . Filter . Contains ( "endTime eq " + endDate . ToString ( "O" ) ) ) ;
125
+ Assert . True ( filter . Filter . Contains ( "timeGrain eq duration'" + XmlConvert . ToString ( cmdlet . TimeGrain ) + "'" ) ) ;
114
126
Assert . Equal ( Utilities . ResourceUri , resourceId ) ;
115
127
}
116
128
}
0 commit comments