Skip to content

Commit b5713fb

Browse files
List All get paged data
1 parent ef4fb6f commit b5713fb

25 files changed

+403
-329
lines changed

src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationAccountTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ public void GetAzureAutomationAllAccountsSuccessfull()
5050
{
5151
// Setup
5252
string resourceGroupName = "resourceGroup";
53+
string nextLink = string.Empty;
5354

54-
this.mockAutomationClient.Setup(f => f.ListAutomationAccounts(resourceGroupName)).Returns((string a) => new List<AutomationAccount>());
55+
this.mockAutomationClient.Setup(f => f.ListAutomationAccounts(resourceGroupName, ref nextLink)).Returns((string a) => new List<AutomationAccount>());
5556

5657
// Test
5758
this.cmdlet.ExecuteCmdlet();
5859

5960
// Assert
60-
this.mockAutomationClient.Verify(f => f.ListAutomationAccounts(null), Times.Once());
61+
this.mockAutomationClient.Verify(f => f.ListAutomationAccounts(resourceGroupName, ref nextLink), Times.Once());
6162
}
6263

6364
[TestMethod]

src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAccount.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ public override void ExecuteCmdlet()
7777
{
7878
this.AutomationClient.GetAutomationAccount(this.ResourceGroupName, this.Name)
7979
};
80+
this.WriteObject(ret, true);
8081
}
8182
else
8283
{
83-
ret = this.AutomationClient.ListAutomationAccounts(this.ResourceGroupName);
84-
}
84+
string nextLink = string.Empty;
85+
86+
do
87+
{
88+
ret = this.AutomationClient.ListAutomationAccounts(this.ResourceGroupName, ref nextLink);
89+
this.WriteObject(ret, true);
8590

86-
this.WriteObject(ret, true);
91+
} while (!string.IsNullOrEmpty(nextLink));
92+
}
8793
}
8894
}
8995
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,19 @@ protected override void AutomationExecuteCmdlet()
4848
{
4949
this.AutomationClient.GetModule(this.ResourceGroupName, this.AutomationAccountName, this.Name)
5050
};
51+
this.GenerateCmdletOutput(ret);
5152
}
5253
else
5354
{
54-
ret = this.AutomationClient.ListModules(this.ResourceGroupName, this.AutomationAccountName);
55-
}
55+
string nextLink = string.Empty;
56+
57+
do
58+
{
59+
ret = this.AutomationClient.ListModules(this.ResourceGroupName, this.AutomationAccountName, ref nextLink);
60+
this.GenerateCmdletOutput(ret);
5661

57-
this.GenerateCmdletOutput(ret);
62+
} while (!string.IsNullOrEmpty(nextLink));
63+
}
5864
}
5965
}
6066
}

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,23 @@ void SetClientIdHeader(string clientRequestId)
7575

7676
#region Account Operations
7777

78-
public IEnumerable<Model.AutomationAccount> ListAutomationAccounts(string resourceGroupName)
78+
public IEnumerable<Model.AutomationAccount> ListAutomationAccounts(string resourceGroupName, ref string nextLink)
7979
{
8080
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
8181

82-
return AutomationManagementClient
83-
.ContinuationTokenHandler(
84-
skipToken =>
85-
{
86-
var response = this.automationManagementClient.AutomationAccounts.List(
87-
resourceGroupName);
88-
return new ResponseWithSkipToken<AutomationManagement.Models.AutomationAccount>(
89-
response, response.AutomationAccounts);
90-
}).Select(c => new Model.AutomationAccount(resourceGroupName, c));
82+
AutomationAccountListResponse response;
83+
84+
if (string.IsNullOrEmpty(nextLink))
85+
{
86+
response = this.automationManagementClient.AutomationAccounts.List(resourceGroupName);
87+
}
88+
else
89+
{
90+
response = this.automationManagementClient.AutomationAccounts.ListNext(nextLink);
91+
}
92+
93+
nextLink = response.NextLink;
94+
return response.AutomationAccounts.Select(c => new AutomationAccount(resourceGroupName, c));
9195
}
9296

9397
public AutomationAccount GetAutomationAccount(string resourceGroupName, string automationAccountName)
@@ -231,18 +235,22 @@ public Module GetModule(string resourceGroupName, string automationAccountName,
231235
}
232236
}
233237

