Skip to content

Commit fc7b143

Browse files
committed
Merge pull request Azure#252 from jasper-schneider/addRemovePool
Batch Add/Remove cmdlets
2 parents 84a312c + a9124c5 commit fc7b143

File tree

72 files changed

+26876
-3558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+26876
-3558
lines changed

src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@
155155
<Compile Include="Accounts\SetBatchAccountCommandTests.cs" />
156156
<Compile Include="BatchTestHelpers.cs" />
157157
<Compile Include="Jobs\GetBatchJobCommandTests.cs" />
158+
<Compile Include="Jobs\RemoveBatchJobCommandTests.cs" />
158159
<Compile Include="Models\BatchAccountContextTest.cs" />
159160
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
161+
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
162+
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
160163
<Compile Include="Properties\AssemblyInfo.cs" />
161164
<Compile Include="ScenarioTests\BatchAccountTests.cs" />
162165
<Compile Include="ScenarioTests\BatchController.cs" />
@@ -166,7 +169,11 @@
166169
<Compile Include="ScenarioTests\TaskTests.cs" />
167170
<Compile Include="ScenarioTests\WorkItemTests.cs" />
168171
<Compile Include="Tasks\GetBatchTaskCommandTests.cs" />
172+
<Compile Include="Tasks\NewBatchTaskCommandTests.cs" />
173+
<Compile Include="Tasks\RemoveBatchTaskCommandTests.cs" />
169174
<Compile Include="WorkItems\GetBatchWorkItemCommandTests.cs" />
175+
<Compile Include="WorkItems\NewBatchWorkItemCommandTests.cs" />
176+
<Compile Include="WorkItems\RemoveBatchWorkItemCommandTests.cs" />
170177
</ItemGroup>
171178
<ItemGroup>
172179
<None Include="MSSharedLibKey.snk" />
@@ -212,6 +219,12 @@
212219
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests\TestUpdatesExistingBatchAccount.json">
213220
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
214221
</None>
222+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestDeleteJob.json">
223+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
224+
</None>
225+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestDeleteJobPipeline.json">
226+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
227+
</None>
215228
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestGetJobByName.json">
216229
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
217230
</None>
@@ -230,6 +243,12 @@
230243
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestListJobsWithMaxCount.json">
231244
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
232245
</None>
246+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDeletePool.json">
247+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
248+
</None>
249+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDeletePoolPipeline.json">
250+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
251+
</None>
233252
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestGetPoolByName.json">
234253
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
235254
</None>
@@ -242,6 +261,18 @@
242261
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestListPoolsWithMaxCount.json">
243262
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
244263
</None>
264+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestNewPool.json">
265+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
266+
</None>
267+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestCreateTask.json">
268+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
269+
</None>
270+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestDeleteTask.json">
271+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
272+
</None>
273+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestDeleteTaskPipeline.json">
274+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
275+
</None>
245276
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestGetTaskByName.json">
246277
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
247278
</None>
@@ -260,6 +291,12 @@
260291
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListTasksWithMaxCount.json">
261292
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
262293
</None>
294+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.WorkItemTests\TestDeleteWorkItem.json">
295+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
296+
</None>
297+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.WorkItemTests\TestDeleteWorkItemPipeline.json">
298+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
299+
</None>
263300
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.WorkItemTests\TestGetWorkItemByName.json">
264301
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
265302
</None>
@@ -272,6 +309,9 @@
272309
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.WorkItemTests\TestListWorkItemsWithMaxCount.json">
273310
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
274311
</None>
312+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.WorkItemTests\TestNewWorkItem.json">
313+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
314+
</None>
275315
</ItemGroup>
276316
<ItemGroup>
277317
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Entities;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using System.Threading.Tasks;
24+
using Xunit;
25+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.Jobs
28+
{
29+
public class RemoveBatchJobCommandTests
30+
{
31+
private RemoveBatchJobCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public RemoveBatchJobCommandTests()
36+
{
37+
batchClientMock = new Mock<BatchClient>();
38+
commandRuntimeMock = new Mock<ICommandRuntime>();
39+
cmdlet = new RemoveBatchJobCommand()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
BatchClient = batchClientMock.Object,
43+
};
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void RemoveBatchJobParametersTest()
49+
{
50+
// Setup cmdlet without the required parameters
51+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
52+
cmdlet.BatchContext = context;
53+
54+
// Setup cmdlet to skip confirmation popup
55+
cmdlet.Force = true;
56+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
57+
58+
Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());
59+
60+
cmdlet.WorkItemName = "testWorkItem";
61+
cmdlet.Name = "job-0000000001";
62+
63+
// Don't go to the service on a DeleteJob call
64+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
65+
{
66+
if (request is DeleteJobRequest)
67+
{
68+
DeleteJobResponse response = new DeleteJobResponse();
69+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
70+
return task;
71+
}
72+
return null;
73+
});
74+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
75+
76+
// Verify no exceptions when required parameters are set
77+
cmdlet.ExecuteCmdlet();
78+
}
79+
}
80+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Entities;
19+
using Microsoft.Azure.Commands.Batch.Models;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21+
using Moq;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using System.Threading.Tasks;
25+
using Xunit;
26+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
27+
28+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
29+
{
30+
public class NewBatchPoolCommandTests
31+
{
32+
private NewBatchPoolCommand cmdlet;
33+
private Mock<BatchClient> batchClientMock;
34+
private Mock<ICommandRuntime> commandRuntimeMock;
35+
36+
public NewBatchPoolCommandTests()
37+
{
38+
batchClientMock = new Mock<BatchClient>();
39+
commandRuntimeMock = new Mock<ICommandRuntime>();
40+
cmdlet = new NewBatchPoolCommand()
41+
{
42+
CommandRuntime = commandRuntimeMock.Object,
43+
BatchClient = batchClientMock.Object,
44+
};
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void NewBatchPoolParametersTest()
50+
{
51+
// Setup cmdlet without the required parameters
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
55+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
56+
57+
cmdlet.Name = "testPool";
58+
59+
// Don't go to the service on an AddPool call
60+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
61+
{
62+
if (request is AddPoolRequest)
63+
{
64+
AddPoolResponse response = new AddPoolResponse();
65+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
66+
return task;
67+
}
68+
return null;
69+
});
70+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
71+
72+
// Verify no exceptions when required parameters are set
73+
cmdlet.ExecuteCmdlet();
74+
}
75+
}
76+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Entities;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using System.Threading.Tasks;
24+
using Xunit;
25+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
28+
{
29+
public class RemoveBatchPoolCommandTests
30+
{
31+
private RemoveBatchPoolCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public RemoveBatchPoolCommandTests()
36+
{
37+
batchClientMock = new Mock<BatchClient>();
38+
commandRuntimeMock = new Mock<ICommandRuntime>();
39+
cmdlet = new RemoveBatchPoolCommand()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
BatchClient = batchClientMock.Object,
43+
};
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void RemoveBatchPoolParametersTest()
49+
{
50+
// Setup cmdlet without the required parameters
51+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
52+
cmdlet.BatchContext = context;
53+
54+
// Setup cmdlet to skip confirmation popup
55+
cmdlet.Force = true;
56+
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
57+
58+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
59+
60+
cmdlet.Name = "testPool";
61+
62+
// Don't go to the service on a DeletePool call
63+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
64+
{
65+
if (request is DeletePoolRequest)
66+
{
67+
DeletePoolResponse response = new DeletePoolResponse();
68+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
69+
return task;
70+
}
71+
return null;
72+
});
73+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
74+
75+
// Verify no exceptions when required parameters are set
76+
cmdlet.ExecuteCmdlet();
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)