diff --git a/src/ResourceManager/Batch/Commands.Batch.Test/BatchTestHelpers.cs b/src/ResourceManager/Batch/Commands.Batch.Test/BatchTestHelpers.cs
index 8bf7040956d3..c01b9dd2415a 100644
--- a/src/ResourceManager/Batch/Commands.Batch.Test/BatchTestHelpers.cs
+++ b/src/ResourceManager/Batch/Commands.Batch.Test/BatchTestHelpers.cs
@@ -12,15 +12,23 @@
// limitations under the License.
// ----------------------------------------------------------------------------------
+using System.Net;
+using Microsoft.Azure.Batch.Protocol;
+using Microsoft.Azure.Batch.Protocol.Entities;
using Microsoft.Azure.Management.Batch.Models;
+using System;
using System.Collections;
using System.Collections.Generic;
+using System.Reflection;
using Xunit;
namespace Microsoft.Azure.Commands.Batch.Test
{
public static class BatchTestHelpers
{
+ ///
+ /// Builds an AccountResource object using the specified parameters
+ ///
public static AccountResource CreateAccountResource(string accountName, string resourceGroupName, Hashtable[] tags = null)
{
string tenantUrlEnding = "batch-test.windows-int.net";
@@ -39,9 +47,28 @@ public static AccountResource CreateAccountResource(string accountName, string r
{
resource.Tags = Microsoft.Azure.Commands.Batch.Helpers.CreateTagDictionary(tags, true);
}
+
return resource;
}
+ ///
+ /// Builds a BatchAccountContext object with the keys set for testing
+ ///
+ 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;
+ }
+
+
+ ///
+ /// Verifies that two BatchAccountContext objects are equal
+ ///
public static void AssertBatchAccountContextsAreEqual(BatchAccountContext context1, BatchAccountContext context2)
{
if (context1 == null)
@@ -67,5 +94,52 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
Assert.Equal(context1.TagsTable, context2.TagsTable);
Assert.Equal(context1.TaskTenantUrl, context2.TaskTenantUrl);
}
+
+ ///
+ /// Builds a GetWorkItemResponse object
+ ///
+ 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;
+ }
+
+ ///
+ /// Builds a ListWorkItemsResponse object
+ ///
+ public static ListWorkItemsResponse CreateListWorkItemsResponse(IEnumerable workItemNames)
+ {
+ ListWorkItemsResponse response = new ListWorkItemsResponse();
+ SetProperty(response, "StatusCode", HttpStatusCode.OK);
+
+ List workItems = new List();
+ JobExecutionEnvironment jee = new JobExecutionEnvironment();
+
+ foreach (string name in workItemNames)
+ {
+ workItems.Add(new WorkItem(name, jee));
+ }
+
+ SetProperty(response, "WorkItems", workItems);
+
+ return response;
+ }
+
+ ///
+ /// Uses Reflection to set a property value on an object. Can be used to bypass restricted set accessors.
+ ///
+ private static void SetProperty(object obj, string propertyName, object propertyValue)
+ {
+ Type t = obj.GetType();
+ PropertyInfo propInfo = t.GetProperty(propertyName);
+ propInfo.SetValue(obj, propertyValue);
+ }
}
}
diff --git a/src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj b/src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj
index 38901382309c..5e571e467422 100644
--- a/src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj
+++ b/src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj
@@ -14,6 +14,7 @@
..\
true
+ 49379715
true
@@ -38,6 +39,10 @@
false
+
+ False
+ ..\..\..\packages\Azure.Batch.1.1.0\lib\net45\Microsoft.Azure.Batch.dll
+
..\..\..\packages\Hyak.Common.1.0.1\lib\portable-net403+win+wpa81\Hyak.Common.dll
@@ -72,6 +77,12 @@
False
..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5486.28526-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll
+
+ ..\..\..\packages\Microsoft.Data.Edm.5.6.0\lib\net40\Microsoft.Data.Edm.dll
+
+
+ ..\..\..\packages\Microsoft.Data.OData.5.6.0\lib\net40\Microsoft.Data.OData.dll
+
False
..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.11.10918.1222\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll
@@ -80,6 +91,17 @@
False
..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.11.10918.1222\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll
+
+ ..\..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll
+
+
+ False
+ ..\..\..\packages\WindowsAzure.Storage.2.1.0.4\lib\net40\Microsoft.WindowsAzure.Storage.dll
+
+
+ False
+ ..\..\..\packages\Hydra.SpecTestSupport.1.0.5417.13285-prerelease\lib\net45\Microsoft.WindowsAzure.Testing.dll
+
False
..\..\..\packages\Microsoft.WindowsAzure.Management.4.0.1\lib\net40\Microsoft.WindowsAzure.Management.dll
@@ -87,9 +109,15 @@
..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll
+
+ False
+ ..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll
+
+
+
False
D:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
@@ -105,9 +133,11 @@
..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll
-
- ..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll
+
+ ..\..\..\packages\System.Spatial.5.6.0\lib\net40\System.Spatial.dll
+
+
False
..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
@@ -125,6 +155,7 @@
+
@@ -180,6 +211,9 @@
+
+
+
diff --git a/src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/BatchController.cs b/src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/BatchController.cs
index fb3848dee18d..b9547d814413 100644
--- a/src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/BatchController.cs
+++ b/src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/BatchController.cs
@@ -19,8 +19,6 @@
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Test;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
-using Microsoft.WindowsAzure.Commands.Utilities.Common;
-using Microsoft.Azure.Test;
using System;
using System.Linq;
diff --git a/src/ResourceManager/Batch/Commands.Batch.Test/WorkItems/GetBatchWorkItemCommandTests.cs b/src/ResourceManager/Batch/Commands.Batch.Test/WorkItems/GetBatchWorkItemCommandTests.cs
new file mode 100644
index 000000000000..97e8daa3f156
--- /dev/null
+++ b/src/ResourceManager/Batch/Commands.Batch.Test/WorkItems/GetBatchWorkItemCommandTests.cs
@@ -0,0 +1,168 @@
+// ----------------------------------------------------------------------------------
+//
+// Copyright Microsoft Corporation
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------------
+
+using Microsoft.Azure.Batch;
+using Microsoft.Azure.Batch.Protocol;
+using Microsoft.Azure.Batch.Protocol.Entities;
+using Microsoft.Azure.Commands.Batch.Models;
+using Microsoft.WindowsAzure.Commands.ScenarioTest;
+using Moq;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management.Automation;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Azure.Commands.Batch.Test.WorkItems
+{
+ public class GetBatchWorkItemCommandTests
+ {
+ private GetBatchWorkItemCommand cmdlet;
+ private Mock batchClientMock;
+ private Mock commandRuntimeMock;
+
+ public GetBatchWorkItemCommandTests()
+ {
+ batchClientMock = new Mock();
+ commandRuntimeMock = new Mock();
+ cmdlet = new GetBatchWorkItemCommand()
+ {
+ CommandRuntime = commandRuntimeMock.Object,
+ BatchClient = batchClientMock.Object,
+ };
+ }
+
+ [Fact]
+ [Trait(Category.AcceptanceType, Category.CheckIn)]
+ public void GetBatchWorkItemTest()
+ {
+ // Setup cmdlet to get a WorkItem by name
+ BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
+ cmdlet.BatchContext = context;
+ cmdlet.Name = "testWorkItem";
+ cmdlet.Filter = null;
+
+ // Build a WorkItem instead of querying the service on a GetWorkItem call
+ YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
+ {
+ if (request is GetWorkItemRequest)
+ {
+ GetWorkItemResponse response = BatchTestHelpers.CreateGetWorkItemResponse(cmdlet.Name);
+ Task