Skip to content

Batch Select/Expand parameters on Get cmdlets #1025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Management.Batch.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests\TestUpdatesExistingBatchAccount.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetAndListComputeNodesWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -382,6 +385,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestDisableAndEnableJobSchedule.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestGetAndListJobSchedulesWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobScheduleTests\TestGetJobScheduleById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -415,6 +421,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestDisableAndEnableJob.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestGetAndListJobsWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestGetJobById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -472,6 +481,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestEvaluateAutoScaleByPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestGetAndListPoolsWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestGetPoolById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -511,6 +523,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestDeleteTaskPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestGetAndListTasksWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestGetTaskById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

Expand Down Expand Up @@ -72,39 +73,63 @@ public void GetBatchComputeNodeTest()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchComputeNodesByODataFilterTest()
public void GetBatchComputeNodeODataTest()
{
// Setup cmdlet to list vms using an OData filter.
// Setup cmdlet to get a single compute node
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.PoolId = "pool";
cmdlet.Id = null;
cmdlet.Filter = "state -eq 'idle'";
cmdlet.PoolId = "testPool";
cmdlet.Id = "computeNode1";
cmdlet.Select = "id,state";

string[] idsOfConstructedComputeNodes = new[] { "computeNode1", "computeNode2" };
string requestSelect = null;

// Build some compute nodes instead of querying the service on a List ComputeNodes call
ComputeNodeListResponse response = BatchTestHelpers.CreateComputeNodeListResponse(idsOfConstructedComputeNodes);
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeListParameters, ComputeNodeListResponse>(response);
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
ComputeNodeGetResponse getResponse = BatchTestHelpers.CreateComputeNodeGetResponse(cmdlet.Id);
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeGetParameters, ComputeNodeGetResponse>(getResponse);
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
requestSelect = request.Parameters.DetailLevel.SelectClause;

// Setup the cmdlet to write pipeline output to a list that can be examined later
List<PSComputeNode> pipeline = new List<PSComputeNode>();
commandRuntimeMock.Setup(r =>
r.WriteObject(It.IsAny<PSComputeNode>()))
.Callback<object>(c => pipeline.Add((PSComputeNode)c));
return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

cmdlet.ExecuteCmdlet();

// Verify that the cmdlet wrote the constructed compute nodes to the pipeline
Assert.Equal(2, pipeline.Count);
int computeNodeCount = 0;
foreach (PSComputeNode c in pipeline)
Assert.Equal(cmdlet.Select, requestSelect);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchComputeNodesODataTest()
{
// Setup cmdlet to list compute nodes using an OData filter
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.PoolId = "testPool";
cmdlet.Id = null;
cmdlet.Filter = "startswith(id,'test')";
cmdlet.Select = "id,state";

string requestFilter = null;
string requestSelect = null;

// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeListParameters, ComputeNodeListResponse>();
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
Assert.True(idsOfConstructedComputeNodes.Contains(c.Id));
computeNodeCount++;
}
Assert.Equal(idsOfConstructedComputeNodes.Length, computeNodeCount);
requestFilter = request.Parameters.DetailLevel.FilterClause;
requestSelect = request.Parameters.DetailLevel.SelectClause;

return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

cmdlet.ExecuteCmdlet();

Assert.Equal(cmdlet.Filter, requestFilter);
Assert.Equal(cmdlet.Select, requestSelect);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

Expand Down Expand Up @@ -71,38 +72,69 @@ public void GetBatchJobScheduleTest()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchJobScheduleByODataFilterTest()
public void GetBatchJobScheduleODataTest()
{
// Setup cmdlet to get a single job schedule
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Id = "testJobSchedule";
cmdlet.Select = "id,state";
cmdlet.Expand = "stats";

string requestSelect = null;
string requestExpand = null;

// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
CloudJobScheduleGetResponse getResponse = BatchTestHelpers.CreateCloudJobScheduleGetResponse(cmdlet.Id);
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudJobScheduleGetParameters, CloudJobScheduleGetResponse>(getResponse);
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
requestSelect = request.Parameters.DetailLevel.SelectClause;
requestExpand = request.Parameters.DetailLevel.ExpandClause;

return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

cmdlet.ExecuteCmdlet();

Assert.Equal(cmdlet.Select, requestSelect);
Assert.Equal(cmdlet.Expand, requestExpand);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchJobSchedulesODataTest()
{
// Setup cmdlet to list job schedules using an OData filter
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Id = null;
cmdlet.Filter = "startswith(id,'test')";
cmdlet.Select = "id,state";
cmdlet.Expand = "stats";

string[] idsOfConstructedJobSchedules = new[] { "test1", "test2" };
string requestFilter = null;
string requestSelect = null;
string requestExpand = null;

// Build some CloudJobSchedules instead of querying the service on a List CloudJobSchedules call
CloudJobScheduleListResponse response = BatchTestHelpers.CreateCloudJobScheduleListResponse(idsOfConstructedJobSchedules);
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudJobScheduleListParameters, CloudJobScheduleListResponse>(response);
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudJobScheduleListParameters, CloudJobScheduleListResponse>();
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
requestFilter = request.Parameters.DetailLevel.FilterClause;
requestSelect = request.Parameters.DetailLevel.SelectClause;
requestExpand = request.Parameters.DetailLevel.ExpandClause;

// Setup the cmdlet to write pipeline output to a list that can be examined later
List<PSCloudJobSchedule> pipeline = new List<PSCloudJobSchedule>();
commandRuntimeMock.Setup(r =>
r.WriteObject(It.IsAny<PSCloudJobSchedule>()))
.Callback<object>(j => pipeline.Add((PSCloudJobSchedule)j));
return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

cmdlet.ExecuteCmdlet();

// Verify that the cmdlet wrote the constructed job schedules to the pipeline
Assert.Equal(2, pipeline.Count);
int jobScheduleCount = 0;
foreach (PSCloudJobSchedule j in pipeline)
{
Assert.True(idsOfConstructedJobSchedules.Contains(j.Id));
jobScheduleCount++;
}
Assert.Equal(idsOfConstructedJobSchedules.Length, jobScheduleCount);
Assert.Equal(cmdlet.Filter, requestFilter);
Assert.Equal(cmdlet.Select, requestSelect);
Assert.Equal(cmdlet.Expand, requestExpand);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

Expand Down Expand Up @@ -71,39 +72,69 @@ public void GetBatchJobTest()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchJobsByODataFilterTest()
public void GetBatchJobODataTest()
{
// Setup cmdlet to list jobs using an OData filter. Use JobScheduleId input.
// Setup cmdlet to get a single job
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.JobScheduleId = "jobSchedule";
cmdlet.Id = null;
cmdlet.Filter = "state -eq 'active'";
cmdlet.Id = "testJob";
cmdlet.Select = "id,state";
cmdlet.Expand = "stats";

string[] idsOfConstructedJobs = new[] { "job-1", "job-2" };
string requestSelect = null;
string requestExpand = null;

// Build some CloudJobs instead of querying the service on a List CloudJobs call
CloudJobListResponse response = BatchTestHelpers.CreateCloudJobListResponse(idsOfConstructedJobs);
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudJobListParameters, CloudJobListResponse>(response);
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
CloudJobGetResponse getResponse = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id);
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudJobGetParameters, CloudJobGetResponse>(getResponse);
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
requestSelect = request.Parameters.DetailLevel.SelectClause;
requestExpand = request.Parameters.DetailLevel.ExpandClause;

// Setup the cmdlet to write pipeline output to a list that can be examined later
List<PSCloudJob> pipeline = new List<PSCloudJob>();
commandRuntimeMock.Setup(r =>
r.WriteObject(It.IsAny<PSCloudJob>()))
.Callback<object>(j => pipeline.Add((PSCloudJob)j));
return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

cmdlet.ExecuteCmdlet();

// Verify that the cmdlet wrote the constructed jobs to the pipeline
Assert.Equal(2, pipeline.Count);
int jobCount = 0;
foreach (PSCloudJob j in pipeline)
Assert.Equal(cmdlet.Select, requestSelect);
Assert.Equal(cmdlet.Expand, requestExpand);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchJobsODataTest()
{
// Setup cmdlet to list job using an OData filter
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Id = null;
cmdlet.Filter = "startswith(id,'test')";
cmdlet.Select = "id,state";
cmdlet.Expand = "stats";

string requestFilter = null;
string requestSelect = null;
string requestExpand = null;

// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudJobListParameters, CloudJobListResponse>();
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
Assert.True(idsOfConstructedJobs.Contains(j.Id));
jobCount++;
}
Assert.Equal(idsOfConstructedJobs.Length, jobCount);
requestFilter = request.Parameters.DetailLevel.FilterClause;
requestSelect = request.Parameters.DetailLevel.SelectClause;
requestExpand = request.Parameters.DetailLevel.ExpandClause;

return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

cmdlet.ExecuteCmdlet();

Assert.Equal(cmdlet.Filter, requestFilter);
Assert.Equal(cmdlet.Select, requestSelect);
Assert.Equal(cmdlet.Expand, requestExpand);
}

[Fact]
Expand Down
Loading