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 13, 2024
1 parent aa3634b commit b4323f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ protected static ArmDeploymentStackData CreateRGDeploymentStackDataWithTemplate(
return data;
}

protected static ArmDeploymentStackData CreateSubDeploymentStackDataWithTemplate(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 @@ -192,6 +193,8 @@ protected static ArmDeploymentStackData CreateMGDeploymentStackDataWithTemplate(
{
var data = new ArmDeploymentStackData();

data.Location = location;

data.Template = BinaryData.FromString(File.ReadAllText(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Scenario",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public async Task CreateOrUpdateRG()
ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS);
ResourceGroupResource rg = (await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData)).Value;

string deploymentStackName = Recording.GenerateAssetName("deployStackExRG-CreateOrUpdate-");
string deploymentStackName = Recording.GenerateAssetName("deployStackRG-CreateOrUpdate-");
var deploymentStackData = CreateRGDeploymentStackDataWithTemplate();
ArmDeploymentStackResource 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;

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

Expand All @@ -51,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 @@ -73,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 @@ -100,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 @@ -130,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 @@ -149,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 @@ -174,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 @@ -189,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 @@ -206,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,8 +73,7 @@ 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;
ArmDeploymentStackResource deploymentStack = (await subscription.GetArmDeploymentStacks().CreateOrUpdateAsync(WaitUntil.Completed, deploymentStackName, deploymentStackData)).Value;
await deploymentStack.DeleteAsync(WaitUntil.Completed);

var ex = Assert.ThrowsAsync<RequestFailedException>(async () => await deploymentStack.GetAsync());
Expand All @@ -88,11 +86,9 @@ public async Task ExportSub()
{
SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

string deploymentStackName = Recording.GenerateAssetName("deployStackSub-Export-");
string deploymentStackName = Recording.GenerateAssetName("deployStackEx-Export-");
var deploymentStackData = CreateSubDeploymentStackDataWithTemplate(AzureLocation.WestUS);
var deploymentStackCollection = Client.GetArmDeploymentStacks(new ResourceIdentifier(subscription.Id));

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

Expand All @@ -112,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 @@ -127,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 b4323f5

Please sign in to comment.