Skip to content

Commit

Permalink
Refactor test code per review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-schneider committed Dec 1, 2016
1 parent 7e40657 commit b35b02f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceManagementClient>();
this.BatchManagementClient = context.GetServiceClient<BatchManagementClient>();

Provider provider = this.ResourceManagementClient.Providers.Get("Microsoft.Batch");
IList<string> locations = provider.ResourceTypes.Where((resType) => resType.ResourceType == "batchAccounts").First().Locations;
this.Location = locations.Count == 0 ? "westus" : locations.First();
this.Location = locations.DefaultIfEmpty("westus").First();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b35b02f

Please sign in to comment.