diff --git a/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/AccountTests.ScenarioTests.cs b/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/AccountTests.ScenarioTests.cs index c4ce09964033d..f58689563d195 100644 --- a/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/AccountTests.ScenarioTests.cs +++ b/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/AccountTests.ScenarioTests.cs @@ -33,10 +33,8 @@ public class AccountTests : BatchScenarioTestBase [Fact] public async Task BatchAccountEndToEndAsync() { - using (MockContext context = MockContext.Start(this.GetType().FullName)) + using (MockContext context = StartMockContextAndInitializeClients(this.GetType().FullName)) { - Initialize(context); - string resourceGroupName = TestUtilities.GenerateName(); string batchAccountName = TestUtilities.GenerateName(); ResourceGroup group = new ResourceGroup(this.Location); @@ -91,7 +89,14 @@ public async Task BatchAccountEndToEndAsync() } } // Verify account was deleted. A GET operation will return a 404 error and result in an exception - await Assert.ThrowsAsync(typeof(CloudException), () => this.BatchManagementClient.BatchAccount.GetAsync(resourceGroupName, batchAccountName)); + try + { + await this.BatchManagementClient.BatchAccount.GetAsync(resourceGroupName, batchAccountName); + } + catch (CloudException ex) + { + Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); + } } finally { diff --git a/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/BatchScenarioTestBase.cs b/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/BatchScenarioTestBase.cs index 09173862c58af..3fad27cd1d338 100644 --- a/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/BatchScenarioTestBase.cs +++ b/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/BatchScenarioTestBase.cs @@ -32,14 +32,26 @@ public class BatchScenarioTestBase : TestBase public string Location { get; private set; } - public void Initialize(MockContext context) + protected MockContext StartMockContextAndInitializeClients(string className, + // Automatically populates the methodName parameter with the calling method, which + // gets used to generate recorder file names. + [System.Runtime.CompilerServices.CallerMemberName] + string methodName = "") + { + MockContext context = MockContext.Start(className, methodName); + Initialize(context); + + return context; + } + + private void Initialize(MockContext context) { this.ResourceManagementClient = context.GetServiceClient(); this.BatchManagementClient = context.GetServiceClient(); Provider provider = this.ResourceManagementClient.Providers.Get("Microsoft.Batch"); IList locations = provider.ResourceTypes.Where((resType) => resType.ResourceType == "batchAccounts").First().Locations; - this.Location = locations.Count == 0 ? "westus" : locations.First(); + this.Location = locations.DefaultIfEmpty("westus").First(); } } } diff --git a/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/LocationTests.ScenarioTests.cs b/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/LocationTests.ScenarioTests.cs index ba8200f4cef39..1f9f05f6f75b7 100644 --- a/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/LocationTests.ScenarioTests.cs +++ b/src/ResourceManagement/Batch/Batch.Tests/ScenarioTests/LocationTests.ScenarioTests.cs @@ -30,9 +30,8 @@ public class LocationTests : BatchScenarioTestBase [Fact] public async Task GetLocationQuotasAsync() { - using (MockContext context = MockContext.Start(this.GetType().FullName)) + using (MockContext context = StartMockContextAndInitializeClients(this.GetType().FullName)) { - Initialize(context); BatchLocationQuota quotas = await this.BatchManagementClient.Location.GetQuotasAsync(this.Location); Assert.NotNull(quotas.AccountQuota);