From b4323f5428e7086f37d9df1cca49323858983c58 Mon Sep 17 00:00:00 2001 From: Dante Dalla Gasperina Date: Fri, 7 Jun 2024 16:40:23 -0400 Subject: [PATCH] update tests with generation changes. --- .../tests/ResourcesTestBase.cs | 7 ++- .../DeploymentStackCollectionTests.cs | 54 ++++++------------- .../DeploymentStackOperationsTests.cs | 22 +++----- 3 files changed, 30 insertions(+), 53 deletions(-) diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/ResourcesTestBase.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/ResourcesTestBase.cs index 1ca28f44f56f9..8399123e859f9 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/ResourcesTestBase.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/ResourcesTestBase.cs @@ -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", @@ -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", diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackCollectionTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackCollectionTests.cs index 322034bb5142a..7748f521af5c3 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackCollectionTests.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackCollectionTests.cs @@ -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); @@ -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); @@ -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) { @@ -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); @@ -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; @@ -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) { @@ -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); @@ -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); @@ -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) { diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackOperationsTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackOperationsTests.cs index 719b2eed09c6f..8f916fa339a5b 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackOperationsTests.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentStackOperationsTests.cs @@ -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(async () => await deploymentStack.GetAsync()); @@ -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. @@ -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(async () => await deploymentStack.GetAsync()); @@ -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); @@ -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(async () => await deploymentStack.GetAsync()); @@ -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);