From c6c18984cca1210b84286d67c4c144fd36f3b5c1 Mon Sep 17 00:00:00 2001 From: mcgallan <88413158+mcgallan@users.noreply.github.com> Date: Tue, 18 Jul 2023 00:44:22 +0800 Subject: [PATCH] Analysis tests (#37065) --- .../assets.json | 6 + .../tests/AnaltsisManagementTestBase.cs | 41 ------- .../tests/AnalysisManagementTestBase.cs | 52 +++++++++ ...s => AnalysisManagementTestEnvironment.cs} | 2 +- .../tests/TestCase/AnalysisServiceTests.cs | 108 ++++++++++++++++++ 5 files changed, 167 insertions(+), 42 deletions(-) create mode 100644 sdk/analysisservices/Azure.ResourceManager.Analysis/assets.json delete mode 100644 sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestBase.cs create mode 100644 sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestBase.cs rename sdk/analysisservices/Azure.ResourceManager.Analysis/tests/{AnaltsisManagementTestEnvironment.cs => AnalysisManagementTestEnvironment.cs} (75%) create mode 100644 sdk/analysisservices/Azure.ResourceManager.Analysis/tests/TestCase/AnalysisServiceTests.cs diff --git a/sdk/analysisservices/Azure.ResourceManager.Analysis/assets.json b/sdk/analysisservices/Azure.ResourceManager.Analysis/assets.json new file mode 100644 index 0000000000000..b67757cc05078 --- /dev/null +++ b/sdk/analysisservices/Azure.ResourceManager.Analysis/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "net", + "TagPrefix": "net/analysisservices/Azure.ResourceManager.Analysis", + "Tag": "net/analysisservices/Azure.ResourceManager.Analysis_e6bfde6996" +} diff --git a/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestBase.cs b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestBase.cs deleted file mode 100644 index af6d463a67944..0000000000000 --- a/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestBase.cs +++ /dev/null @@ -1,41 +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; - -namespace Azure.ResourceManager.Analysis.Tests -{ - public class AnaltsisManagementTestBase : ManagementRecordedTestBase - { - protected ArmClient Client { get; private set; } - - protected AnaltsisManagementTestBase(bool isAsync, RecordedTestMode mode) - : base(isAsync, mode) - { - } - - protected AnaltsisManagementTestBase(bool isAsync) - : base(isAsync) - { - } - - [SetUp] - public void CreateCommonClient() - { - Client = GetArmClient(); - } - - protected async Task CreateResourceGroup(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location) - { - string rgName = Recording.GenerateAssetName(rgNamePrefix); - ResourceGroupData input = new ResourceGroupData(location); - var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); - return lro.Value; - } - } -} diff --git a/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestBase.cs b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestBase.cs new file mode 100644 index 0000000000000..b64e877c26694 --- /dev/null +++ b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestBase.cs @@ -0,0 +1,52 @@ +// 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; + +namespace Azure.ResourceManager.Analysis.Tests +{ + public class AnalysisManagementTestBase : ManagementRecordedTestBase + { + protected ArmClient Client { get; private set; } + protected AzureLocation DefaultLocation => TestEnvironment.Location; + protected SubscriptionResource DefaultSubscription { get; private set; } + + protected AnalysisManagementTestBase(bool isAsync, RecordedTestMode mode) + : base(isAsync, mode) + { + } + + protected AnalysisManagementTestBase(bool isAsync) + : base(isAsync) + { + } + + [SetUp] + public async Task CreateCommonClient() + { + Client = GetArmClient(); + DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); + } + + protected async Task CreateResourceGroupAsync() + { + var resourceGroupName = Recording.GenerateAssetName("testRG-"); + var rgOp = await DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync( + WaitUntil.Completed, + resourceGroupName, + new ResourceGroupData(DefaultLocation) + { + Tags = + { + { "test", "env" } + } + }); + return rgOp.Value; + } + } +} diff --git a/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestEnvironment.cs b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestEnvironment.cs similarity index 75% rename from sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestEnvironment.cs rename to sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestEnvironment.cs index f44918fcb0a42..a5ed3e2bd8034 100644 --- a/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnaltsisManagementTestEnvironment.cs +++ b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/AnalysisManagementTestEnvironment.cs @@ -5,7 +5,7 @@ namespace Azure.ResourceManager.Analysis.Tests { - public class AnaltsisManagementTestEnvironment : TestEnvironment + public class AnalysisManagementTestEnvironment : TestEnvironment { } } \ No newline at end of file diff --git a/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/TestCase/AnalysisServiceTests.cs b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/TestCase/AnalysisServiceTests.cs new file mode 100644 index 0000000000000..619f8b1f90455 --- /dev/null +++ b/sdk/analysisservices/Azure.ResourceManager.Analysis/tests/TestCase/AnalysisServiceTests.cs @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Analysis.Models; +using Azure.ResourceManager.Models; +using Azure.ResourceManager.Resources; +using NUnit.Framework; + +namespace Azure.ResourceManager.Analysis.Tests +{ + public class AnalysisServiceTests : AnalysisManagementTestBase + { + public AnalysisServiceTests(bool isAsync): + base(isAsync)//, RecordedTestMode.Record) + { + } + + private AnalysisServerData GetServerData() + { + var sku = new AnalysisResourceSku("S1") + { + Tier = AnalysisSkuTier.Standard + }; + var data = new AnalysisServerData(DefaultLocation, sku) + { + AsAdministrators = new ServerAdministrators() + { + }, + BackupBlobContainerUri = new Uri("https://aassdk1.blob.core.windows.net/azsdktest?dummykey1") + }; + return data; + } + + private async Task GetCollection() + { + var resourceGroup = await CreateResourceGroupAsync(); + var collection = resourceGroup.GetAnalysisServers(); + return collection; + } + + public static void AssertResource(ResourceData r1, ResourceData r2) + { + Assert.AreEqual(r1.Name, r2.Name); + Assert.AreEqual(r1.Id, r2.Id); + Assert.AreEqual(r1.ResourceType, r2.ResourceType); + } + + private void AssertService(AnalysisServerData data1, AnalysisServerData data2) + { + AssertResource(data1, data2); + Assert.AreEqual(data1.State, data2.State); + Assert.AreEqual(data1.AnalysisServerSku, data2.AnalysisServerSku); + Assert.AreEqual(data1.BackupBlobContainerUri, data2.BackupBlobContainerUri); + Assert.AreEqual(data1.Location, data2.Location); + } + + [TestCase] + public async Task AnalysticServiceTests() + { + var collection = await GetCollection(); + var name = Recording.GenerateAssetName("analysisservice"); + var name2 = Recording.GenerateAssetName("analysisservice"); + var name3 = Recording.GenerateAssetName("analysisservice"); + var input = GetServerData(); + var lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, name, input); + AnalysisServerResource account = lro.Value; + Assert.AreEqual(name, account.Data.Name); + //2.Get + AnalysisServerResource account2 = await account.GetAsync(); + AssertService(account.Data, account2.Data); + //3.GetAll + _ = await collection.CreateOrUpdateAsync(WaitUntil.Completed, name, input); + _ = await collection.CreateOrUpdateAsync(WaitUntil.Completed, name2, input); + _ = await collection.CreateOrUpdateAsync(WaitUntil.Completed, name3, input); + int count = 0; + await foreach (var num in collection.GetAllAsync()) + { + count++; + } + Assert.GreaterOrEqual(count, 3); + //4.Exists + Assert.IsTrue(await collection.ExistsAsync(name)); + Assert.IsFalse(await collection.ExistsAsync(name + "1")); + + Assert.ThrowsAsync(async () => _ = await collection.ExistsAsync(null)); + //Resource + //5.Get + AnalysisServerResource account3 = await account.GetAsync(); + AssertService(account.Data, account3.Data); + //6.CheckAnalysisServerNameAvailability + AnalysisServerNameAvailabilityContent content = new AnalysisServerNameAvailabilityContent() + { + Name = name, + ResourceType = "Microsoft.AnalysisServices/servers", + }; + AnalysisServerNameAvailabilityResult result = await DefaultSubscription.CheckAnalysisServerNameAvailabilityAsync(DefaultLocation, content); + //7.suspend + await account.SuspendAsync(WaitUntil.Completed); + //8.Resume + await account.ResumeAsync(WaitUntil.Completed); + //9.Delete + await account.DeleteAsync(WaitUntil.Completed); + } + } +}