From 5e6363c0065b2081c114137ffda9899b3c92b65c Mon Sep 17 00:00:00 2001 From: Hong Ma Date: Thu, 14 Nov 2024 16:39:12 -0800 Subject: [PATCH] add scenario tests --- ...rceManager.HybridConnectivity.Tests.csproj | 5 + ...onnectivityManagementMultiCloudTestBase.cs | 55 ----------- .../HybridConnectivityManagementTestBase.cs | 65 ++++++++++++ ...ridConnectivityPublicCloudConnectorTest.cs | 98 +++++++++++++++++++ ...idconnectivityManagementTestEnvironment.cs | 4 +- sdk/hybridconnectivity/test-resources.json | 6 ++ 6 files changed, 176 insertions(+), 57 deletions(-) delete mode 100644 sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementMultiCloudTestBase.cs create mode 100644 sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementTestBase.cs create mode 100644 sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Scenario/HybridConnectivityPublicCloudConnectorTest.cs create mode 100644 sdk/hybridconnectivity/test-resources.json diff --git a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Azure.ResourceManager.HybridConnectivity.Tests.csproj b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Azure.ResourceManager.HybridConnectivity.Tests.csproj index 9ec3fc73b24bf..286e584c88f17 100644 --- a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Azure.ResourceManager.HybridConnectivity.Tests.csproj +++ b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Azure.ResourceManager.HybridConnectivity.Tests.csproj @@ -1,6 +1,11 @@  + + + + + diff --git a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementMultiCloudTestBase.cs b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementMultiCloudTestBase.cs deleted file mode 100644 index c0de7e8bb5fb4..0000000000000 --- a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementMultiCloudTestBase.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using NUnit.Framework; -using System.Threading.Tasks; -using System; -using Azure.Identity; -using Azure.ResourceManager.HybridConnectivity.Models; -using Azure.ResourceManager.Models; -using System.Collections.Generic; -using System.Xml; -using Castle.Components.DictionaryAdapter.Xml; - -namespace Azure.ResourceManager.HybridConnectivity.Tests -{ - public class HybridConnectivityManagementMultiCloudTestBase : ManagementRecordedTestBase - { - public ArmClient ArmClient { get; private set; } - - public ResourceIdentifier resourceGroupResourceId { get; set; } - - public ResourceGroupResource resourceGroupResource { get; set; } - - public PublicCloudConnectorCollection publicCloudConnectorCollection { get; set; } - - public SubscriptionResource Subscription { get; set; } - - public string subscriptionId = "1c70e365-4937-4ff9-8524-262064a268d8"; - - public string resourceGroupName = "MultiCloudSDKTestRG"; - - public HybridConnectivityManagementMultiCloudTestBase(bool isAsync) : base(isAsync) { } - - protected HybridConnectivityManagementMultiCloudTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode) { } - - [SetUp] - public void CreateCommonClient() - { - ArmClient = GetArmClient(); - } - - protected async Task InitializeClients() - { - Subscription = await ArmClient.GetDefaultSubscriptionAsync(); - resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName); - resourceGroupResource = ArmClient.GetResourceGroupResource(resourceGroupResourceId); - - //publicCloudConnectorCollection = resourceGroupResource.GetPublicCloudConnectors(); - } - } -} diff --git a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementTestBase.cs b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementTestBase.cs new file mode 100644 index 0000000000000..fabfea9bd71e6 --- /dev/null +++ b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/HybridConnectivityManagementTestBase.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.TestFramework; +using NUnit.Framework; +using System.Threading.Tasks; +using System; +using Azure.Identity; +using Azure.ResourceManager.HybridConnectivity.Models; +using Azure.ResourceManager.Models; +using System.Collections.Generic; +using System.Xml; +using Castle.Components.DictionaryAdapter.Xml; + +namespace Azure.ResourceManager.HybridConnectivity.Tests +{ + public abstract class HybridConnectivityManagementTestBase : ManagementRecordedTestBase + { + protected ArmClient ArmClient { get; private set; } + protected AzureLocation DefaultLocation = AzureLocation.EastUS; + protected const string DefaultResourceGroupPrefix = "HybridConnectivitySDKRG"; + protected const string ConnectorName = "MultiCloudSDKTestConnectorName"; + protected const string SolutionConfigurationName = "TestSolutionConfigName"; + protected const string AssetManagementType = "Microsoft.AssetManagement"; + + protected HybridConnectivityManagementTestBase(bool isAsync, RecordedTestMode? mode = null) + : base(isAsync, mode) + { + } + + [SetUp] + public void CreateCommonClient() + { + ArmClient = GetArmClient(); + } + + protected async Task CreateResourceGroup() + { + var subscription = await ArmClient.GetDefaultSubscriptionAsync(); + string rgName = Recording.GenerateAssetName(DefaultResourceGroupPrefix); + ResourceGroupData input = new ResourceGroupData(DefaultLocation); + var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); + return lro.Value; + } + + protected async Task CreatePublicCloudConnector(ResourceGroupResource rg) + { + var connectorData = new PublicCloudConnectorData(DefaultLocation) { }; + + var awsCloudProfile = new AwsCloudProfile("123456789123") { }; + awsCloudProfile.IsOrganizationalAccount = false; + + var properties = new PublicCloudConnectorProperties(awsCloudProfile, HybridConnectivityHostType.AWS) { }; + + connectorData.Properties = properties; + + var collection = rg.GetPublicCloudConnectors(); + var pcc = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ConnectorName, connectorData); + return pcc.Value; + } + } +} diff --git a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Scenario/HybridConnectivityPublicCloudConnectorTest.cs b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Scenario/HybridConnectivityPublicCloudConnectorTest.cs new file mode 100644 index 0000000000000..12d47b7d933c8 --- /dev/null +++ b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/Scenario/HybridConnectivityPublicCloudConnectorTest.cs @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.IO; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.ResourceManager.HybridConnectivity; +using Azure.ResourceManager.HybridConnectivity.Models; +using Azure.ResourceManager.Models; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.TestFramework; +using NUnit.Framework; + +namespace Azure.ResourceManager.HybridConnectivity.Tests.Scenario +{ + public class HybridConnectivityPublicCloudConnectorTest : HybridConnectivityManagementTestBase + { + private PublicCloudConnectorResource _testConnector; + + private ResourceGroupResource _testRG; + + public HybridConnectivityPublicCloudConnectorTest(bool isAsync) : base(isAsync, RecordedTestMode.Record) + { + } + + [SetUp] + public async Task TestSetUp() + { + _testRG = await CreateResourceGroup(); + Assert.IsNotNull(_testRG, "Resource Group initialization failed."); + + _testConnector = await CreatePublicCloudConnector(_testRG); + Assert.IsNotNull(_testConnector, "Public Cloud Connector initialization failed."); + } + + [TearDown] + public async Task TearDown() + { + var deleteResp = await _testConnector.DeleteAsync(WaitUntil.Completed); + Assert.AreEqual(200, deleteResp.GetRawResponse().Status); + } + + [RecordedTest] + public async Task TestPublicCloudConnector() + { + var connectorCollection = _testRG.GetPublicCloudConnectors(); + Assert.IsNotNull(connectorCollection); + + await createSolutionConfiguration(); + + var testPermissionResp = await _testConnector.TestPermissionsAsync(WaitUntil.Completed); + Assert.IsNotNull(testPermissionResp); + Assert.AreEqual(200, testPermissionResp.GetRawResponse().Status); + } + + [RecordedTest] + public async Task TestSolutionConfiguration() + { + var sc = await createSolutionConfiguration(); + + var patchData = new SolutionConfigurationPatch(); + patchData.Properties = new SolutionConfigurationPropertiesUpdate(); + patchData.Properties.SolutionType = "Microsoft.AssetManagement"; + patchData.Properties.SolutionSettings.Add("periodicSync", "true"); + patchData.Properties.SolutionSettings.Add("periodicSyncTime", "2"); + + var updateResp = await sc.UpdateAsync(patchData); + Assert.AreEqual(200, updateResp.GetRawResponse().Status); + Assert.AreEqual("2", updateResp.Value.Data.Properties.SolutionSettings["periodicSyncTime"]); + + var deleteResp = await sc.DeleteAsync(WaitUntil.Completed); + Assert.AreEqual(200, deleteResp.GetRawResponse().Status); + } + + protected async Task createSolutionConfiguration() + { + var scopeId = _testConnector.Id; + var scCollection = ArmClient.GetSolutionConfigurations(scopeId); + Assert.IsNotNull(scCollection); + + var scProperties = new SolutionConfigurationProperties(AssetManagementType); + scProperties.SolutionSettings.Add("periodicSync", "true"); + scProperties.SolutionSettings.Add("periodicSyncTime", "1"); + scProperties.SolutionSettings.Add("cloudProviderServiceTypes", "ec2,s3"); + scProperties.SolutionSettings.Add("awsGlobalReadOnly", "true"); + scProperties.SolutionSettings.Add("cloudProviderRegions", "us-east-1"); + + var scData = new SolutionConfigurationData(); + scData.Properties = scProperties; + + var scTask = await scCollection.CreateOrUpdateAsync(WaitUntil.Completed, SolutionConfigurationName, scData); + var sc = scTask.Value; + Assert.IsNotNull(sc); + return sc; + } + } +} diff --git a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/hybridconnectivityManagementTestEnvironment.cs b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/hybridconnectivityManagementTestEnvironment.cs index db5d0c8d09084..c095519a72a09 100644 --- a/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/hybridconnectivityManagementTestEnvironment.cs +++ b/sdk/hybridconnectivity/Azure.ResourceManager.HybridConnectivity/tests/hybridconnectivityManagementTestEnvironment.cs @@ -5,7 +5,7 @@ namespace Azure.ResourceManager.HybridConnectivity.Tests { - public class hybridconnectivityManagementTestEnvironment : TestEnvironment + public class HybridconnectivityManagementTestEnvironment : TestEnvironment { } -} \ No newline at end of file +} diff --git a/sdk/hybridconnectivity/test-resources.json b/sdk/hybridconnectivity/test-resources.json new file mode 100644 index 0000000000000..a837d5a0f2b84 --- /dev/null +++ b/sdk/hybridconnectivity/test-resources.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + ] +}