Skip to content

Batch cmdlets #194

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 29 commits into from
Feb 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6aa12e3
WORK:3301271 - Data models for Batch cmdlets
Jan 23, 2015
134d229
WORK:3312195 - PSH - Get-AzureBatchWorkItem cmdlet and infrastructure
Jan 29, 2015
14cb583
Merge changes from upstream dev branch
Jan 30, 2015
f903d1f
Remove XUnit NuGet reference for now
Feb 5, 2015
a03fd92
Remove model generator tool
Feb 5, 2015
52a3942
Incorporate pull request feedback
Feb 5, 2015
c621d10
Incorporate pull request feedback
Feb 5, 2015
45ba099
Merge remote-tracking branch 'upstream/dev' into firstcmd
Feb 5, 2015
84a6a5a
Get pool and some initial job work
Feb 9, 2015
379a4a7
Merge latest changes
Feb 9, 2015
15f3fb7
Get-Job changes
Feb 11, 2015
79bcb5a
Merge remote-tracking branch 'upstream/dev' into firstcmd
Feb 11, 2015
fcbb0ce
Add scenario tests and incorporate PR feedback
Feb 19, 2015
326a4b5
Merge latest changes from Azure dev branch
Feb 19, 2015
675a566
Merge remote-tracking branch 'origin/firstcmd' into gets
Feb 19, 2015
5db5a98
Updates to get pool and get job cmdlets and unit tests
Feb 20, 2015
2586ec7
Comment tweak
Feb 20, 2015
789fafb
Merge remote-tracking branch 'upstream/dev' into firstcmd
Feb 20, 2015
2b60560
Merge remote-tracking branch 'origin/firstcmd' into gets
Feb 20, 2015
7def95a
Reorganize test helpers
Feb 20, 2015
b0bf867
Add unit tests
Feb 20, 2015
3d9201a
Get Task and unit tests
Feb 20, 2015
910c17b
Pool scenario tests
Feb 21, 2015
d689b14
Get Job scenario tests
Feb 23, 2015
ad83ab8
Get Task scenario tests
Feb 23, 2015
80d44a6
Merge remote-tracking branch 'upstream/dev' into gets
Feb 25, 2015
2b2a463
Update Azure Batch package reference which includes update to Storage…
Feb 25, 2015
fce43fb
Merge remote-tracking branch 'upstream/dev' into gets
Feb 27, 2015
46f09ae
Create data models for convenience client calls per feedback
Feb 27, 2015
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 @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Moq;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
Expand Down
231 changes: 230 additions & 1 deletion src/ResourceManager/Batch/Commands.Batch.Test/BatchTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,46 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Common;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.Entities;
using Microsoft.Azure.Commands.Batch.Models;
using Microsoft.Azure.Commands.Batch.Test.ScenarioTests;
using Microsoft.Azure.Management.Batch;
using Microsoft.Azure.Management.Batch.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
using Microsoft.WindowsAzure.Storage.Shared.Protocol;
using Xunit;
using JobExecutionEnvironment = Microsoft.Azure.Batch.Protocol.Entities.JobExecutionEnvironment;