234-
public IEnumerable<Module> ListModules(string resourceGroupName, string automationAccountName)
238+
public IEnumerable<Module> ListModules(string resourceGroupName, string automationAccountName, ref string nextLink)
235239
{
236-
IList<AutomationManagement.Models.Module> modulesModels = AutomationManagementClient
237-
.ContinuationTokenHandler(
238-
skipToken =>
239-
{
240-
var response = this.automationManagementClient.Modules.List(resourceGroupName, automationAccountName);
241-
return new ResponseWithSkipToken<AutomationManagement.Models.Module>(
242-
response, response.Modules);
243-
});
240+
ModuleListResponse response;
241+
242+
if (string.IsNullOrEmpty(nextLink))
243+
{
244+
response = this.automationManagementClient.Modules.List(resourceGroupName,
245+
automationAccountName);
246+
}
247+
else
248+
{
249+
response = this.automationManagementClient.Modules.ListNext(nextLink);
250+
}
244251

245-
return modulesModels.Select(c => new Module(resourceGroupName, automationAccountName, c));
252+
nextLink = response.NextLink;
253+
return response.Modules.Select(c => new Module(resourceGroupName, automationAccountName, c));
246254
}
247255

248256
public Module UpdateModule(string resourceGroupName, string automationAccountName, string name, Uri contentLinkUri, string contentLinkVersion)

src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IAutomationClient
2828

2929
#region Accounts
3030

31-
IEnumerable<AutomationAccount> ListAutomationAccounts(string resourceGroupName);
31+
IEnumerable<AutomationAccount> ListAutomationAccounts(string resourceGroupName, ref string nextLink);
3232

3333
AutomationAccount GetAutomationAccount(string resourceGroupName, string automationAccountName);
3434

@@ -113,7 +113,7 @@ IEnumerable<DscNode> ListDscNodesByConfiguration(
113113

114114
Module UpdateModule(string resourceGroupName, string automationAccountName, string name, Uri contentLink, string contentLinkVersion);
115115

116-
IEnumerable<Module> ListModules(string resourceGroupName, string automationAccountName);
116+
IEnumerable<Module> ListModules(string resourceGroupName, string automationAccountName, ref string nextLink);
117117

118118
void DeleteModule(string resourceGroupName, string automationAccountName, string name);
119119

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCertificateTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ public void GetAzureAutomationCertificateByAllSuccessfull()
7070
{
7171
// Setup
7272
string accountName = "automation";
73+
string nextLink = string.Empty;
7374

74-
this.mockAutomationClient.Setup(f => f.ListCertificates(accountName)).Returns((string a) => new List<CertificateInfo>());
75+
this.mockAutomationClient.Setup(f => f.ListCertificates(accountName, ref nextLink)).Returns((string a, string b) => new List<CertificateInfo>());
7576

7677
// Test
7778
this.cmdlet.AutomationAccountName = accountName;
7879
this.cmdlet.ExecuteCmdlet();
7980

8081
// Assert
81-
this.mockAutomationClient.Verify(f => f.ListCertificates(accountName), Times.Once());
82+
this.mockAutomationClient.Verify(f => f.ListCertificates(accountName, ref nextLink), Times.Once());
8283
}
8384
}
8485
}

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationConnectionTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ public void GetAzureAutomationConnectionByAllSuccessfull()
7070
{
7171
// Setup
7272
string accountName = "automation";
73+
string nextLink = string.Empty;
7374

74-
this.mockAutomationClient.Setup(f => f.ListConnections(accountName)).Returns((string a) => new List<Connection>());
75+
this.mockAutomationClient.Setup(f => f.ListConnections(accountName, ref nextLink)).Returns((string a, string b) => new List<Connection>());
7576

7677
// Test
7778
this.cmdlet.AutomationAccountName = accountName;
7879
this.cmdlet.ExecuteCmdlet();
7980

8081
// Assert
81-
this.mockAutomationClient.Verify(f => f.ListConnections(accountName), Times.Once());
82+
this.mockAutomationClient.Verify(f => f.ListConnections(accountName, ref nextLink), Times.Once());
8283
}
8384

