Skip to content

Commit

Permalink
update tests with generation changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dantedallag committed Jun 7, 2024
1 parent 251f98f commit a7f9e7a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ protected static ArmDeploymentStackData CreateRGDeploymentStackDataWithTemplate(
return data;
}

protected static ArmDeploymentStackData CreateDeploymentStackDataWithTemplate(AzureLocation location) {
protected static ArmDeploymentStackData CreateSubDeploymentStackDataWithTemplate(AzureLocation location) {
var data = new ArmDeploymentStackData();

data.Location = location;

data.Template = BinaryData.FromString(File.ReadAllText(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Scenario",
Expand All @@ -189,7 +191,9 @@ protected static ArmDeploymentStackData CreateDeploymentStackDataWithTemplate(Az

protected static ArmDeploymentStackData CreateMGDeploymentStackDataWithTemplate(AzureLocation location)
{
var data = new ArmDeploymentStackData(location);
var data = new ArmDeploymentStackData();

data.Location = location;

data.Template = BinaryData.FromString(File.ReadAllText(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ public DeploymentStackCollectionTests(bool isAsync)
public async Task CreateOrUpdateRG()
{
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();
string deploymentStackName = Recording.GenerateAssetName("deployStackEx-CreateOrUpdate-");
var deploymentStackData = CreateDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed ,deploymentStackName, deploymentStackData)).Value;

string rgName = Recording.GenerateAssetName("testRg-1-");
ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS);
ResourceGroupResource rg = (await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData)).Value;

string deploymentStackName = Recording.GenerateAssetName("deployStackRG-CreateOrUpdate-");
var deploymentStackData = CreateRGDeploymentStackDataWithTemplate();
var deploymentStack = (await rg.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed ,deploymentStackName, deploymentStackData)).Value;

Assert.AreEqual(deploymentStackName, deploymentStack.Data.Name);

Expand All @@ -46,9 +51,9 @@ public async Task GetRG()

string deploymentStackName = Recording.GenerateAssetName("deployStackRG-Get-");
var deploymentStackData = CreateRGDeploymentStackDataWithTemplate();
var deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(rg.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
var deploymentStack = (await rg.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

var deploymentStackGet = (await Client.GetArmDeploymentStackAsync(new ResourceIdentifier(rg.Id), deploymentStackName)).Value;
var deploymentStackGet = (await rg.GetArmDeploymentStackAsync(deploymentStackName)).Value;

AssertValidDeploymentStack(deploymentStack, deploymentStackGet);

Expand All @@ -68,14 +73,9 @@ public async Task ListRG()

string deploymentStackName = Recording.GenerateAssetName("deployStackRG-List-");
var deploymentStackData = CreateRGDeploymentStackDataWithTemplate();
_ = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(rg.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
_ = (await rg.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

var deploymentStacks = Client.GetArmDeploymentStacks(new ResourceIdentifier(rg.Id));
string deploymentStackName = Recording.GenerateAssetName("deployStackEx-List-");
var deploymentStackData = CreateDeploymentStackDataWithTemplate(AzureLocation.WestUS);
_ = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed ,deploymentStackName, deploymentStackData)).Value;

var deploymentStacks = subscription.GetArmDeploymentStacks();
var deploymentStacks = rg.GetArmDeploymentStacks();
int count = 0;
await foreach (var deploymentStack in deploymentStacks)
{
Expand All @@ -95,24 +95,9 @@ public async Task CreateOrUpdateSub()
{
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

string deploymentStackName = Recording.GenerateAssetName("deployStackEx-CreateOrUpdate-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

Assert.AreEqual(deploymentStackName, deploymentStack.Data.Name);

await deploymentStack.DeleteAsync(WaitUntil.Completed, unmanageActionResources: UnmanageActionResourceMode.Delete, unmanageActionResourceGroups: UnmanageActionResourceGroupMode.Delete, unmanageActionManagementGroups: UnmanageActionManagementGroupMode.Delete);
}

[TestCase]
[RecordedTest]
public async Task ValidateSub()
{
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

string deploymentStackName = Recording.GenerateAssetName("deployStackEx-CreateOrUpdate-");
string deploymentStackName = Recording.GenerateAssetName("deployStackSub-CreateOrUpdate-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
ArmDeploymentStackResource deploymentStack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

Assert.AreEqual(deploymentStackName, deploymentStack.Data.Name);

Expand All @@ -125,8 +110,8 @@ public async Task GetSub()
{
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

string deploymentStackName = Recording.GenerateAssetName("deployStackEx-Get-");
var deploymentStackData = CreateDeploymentStackDataWithTemplate(AzureLocation.WestUS);
string deploymentStackName = Recording.GenerateAssetName("deployStackSub-Get-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);
var deploymentStack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

var deploymentStackGet = (await subscription.GetArmDeploymentStackAsync(deploymentStackName)).Value;
Expand All @@ -144,9 +129,9 @@ public async Task ListSub()

string deploymentStackName = Recording.GenerateAssetName("deployStackSub-List-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);
var stack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
var stack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

var deploymentStacks = Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id));
var deploymentStacks = subscription.GetArmDeploymentStacks();
int count = 0;
await foreach (var deploymentStack in deploymentStacks)
{
Expand All @@ -169,7 +154,7 @@ public async Task CreateOrUpdateMG()

string deploymentStackName = Recording.GenerateAssetName("deployStackExMG-CreateOrUpdate-");
var deploymentStackData = CreateMGDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(managementGroup.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
ArmDeploymentStackResource deploymentStack = (await managementGroup.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

Assert.AreEqual(deploymentStackName, deploymentStack.Data.Name);

Expand All @@ -184,9 +169,9 @@ public async Task GetMG()

string deploymentStackName = Recording.GenerateAssetName("deployStackMG-Get-");
var deploymentStackData = CreateMGDeploymentStackDataWithTemplate(AzureLocation.WestUS);
var deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(managementGroup.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
var deploymentStack = (await managementGroup.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

var deploymentStackGet = (await Client.GetArmDeploymentStackAsync(new ResourceIdentifier(managementGroup.Id), deploymentStackName)).Value;
var deploymentStackGet = (await managementGroup.GetArmDeploymentStackAsync(deploymentStackName)).Value;

AssertValidDeploymentStack(deploymentStack, deploymentStackGet);

Expand All @@ -201,9 +186,9 @@ public async Task ListMG()

string deploymentStackName = Recording.GenerateAssetName("deployStackExMG-List-");
var deploymentStackData = CreateMGDeploymentStackDataWithTemplate(AzureLocation.WestUS);
_ = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(managementGroup.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
_ = (await managementGroup.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;

var deploymentStacks = Client.GetArmDeploymentStacks(new ResourceIdentifier(managementGroup.Id));
var deploymentStacks = managementGroup.GetArmDeploymentStacks();
int count = 0;
await foreach (var deploymentStack in deploymentStacks)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task DeleteRG()

string deploymentStackName = Recording.GenerateAssetName("deployStackRG-Delete-");
var deploymentStackData = CreateRGDeploymentStackDataWithTemplate();
ArmDeploymentStackResource deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(rg.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
ArmDeploymentStackResource deploymentStack = (await rg.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
await deploymentStack.DeleteAsync(WaitUntil.Completed);

var ex = Assert.ThrowsAsync<RequestFailedException>(async () => await deploymentStack.GetAsync());
Expand All @@ -51,10 +51,9 @@ public async Task ExportRG()

string deploymentStackName = Recording.GenerateAssetName("deployStackRG-Export-");
var deploymentStackData = CreateRGDeploymentStackDataWithTemplate();
var deploymentStackCollection = Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id));

ArmDeploymentStackResource deploymentStack = (await deploymentStackCollection.CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
ArmDeploymentStackResource deploymentStack = (await rg.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
var deploymentStackTemplate = (await deploymentStack.ExportTemplateAsync()).Value;

Assert.IsNotNull(deploymentStackTemplate);

// TODO: Output is off by a little and may be how the template is being read.
Expand All @@ -74,10 +73,6 @@ public async Task DeleteSub()

string deploymentStackName = Recording.GenerateAssetName("deployStackSub-Delete-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);

ArmDeploymentStackResource deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
string deploymentStackName = Recording.GenerateAssetName("deployStackEx-Delete-");
var deploymentStackData = CreateDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
await deploymentStack.DeleteAsync(WaitUntil.Completed);

Expand All @@ -90,11 +85,10 @@ public async Task DeleteSub()
public async Task ExportSub()
{
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();
string deploymentStackName = Recording.GenerateAssetName("deployStackEx-Export-");
var deploymentStackData = CreateDeploymentStackDataWithTemplate(AzureLocation.WestUS);
var deploymentStackCollection = subscription.GetArmDeploymentStacks();

ArmDeploymentStackResource deploymentStack = (await deploymentStackCollection.CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
string deploymentStackName = Recording.GenerateAssetName("deployStackEx-Export-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
var deploymentStackTemplate = (await deploymentStack.ExportTemplateAsync()).Value;
Assert.IsNotNull(deploymentStackTemplate);

Expand All @@ -114,7 +108,7 @@ public async Task DeleteMG()

string deploymentStackName = Recording.GenerateAssetName("deployStackMG-Delete-");
var deploymentStackData = CreateMGDeploymentStackDataWithTemplate(AzureLocation.WestUS);
ArmDeploymentStackResource deploymentStack = (await Client.GetArmDeploymentStacks(new ResourceIdentifier(managementGroup.Id)).CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
ArmDeploymentStackResource deploymentStack = (await managementGroup.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
await deploymentStack.DeleteAsync(WaitUntil.Completed);

var ex = Assert.ThrowsAsync<RequestFailedException>(async () => await deploymentStack.GetAsync());
Expand All @@ -129,9 +123,7 @@ public async Task ExportMG()

string deploymentStackName = Recording.GenerateAssetName("deployStackMG-Export-");
var deploymentStackData = CreateMGDeploymentStackDataWithTemplate(AzureLocation.WestUS);
var deploymentStackCollection = Client.GetArmDeploymentStacks(new ResourceIdentifier(managementGroup.Id));

ArmDeploymentStackResource deploymentStack = (await deploymentStackCollection.CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
ArmDeploymentStackResource deploymentStack = (await managementGroup.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
var deploymentStackTemplate = (await deploymentStack.ExportTemplateAsync()).Value;
Assert.IsNotNull(deploymentStackTemplate);

Expand Down

0 comments on commit a7f9e7a

Please sign in to comment.