|
| 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 Microsoft.Azure.Batch; |
| 16 | +using Microsoft.Azure.Test; |
| 17 | +using Microsoft.WindowsAzure.Commands.ScenarioTest; |
| 18 | +using System.Collections.Generic; |
| 19 | +using System.Management.Automation; |
| 20 | +using Xunit; |
| 21 | +using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants; |
| 22 | + |
| 23 | +namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests |
| 24 | +{ |
| 25 | + public class PoolTests |
| 26 | + { |
| 27 | + [Fact] |
| 28 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 29 | + public void TestGetPoolByName() |
| 30 | + { |
| 31 | + BatchController controller = BatchController.NewInstance; |
| 32 | + string resourceGroupName = "test-get-pool"; |
| 33 | + string accountName = "testgetpool"; |
| 34 | + string location = "eastus"; |
| 35 | + string poolName = "testName"; |
| 36 | + BatchAccountContext context = null; |
| 37 | + controller.RunPsTestWorkflow( |
| 38 | + () => { return new string[] { string.Format("Test-GetPoolByName '{0}' '{1}'", accountName, poolName) }; }, |
| 39 | + () => |
| 40 | + { |
| 41 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 42 | + ScenarioTestHelpers.CreateTestPool(context, poolName); |
| 43 | + }, |
| 44 | + () => |
| 45 | + { |
| 46 | + ScenarioTestHelpers.DeletePool(context, poolName); |
| 47 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 48 | + }, |
| 49 | + TestUtilities.GetCallingClass(), |
| 50 | + TestUtilities.GetCurrentMethodName()); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 55 | + public void TestListPoolsByFilter() |
| 56 | + { |
| 57 | + BatchController controller = BatchController.NewInstance; |
| 58 | + string resourceGroupName = "test-list-pool-filter"; |
| 59 | + string accountName = "testlistpoolfilter"; |
| 60 | + string location = "eastus"; |
| 61 | + string poolName1 = "testName1"; |
| 62 | + string poolName2 = "testName2"; |
| 63 | + string poolName3 = "thirdtestName"; |
| 64 | + string poolPrefix = "testName"; |
| 65 | + int matches = 2; |
| 66 | + BatchAccountContext context = null; |
| 67 | + controller.RunPsTestWorkflow( |
| 68 | + () => { return new string[] { string.Format("Test-ListPoolsByFilter '{0}' '{1}' '{2}'", accountName, poolPrefix, matches) }; }, |
| 69 | + () => |
| 70 | + { |
| 71 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 72 | + ScenarioTestHelpers.CreateTestPool(context, poolName1); |
| 73 | + ScenarioTestHelpers.CreateTestPool(context, poolName2); |
| 74 | + ScenarioTestHelpers.CreateTestPool(context, poolName3); |
| 75 | + }, |
| 76 | + () => |
| 77 | + { |
| 78 | + ScenarioTestHelpers.DeletePool(context, poolName1); |
| 79 | + ScenarioTestHelpers.DeletePool(context, poolName2); |
| 80 | + ScenarioTestHelpers.DeletePool(context, poolName3); |
| 81 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 82 | + }, |
| 83 | + TestUtilities.GetCallingClass(), |
| 84 | + TestUtilities.GetCurrentMethodName()); |
| 85 | + } |
| 86 | + |
| 87 | + [Fact] |
| 88 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 89 | + public void TestListPoolsWithMaxCount() |
| 90 | + { |
| 91 | + BatchController controller = BatchController.NewInstance; |
| 92 | + string resourceGroupName = "test-list-pool-maxcount"; |
| 93 | + string accountName = "testlistpoolmaxcount"; |
| 94 | + string location = "eastus"; |
| 95 | + string poolName1 = "testName1"; |
| 96 | + string poolName2 = "testName2"; |
| 97 | + string poolName3 = "thirdtestName"; |
| 98 | + int maxCount = 1; |
| 99 | + BatchAccountContext context = null; |
| 100 | + controller.RunPsTestWorkflow( |
| 101 | + () => { return new string[] { string.Format("Test-ListPoolsWithMaxCount '{0}' '{1}'", accountName, maxCount) }; }, |
| 102 | + () => |
| 103 | + { |
| 104 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 105 | + ScenarioTestHelpers.CreateTestPool(context, poolName1); |
| 106 | + ScenarioTestHelpers.CreateTestPool(context, poolName2); |
| 107 | + ScenarioTestHelpers.CreateTestPool(context, poolName3); |
| 108 | + }, |
| 109 | + () => |
| 110 | + { |
| 111 | + ScenarioTestHelpers.DeletePool(context, poolName1); |
| 112 | + ScenarioTestHelpers.DeletePool(context, poolName2); |
| 113 | + ScenarioTestHelpers.DeletePool(context, poolName3); |
| 114 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 115 | + }, |
| 116 | + TestUtilities.GetCallingClass(), |
| 117 | + TestUtilities.GetCurrentMethodName()); |
| 118 | + } |
| 119 | + |
| 120 | + [Fact] |
| 121 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 122 | + public void TestListAllPools() |
| 123 | + { |
| 124 | + BatchController controller = BatchController.NewInstance; |
| 125 | + string resourceGroupName = "test-list-pool"; |
| 126 | + string accountName = "testlistpool"; |
| 127 | + string location = "eastus"; |
| 128 | + string poolName1 = "testName1"; |
| 129 | + string poolName2 = "testName2"; |
| 130 | + string poolName3 = "thirdtestName"; |
| 131 | + int count = 3; |
| 132 | + BatchAccountContext context = null; |
| 133 | + controller.RunPsTestWorkflow( |
| 134 | + () => { return new string[] { string.Format("Test-ListAllPools '{0}' '{1}'", accountName, count) }; }, |
| 135 | + () => |
| 136 | + { |
| 137 | + context = ScenarioTestHelpers.CreateTestAccountAndResourceGroup(controller, resourceGroupName, accountName, location); |
| 138 | + ScenarioTestHelpers.CreateTestPool(context, poolName1); |
| 139 | + ScenarioTestHelpers.CreateTestPool(context, poolName2); |
| 140 | + ScenarioTestHelpers.CreateTestPool(context, poolName3); |
| 141 | + }, |
| 142 | + () => |
| 143 | + { |
| 144 | + ScenarioTestHelpers.DeletePool(context, poolName1); |
| 145 | + ScenarioTestHelpers.DeletePool(context, poolName2); |
| 146 | + ScenarioTestHelpers.DeletePool(context, poolName3); |
| 147 | + ScenarioTestHelpers.CleanupTestAccount(controller, resourceGroupName, accountName); |
| 148 | + }, |
| 149 | + TestUtilities.GetCallingClass(), |
| 150 | + TestUtilities.GetCurrentMethodName()); |
| 151 | + } |
| 152 | + |
| 153 | + } |
| 154 | + |
| 155 | + // Cmdlets that use the HTTP Recorder interceptor for use with scenario tests |
| 156 | + [Cmdlet(VerbsCommon.Get, "AzureBatchPool_ST", DefaultParameterSetName = Constants.ODataFilterParameterSet)] |
| 157 | + public class GetBatchPoolScenarioTestCommand : GetBatchPoolCommand |
| 158 | + { |
| 159 | + public override void ExecuteCmdlet() |
| 160 | + { |
| 161 | + AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() }; |
| 162 | + base.ExecuteCmdlet(); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
0 commit comments