8485
[TestMethod]

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ public void GetAzureAutomationCredentialByAllSuccessfull()
6868
{
6969
// Setup
7070
string accountName = "automation";
71+
string nextLink = string.Empty;
7172

72-
this.mockAutomationClient.Setup(f => f.ListCredentials(accountName)).Returns((string a) => new List<CredentialInfo>());
73+
this.mockAutomationClient.Setup(f => f.ListCredentials(accountName, ref nextLink)).Returns((string a, string b) => new List<CredentialInfo>());
7374

7475
// Test
7576
this.cmdlet.AutomationAccountName = accountName;
7677
this.cmdlet.ExecuteCmdlet();
7778

7879
// Assert
79-
this.mockAutomationClient.Verify(f => f.ListCredentials(accountName), Times.Once());
80+
this.mockAutomationClient.Verify(f => f.ListCredentials(accountName, ref nextLink), Times.Once());
8081
}
8182
}
8283
}

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationJobTest.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,52 @@ public void GetAzureAutomationJobByRunbookNameSuccessfull()
5151
// Setup
5252
string accountName = "automation";
5353
string runbookName = "runbook";
54+
string nextLink = string.Empty;
5455

55-
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null));
56+
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null, ref nextLink));
5657

5758
// Test
5859
this.cmdlet.AutomationAccountName = accountName;
5960
this.cmdlet.RunbookName = runbookName;
6061
this.cmdlet.ExecuteCmdlet();
6162

6263
// Assert
63-
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null), Times.Once());
64+
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null, ref nextLink), Times.Once());
6465
}
6566

6667
public void GetAzureAutomationJobByRunbookNamAndStartTimeEndTimeeSuccessfull()
6768
{
6869
// Setup
6970
string accountName = "automation";
7071
string runbookName = "runbook";
72+
string nextLink = string.Empty;
73+
7174
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
7275
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
7376

74-
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null));
77+
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null, ref nextLink));
7578

7679
// Test
7780
this.cmdlet.AutomationAccountName = accountName;
7881
this.cmdlet.RunbookName = runbookName;
7982
this.cmdlet.ExecuteCmdlet();
8083

8184
// Assert
82-
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null), Times.Once());
85+
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null, ref nextLink), Times.Once());
8386
}
8487

8588
public void GetAzureAutomationCompletedJobByRunbookNamAndStartTimeEndTimeeSuccessfull()
8689
{
8790
// Setup
8891
string accountName = "automation";
8992
string runbookName = "runbook";
93+
string nextLink = string.Empty;
94+
9095
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
9196
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
9297
string status = "Completed";
9398

94-
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status));
99+
this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status, ref nextLink));
95100

96101
// Test
97102
this.cmdlet.AutomationAccountName = accountName;
@@ -100,35 +105,38 @@ public void GetAzureAutomationCompletedJobByRunbookNamAndStartTimeEndTimeeSucces
100105
this.cmdlet.ExecuteCmdlet();
101106

102107
// Assert
103-
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status), Times.Once());
108+
this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status, ref nextLink), Times.Once());
104109
}
105110

106111
[TestMethod]
107112
public void GetAzureAutomationAllJobsSuccessfull()
108113
{
109114
// Setup
110115
string accountName = "automation";
116+
string nextLink = string.Empty;
111117

112-
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, null, null, null));
118+
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, null, null, null, ref nextLink));
113119

114120
// Test
115121
this.cmdlet.AutomationAccountName = accountName;
116122
this.cmdlet.ExecuteCmdlet();
117123

118124
// Assert
119-
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, null, null, null), Times.Once());
125+
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, null, null, null, ref nextLink), Times.Once());
120126
}
121127

122128
[TestMethod]
123129
public void GetAzureAutomationAllJobsBetweenStartAndEndTimeSuccessfull()
124130
{
125131
// Setup
126132
string accountName = "automation";
133+
string nextLink = string.Empty;
134+
127135
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
128136
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
129137

130138
// look for jobs between 5pm to 6pm on 30th december 2014
131-
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, null));
139+
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, null, ref nextLink));
132140

