|
| 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.Commands.Batch.Models; |
| 18 | +using Microsoft.Azure.Test; |
| 19 | +using Microsoft.WindowsAzure.Commands.ScenarioTest; |
| 20 | +using System.Collections.Generic; |
| 21 | +using System.Management.Automation; |
| 22 | +using Xunit; |
| 23 | +using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants; |
| 24 | + |
| 25 | +namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests |
| 26 | +{ |
| 27 | + public class TaskTests |
| 28 | + { |
| 29 | + [Fact] |
| 30 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 31 | + public void TestGetTaskRequiredParameters() |
| 32 | + { |
| 33 | + BatchController controller = BatchController.NewInstance; |
| 34 | + string resourceGroupName = "test-get-task-params"; |
| 35 | + string accountName = "testgettaskparams"; |
| 36 | + string location = "eastus"; |
| 37 | + BatchAccountContext context = null; |
| 38 | + controller.RunPsTestWorkflow( |
| 39 | + () => { return new string[] { string.Format("Test-GetTaskRequiredParameters '{0}'", accountName) }; }, |
| 40 | + () => |
| 41 | + { |
| 42 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 43 | + }, |
| 44 | + () => |
| 45 | + { |
| 46 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 47 | + }, |
| 48 | + TestUtilities.GetCallingClass(), |
| 49 | + TestUtilities.GetCurrentMethodName()); |
| 50 | + } |
| 51 | + |
| 52 | + [Fact] |
| 53 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 54 | + public void TestGetTaskByName() |
| 55 | + { |
| 56 | + BatchController controller = BatchController.NewInstance; |
| 57 | + string resourceGroupName = "test-get-task"; |
| 58 | + string accountName = "testgettaskbyname"; |
| 59 | + string location = "eastus"; |
| 60 | + string workItemName = "testName"; |
| 61 | + string jobName = null; |
| 62 | + string taskName = "testTask"; |
| 63 | + BatchAccountContext context = null; |
| 64 | + controller.RunPsTestWorkflow( |
| 65 | + () => { return new string[] { string.Format("Test-GetTaskByName '{0}' '{1}' '{2}' '{3}'", accountName, workItemName, jobName, taskName) }; }, |
| 66 | + () => |
| 67 | + { |
| 68 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 69 | + ScenarioTestHelpers.CreateTestWorkItem(context, workItemName); |
| 70 | + jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName); |
| 71 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName); |
| 72 | + }, |
| 73 | + () => |
| 74 | + { |
| 75 | + ScenarioTestHelpers.DeleteWorkItem(context, workItemName); |
| 76 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 77 | + }, |
| 78 | + TestUtilities.GetCallingClass(), |
| 79 | + TestUtilities.GetCurrentMethodName()); |
| 80 | + } |
| 81 | + |
| 82 | + [Fact] |
| 83 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 84 | + public void TestListTasksByFilter() |
| 85 | + { |
| 86 | + BatchController controller = BatchController.NewInstance; |
| 87 | + string resourceGroupName = "test-list-task-filter"; |
| 88 | + string accountName = "testlisttaskfilter"; |
| 89 | + string location = "eastus"; |
| 90 | + string workItemName = "testWorkItem"; |
| 91 | + string jobName = null; |
| 92 | + string taskName1 = "testTask1"; |
| 93 | + string taskName2 = "testTask2"; |
| 94 | + string taskName3 = "thirdTestTask"; |
| 95 | + string taskPrefix = "testTask"; |
| 96 | + int matches = 2; |
| 97 | + BatchAccountContext context = null; |
| 98 | + controller.RunPsTestWorkflow( |
| 99 | + () => { return new string[] { string.Format("Test-ListTasksByFilter '{0}' '{1}' '{2}' '{3}' '{4}'", accountName, workItemName, jobName, taskPrefix, matches) }; }, |
| 100 | + () => |
| 101 | + { |
| 102 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 103 | + ScenarioTestHelpers.CreateTestWorkItem(context, workItemName); |
| 104 | + jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName); |
| 105 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName1); |
| 106 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName2); |
| 107 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName3); |
| 108 | + }, |
| 109 | + () => |
| 110 | + { |
| 111 | + ScenarioTestHelpers.DeleteWorkItem(context, workItemName); |
| 112 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 113 | + }, |
| 114 | + TestUtilities.GetCallingClass(), |
| 115 | + TestUtilities.GetCurrentMethodName()); |
| 116 | + } |
| 117 | + |
| 118 | + [Fact] |
| 119 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 120 | + public void TestListTasksWithMaxCount() |
| 121 | + { |
| 122 | + BatchController controller = BatchController.NewInstance; |
| 123 | + string resourceGroupName = "test-list-task-maxcount"; |
| 124 | + string accountName = "testlisttaskmaxcount"; |
| 125 | + string location = "eastus"; |
| 126 | + string workItemName = "testWorkItem"; |
| 127 | + string jobName = null; |
| 128 | + string taskName1 = "testTask1"; |
| 129 | + string taskName2 = "testTask2"; |
| 130 | + string taskName3 = "testTask3"; |
| 131 | + int maxCount = 1; |
| 132 | + BatchAccountContext context = null; |
| 133 | + controller.RunPsTestWorkflow( |
| 134 | + () => { return new string[] { string.Format("Test-ListTasksWithMaxCount '{0}' '{1}' '{2}' '{3}'", accountName, workItemName, jobName, maxCount) }; }, |
| 135 | + () => |
| 136 | + { |
| 137 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 138 | + ScenarioTestHelpers.CreateTestWorkItem(context, workItemName); |
| 139 | + jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName); |
| 140 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName1); |
| 141 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName2); |
| 142 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName3); |
| 143 | + }, |
| 144 | + () => |
| 145 | + { |
| 146 | + ScenarioTestHelpers.DeleteWorkItem(context, workItemName); |
| 147 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 148 | + }, |
| 149 | + TestUtilities.GetCallingClass(), |
| 150 | + TestUtilities.GetCurrentMethodName()); |
| 151 | + } |
| 152 | + |
| 153 | + [Fact] |
| 154 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 155 | + public void TestListAllTasks() |
| 156 | + { |
| 157 | + BatchController controller = BatchController.NewInstance; |
| 158 | + string resourceGroupName = "test-list-task"; |
| 159 | + string accountName = "testlisttask"; |
| 160 | + string location = "eastus"; |
| 161 | + string workItemName = "testWorkItem"; |
| 162 | + string jobName = null; |
| 163 | + string taskName1 = "testTask1"; |
| 164 | + string taskName2 = "testTask2"; |
| 165 | + string taskName3 = "testTask3"; |
| 166 | + int count = 3; |
| 167 | + BatchAccountContext context = null; |
| 168 | + controller.RunPsTestWorkflow( |
| 169 | + () => { return new string[] { string.Format("Test-ListAllTasks '{0}' '{1}' '{2}' '{3}'", accountName, workItemName, jobName, count) }; }, |
| 170 | + () => |
| 171 | + { |
| 172 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 173 | + ScenarioTestHelpers.CreateTestWorkItem(context, workItemName); |
| 174 | + jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName); |
| 175 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName1); |
| 176 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName2); |
| 177 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName3); |
| 178 | + }, |
| 179 | + () => |
| 180 | + { |
| 181 | + ScenarioTestHelpers.DeleteWorkItem(context, workItemName); |
| 182 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 183 | + }, |
| 184 | + TestUtilities.GetCallingClass(), |
| 185 | + TestUtilities.GetCurrentMethodName()); |
| 186 | + } |
| 187 | + |
| 188 | + [Fact] |
| 189 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 190 | + public void TestListTaskPipeline() |
| 191 | + { |
| 192 | + BatchController controller = BatchController.NewInstance; |
| 193 | + string resourceGroupName = "test-list-task-pipe"; |
| 194 | + string accountName = "testlisttaskpipe"; |
| 195 | + string location = "eastus"; |
| 196 | + string workItemName = "testWorkItem"; |
| 197 | + string jobName = null; |
| 198 | + string taskName = "testTask"; |
| 199 | + BatchAccountContext context = null; |
| 200 | + controller.RunPsTestWorkflow( |
| 201 | + () => { return new string[] { string.Format("Test-ListTaskPipeline '{0}' '{1}' '{2}' '{3}'", accountName, workItemName, jobName, taskName) }; }, |
| 202 | + () => |
| 203 | + { |
| 204 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 205 | + ScenarioTestHelpers.CreateTestWorkItem(context, workItemName); |
| 206 | + jobName = ScenarioTestHelpers.WaitForRecentJob(controller, context, workItemName); |
| 207 | + ScenarioTestHelpers.CreateTestTask(context, workItemName, jobName, taskName); |
| 208 | + }, |
| 209 | + () => |
| 210 | + { |
| 211 | + ScenarioTestHelpers.DeleteWorkItem(context, workItemName); |
| 212 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 213 | + }, |
| 214 | + TestUtilities.GetCallingClass(), |
| 215 | + TestUtilities.GetCurrentMethodName()); |
| 216 | + } |
| 217 | + |
| 218 | + } |
| 219 | + |
| 220 | + // Cmdlets that use the HTTP Recorder interceptor for use with scenario tests |
| 221 | + [Cmdlet(VerbsCommon.Get, "AzureBatchTask_ST", DefaultParameterSetName = Constants.ODataFilterParameterSet)] |
| 222 | + public class GetBatchTaskScenarioTestCommand : GetBatchTaskCommand |
| 223 | + { |
| 224 | + public override void ExecuteCmdlet() |
| 225 | + { |
| 226 | + AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() }; |
| 227 | + base.ExecuteCmdlet(); |
| 228 | + } |
| 229 | + } |
| 230 | +} |
0 commit comments