namespace Microsoft.Azure.Commands.Batch.Test
{
/// <summary>
/// Helper methods for the Batch cmdlet tests
/// </summary>
public static class BatchTestHelpers
{
/// <summary>
/// Builds an AccountResource object using the specified parameters
/// </summary>
public static AccountResource CreateAccountResource(string accountName, string resourceGroupName, Hashtable[] tags = null)
{
string tenantUrlEnding = "batch-test.windows-int.net";
string endpoint = string.Format("{0}.{1}", accountName, tenantUrlEnding);
string subscription = "00000000-0000-0000-0000-000000000000";
string subscription = Guid.Empty.ToString();
string resourceGroup = resourceGroupName;

AccountResource resource = new AccountResource()
Expand All @@ -39,9 +65,27 @@ public static AccountResource CreateAccountResource(string accountName, string r
{
resource.Tags = Microsoft.Azure.Commands.Batch.Helpers.CreateTagDictionary(tags, true);
}

return resource;
}

/// <summary>
/// Builds a BatchAccountContext object with the keys set for testing
/// </summary>
public static BatchAccountContext CreateBatchContextWithKeys()
{
AccountResource resource = CreateAccountResource("account", "resourceGroup");
BatchAccountContext context = BatchAccountContext.ConvertAccountResourceToNewAccountContext(resource);
string dummyKey = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
SetProperty(context, "PrimaryAccountKey", dummyKey);
SetProperty(context, "SecondaryAccountKey", dummyKey);

return context;
}

/// <summary>
/// Verifies that two BatchAccountContext objects are equal
/// </summary>
public static void AssertBatchAccountContextsAreEqual(BatchAccountContext context1, BatchAccountContext context2)
{
if (context1 == null)
Expand All @@ -67,5 +111,190 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
Assert.Equal<string>(context1.TagsTable, context2.TagsTable);
Assert.Equal<string>(context1.TaskTenantUrl, context2.TaskTenantUrl);
}

/// <summary>
/// Builds a PSCloudWorkItem for testing
/// </summary>
public static PSCloudWorkItem CreatePSCloudWorkItem()
{
BatchAccountContext context = CreateBatchContextWithKeys();
using (IWorkItemManager wiManager = context.BatchOMClient.OpenWorkItemManager())
{
ICloudWorkItem workItem = wiManager.CreateWorkItem("testWorkItem");
return new PSCloudWorkItem(workItem);
}
}

/// <summary>
/// Builds a GetPoolResponse object
/// </summary>
public static GetPoolResponse CreateGetPoolResponse(string poolName)
{
GetPoolResponse response = new GetPoolResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

Pool pool = new Pool();
SetProperty(pool, "Name", poolName);

SetProperty(response, "Pool", pool);

return response;
}

/// <summary>
/// Builds a ListPoolsResponse object
/// </summary>
public static ListPoolsResponse CreateListPoolsResponse(IEnumerable<string> poolNames)
{
ListPoolsResponse response = new ListPoolsResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

List<Pool> pools = new List<Pool>();

foreach (string name in poolNames)
{
Pool pool = new Pool();
SetProperty(pool, "Name", name);
pools.Add(pool);
}

SetProperty(response, "Pools", pools);

return response;
}

/// <summary>
/// Builds a GetWorkItemResponse object
/// </summary>
public static GetWorkItemResponse CreateGetWorkItemResponse(string workItemName)
{
GetWorkItemResponse response = new GetWorkItemResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

JobExecutionEnvironment jee = new JobExecutionEnvironment();

WorkItem workItem = new WorkItem(workItemName, jee);
SetProperty(response, "WorkItem", workItem);

return response;
}

/// <summary>
/// Builds a ListWorkItemsResponse object
/// </summary>
public static ListWorkItemsResponse CreateListWorkItemsResponse(IEnumerable<string> workItemNames)
{
ListWorkItemsResponse response = new ListWorkItemsResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

List<WorkItem> workItems = new List<WorkItem>();
JobExecutionEnvironment jee = new JobExecutionEnvironment();

foreach (string name in workItemNames)
{
workItems.Add(new WorkItem(name, jee));
}

SetProperty(response, "WorkItems", workItems);

return response;
}

/// <summary>
/// Builds a GetJobResponse object
/// </summary>
public static GetJobResponse CreateGetJobResponse(string jobName)
{
GetJobResponse response = new GetJobResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

Job job = new Job();
SetProperty(job, "Name", jobName);

SetProperty(response, "Job", job);

return response;
}

/// <summary>
/// Builds a ListJobsResponse object
/// </summary>
public static ListJobsResponse CreateListJobsResponse(IEnumerable<string> jobNames)
{
ListJobsResponse response = new ListJobsResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

List<Job> jobs = new List<Job>();

foreach (string name in jobNames)
{
Job job = new Job();
SetProperty(job, "Name", name);
jobs.Add(job);
}

SetProperty(response, "Jobs", jobs);

return response;
}

/// <summary>
/// Builds a GetTaskResponse object
/// </summary>
public static GetTaskResponse CreateGetTaskResponse(string taskName)
{
GetTaskResponse response = new GetTaskResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

Azure.Batch.Protocol.Entities.Task task = new Azure.Batch.Protocol.Entities.Task();
SetProperty(task, "Name", taskName);

SetProperty(response, "Task", task);

return response;
}

/// <summary>
/// Builds a ListTasksResponse object
/// </summary>
public static ListTasksResponse CreateListTasksResponse(IEnumerable<string> taskNames)
{
ListTasksResponse response = new ListTasksResponse();
SetProperty(response, "StatusCode", HttpStatusCode.OK);

List<Azure.Batch.Protocol.Entities.Task> tasks = new List<Azure.Batch.Protocol.Entities.Task>();

foreach (string name in taskNames)
{
Azure.Batch.Protocol.Entities.Task task = new Azure.Batch.Protocol.Entities.Task();
SetProperty(task, "Name", name);
tasks.Add(task);
}

SetProperty(response, "Tasks", tasks);

return response;
}


/// <summary>
/// Uses Reflection to set a property value on an object. Can be used to bypass restricted set accessors.
/// </summary>
internal static void SetProperty(object obj, string propertyName, object propertyValue)
{
Type t = obj.GetType();
PropertyInfo propInfo = t.GetProperty(propertyName);
propInfo.SetValue(obj, propertyValue);
}

/// <summary>
/// Uses Reflection to set a property value on an object.
/// </summary>
internal static void SetField(object obj, string fieldName, object fieldValue)
{
Type t = obj.GetType();
FieldInfo fieldInfo = t.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(obj, fieldValue);
}
}
}
Loading