133141
// Test
134142
this.cmdlet.AutomationAccountName = accountName;
@@ -137,20 +145,22 @@ public void GetAzureAutomationAllJobsBetweenStartAndEndTimeSuccessfull()
137145
this.cmdlet.ExecuteCmdlet();
138146

139147
// Assert
140-
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, null), Times.Once());
148+
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, null, ref nextLink), Times.Once());
141149
}
142150

143151
[TestMethod]
144152
public void GetAzureAutomationAllCompletedJobsBetweenStartAndEndTimeSuccessfull()
145153
{
146154
// Setup
147155
string accountName = "automation";
156+
string nextLink = string.Empty;
157+
148158
DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0);
149159
DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0);
150160
string status = "Completed";
151161

152162
// look for jobs between 5pm to 6pm on 30th december 2014
153-
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, status));
163+
this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, status, ref nextLink));
154164

155165
// Test
156166
this.cmdlet.AutomationAccountName = accountName;
@@ -160,7 +170,7 @@ public void GetAzureAutomationAllCompletedJobsBetweenStartAndEndTimeSuccessfull(
160170
this.cmdlet.ExecuteCmdlet();
161171

162172
// Assert
163-
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, status), Times.Once());
173+
this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, status, ref nextLink), Times.Once());
164174
}
165175

166176
public void GetAzureAutomationJobByIdSuccessfull()

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ public void GetAzureAutomationModuleByAllSuccessfull()
6868
{
6969
// Setup
7070
string accountName = "automation";
71+
string nextLink = string.Empty;
7172

72-
this.mockAutomationClient.Setup(f => f.ListModules(accountName)).Returns((string a) => new List<Module>());
73+
this.mockAutomationClient.Setup(f => f.ListModules(accountName, ref nextLink)).Returns((string a, string b) => new List<Module>());
7374

7475
// Test
7576
this.cmdlet.AutomationAccountName = accountName;
7677
this.cmdlet.ExecuteCmdlet();
7778

7879
// Assert
79-
this.mockAutomationClient.Verify(f => f.ListModules(accountName), Times.Once());
80+
this.mockAutomationClient.Verify(f => f.ListModules(accountName, ref nextLink), Times.Once());
8081
}
8182
}
8283
}

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationRunbookTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,17 @@ public void GetAzureAutomationRunbookByAllSuccessfull()
7070
{
7171
// Setup
7272
string accountName = "automation";
73+
string nextLink = string.Empty;
7374

74-
this.mockAutomationClient.Setup(f => f.ListRunbooks(accountName)).Returns((string a) => new List<Runbook>()); ;
75+
this.mockAutomationClient.Setup(f => f.ListRunbooks(accountName, ref nextLink)).Returns((string a, string b) => new List<Runbook>()); ;
7576

7677
// Test
7778
this.cmdlet.AutomationAccountName = accountName;
7879
this.cmdlet.SetParameterSet("ByAll");
7980
this.cmdlet.ExecuteCmdlet();
8081

8182
// Assert
82-
this.mockAutomationClient.Verify(f => f.ListRunbooks(accountName), Times.Once());
83+
this.mockAutomationClient.Verify(f => f.ListRunbooks(accountName, ref nextLink), Times.Once());
8384
}
8485
}
8586
}

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduleTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,17 @@ public void GetAzureAutomationScheduleByAllSuccessfull()
7070
{
7171
// Setup
7272
string accountName = "automation";
73+
string nextLink = string.Empty;
7374

74-
this.mockAutomationClient.Setup(f => f.ListSchedules(accountName)).Returns((string a) => new List<Schedule>());
75+
this.mockAutomationClient.Setup(f => f.ListSchedules(accountName, ref nextLink)).Returns((string a, string b) => new List<Schedule>());
7576

7677
// Test
7778
this.cmdlet.AutomationAccountName = accountName;
7879
this.cmdlet.SetParameterSet(AutomationCmdletParameterSets.ByAll);
7980
this.cmdlet.ExecuteCmdlet();
8081

8182
// Assert
82-
this.mockAutomationClient.Verify(f => f.ListSchedules(accountName), Times.Once());
83+
this.mockAutomationClient.Verify(f => f.ListSchedules(accountName, ref nextLink), Times.Once());
8384
}
8485
}
8586
}

0 commit comments

Comments
 (0)