From 63b53bd25fd74921a525ed717d2658e858438dc5 Mon Sep 17 00:00:00 2001 From: Subhashni Kadhiresan Date: Mon, 14 Oct 2024 16:12:49 -0700 Subject: [PATCH 1/5] added tests --- .../Scenario/DataBoundaryOperationsTests.cs | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs new file mode 100644 index 0000000000000..b43c1e7f51f16 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.TestFramework; +using Azure.Identity; +using Azure.ResourceManager.Resources.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.Resources.Tests +{ + public class DataBoundaryOperationsTests : ResourcesTestBase + { + public DataBoundaryOperationsTests(bool isAsync) + : base(isAsync)//, RecordedTestMode.Record + { + } + + [TestCase] + [RecordedTest] + public async Task GetDataBoundaryTenant() + { + TokenCredential cred = new DefaultAzureCredential(); + ArmClient client = new ArmClient(cred); + + DataBoundaryName name = DataBoundaryName.Default; + ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); + TenantDataBoundaryResource tenantDataBoundary = client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); + + TenantDataBoundaryResource result = await tenantDataBoundary.GetAsync(); + + DataBoundaryData resourceData = result.Data; + + Assert.AreEqual(DataBoundaryRegion.EU, resourceData.Properties.DataBoundary); + } + + [TestCase] + [RecordedTest] + public async Task GetDataBoundaryScoped() + { + TokenCredential cred = new DefaultAzureCredential(); + ArmClient client = new ArmClient(cred); + + DataBoundaryName name = DataBoundaryName.Default; + string scope = "/subscriptions/2145a411-d149-4010-84d4-40fe8a55db44"; + ResourceIdentifier resourceId = DataBoundaryResource.CreateResourceIdentifier(scope, name); + DataBoundaryResource dataBoundary = client.GetDataBoundaryResource(resourceId); + DataBoundaryResource result = await dataBoundary.GetAsync(name); + DataBoundaryData resourceData = result.Data; + Assert.AreEqual(DataBoundaryRegion.Global, resourceData.Properties.DataBoundary); + Assert.AreEqual(DataBoundaryProvisioningState.Succeeded, resourceData.Properties.ProvisioningState); + } + + [TestCase] + [RecordedTest] + public async Task GetDataBoundaryScopedCollection() + { + TokenCredential cred = new DefaultAzureCredential(); + ArmClient client = new ArmClient(cred); + + DataBoundaryName name = DataBoundaryName.Default; + string scope = "subscriptions/2145a411-d149-4010-84d4-40fe8a55db44"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + DataBoundaryCollection collection = client.GetDataBoundaries(scopeId); + + DataBoundaryResource result = await collection.GetAsync(name); + + DataBoundaryData resourceData = result.Data; + + Assert.AreEqual(DataBoundaryRegion.Global, resourceData.Properties.DataBoundary); + Assert.AreEqual(DataBoundaryProvisioningState.Succeeded, resourceData.Properties.ProvisioningState); + } + + [TestCase] + [RecordedTest] + public async Task PutDataBoundary() + { + TokenCredential cred = new DefaultAzureCredential(); + ArmClient client = new ArmClient(cred); + + DataBoundaryName name = DataBoundaryName.Default; + ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); + TenantDataBoundaryResource tenantDataBoundary = client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); + + DataBoundaryData data = new DataBoundaryData() + { + Properties = new DataBoundaryProperties() + { + DataBoundary = DataBoundaryRegion.EU, + } + }; + + try { + ArmOperation result = await tenantDataBoundary.UpdateAsync(WaitUntil.Completed, data); + throw new Exception(); + } catch (Exception e) + { + e.ToString().Contains("does not have authorization to perform action"); + } + } + } +} From ab124179fe1294e120228480d0afa54cff5d0662 Mon Sep 17 00:00:00 2001 From: Subhashni Kadhiresan Date: Mon, 14 Oct 2024 20:53:33 -0700 Subject: [PATCH 2/5] updated tests to using Client --- .../Scenario/DataBoundaryOperationsTests.cs | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs index b43c1e7f51f16..c98b66b3f9d85 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs @@ -22,12 +22,9 @@ public DataBoundaryOperationsTests(bool isAsync) [RecordedTest] public async Task GetDataBoundaryTenant() { - TokenCredential cred = new DefaultAzureCredential(); - ArmClient client = new ArmClient(cred); - DataBoundaryName name = DataBoundaryName.Default; ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); - TenantDataBoundaryResource tenantDataBoundary = client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); + TenantDataBoundaryResource tenantDataBoundary = Client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); TenantDataBoundaryResource result = await tenantDataBoundary.GetAsync(); @@ -40,13 +37,10 @@ public async Task GetDataBoundaryTenant() [RecordedTest] public async Task GetDataBoundaryScoped() { - TokenCredential cred = new DefaultAzureCredential(); - ArmClient client = new ArmClient(cred); - DataBoundaryName name = DataBoundaryName.Default; string scope = "/subscriptions/2145a411-d149-4010-84d4-40fe8a55db44"; ResourceIdentifier resourceId = DataBoundaryResource.CreateResourceIdentifier(scope, name); - DataBoundaryResource dataBoundary = client.GetDataBoundaryResource(resourceId); + DataBoundaryResource dataBoundary = Client.GetDataBoundaryResource(resourceId); DataBoundaryResource result = await dataBoundary.GetAsync(name); DataBoundaryData resourceData = result.Data; Assert.AreEqual(DataBoundaryRegion.Global, resourceData.Properties.DataBoundary); @@ -57,13 +51,10 @@ public async Task GetDataBoundaryScoped() [RecordedTest] public async Task GetDataBoundaryScopedCollection() { - TokenCredential cred = new DefaultAzureCredential(); - ArmClient client = new ArmClient(cred); - DataBoundaryName name = DataBoundaryName.Default; string scope = "subscriptions/2145a411-d149-4010-84d4-40fe8a55db44"; ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); - DataBoundaryCollection collection = client.GetDataBoundaries(scopeId); + DataBoundaryCollection collection = Client.GetDataBoundaries(scopeId); DataBoundaryResource result = await collection.GetAsync(name); @@ -77,12 +68,9 @@ public async Task GetDataBoundaryScopedCollection() [RecordedTest] public async Task PutDataBoundary() { - TokenCredential cred = new DefaultAzureCredential(); - ArmClient client = new ArmClient(cred); - DataBoundaryName name = DataBoundaryName.Default; ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); - TenantDataBoundaryResource tenantDataBoundary = client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); + TenantDataBoundaryResource tenantDataBoundary = Client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); DataBoundaryData data = new DataBoundaryData() { From ae4a3824412064b76383b175dbc78269f8a4afd6 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Tue, 15 Oct 2024 18:38:02 -0700 Subject: [PATCH 3/5] update assets.json with new recording --- sdk/resources/Azure.ResourceManager.Resources/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resources/Azure.ResourceManager.Resources/assets.json b/sdk/resources/Azure.ResourceManager.Resources/assets.json index 399104140838e..833d437794313 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/assets.json +++ b/sdk/resources/Azure.ResourceManager.Resources/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/resources/Azure.ResourceManager.Resources", - "Tag": "net/resources/Azure.ResourceManager.Resources_581adacbe8" + "Tag": "net/resources/Azure.ResourceManager.Resources_58ecd150d6" } From 8746b0c99f0a50c0c54fb8504b9a2872efd8de1c Mon Sep 17 00:00:00 2001 From: Subhashni Kadhiresan Date: Tue, 15 Oct 2024 20:20:01 -0700 Subject: [PATCH 4/5] adding assert --- .../tests/Scenario/DataBoundaryOperationsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs index c98b66b3f9d85..6d7f2316202e0 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs @@ -85,7 +85,7 @@ public async Task PutDataBoundary() throw new Exception(); } catch (Exception e) { - e.ToString().Contains("does not have authorization to perform action"); + Assert.IsTrue(e.ToString().Contains("does not have authorization to perform action")); } } } From 62fc6d961513e088c3c3d27a046f75917e296023 Mon Sep 17 00:00:00 2001 From: Subhashni Kadhiresan Date: Thu, 24 Oct 2024 14:47:58 -0700 Subject: [PATCH 5/5] format --- .../tests/Scenario/DataBoundaryOperationsTests.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs index 6d7f2316202e0..46c789ae015af 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DataBoundaryOperationsTests.cs @@ -66,7 +66,7 @@ public async Task GetDataBoundaryScopedCollection() [TestCase] [RecordedTest] - public async Task PutDataBoundary() + public void PutDataBoundary() { DataBoundaryName name = DataBoundaryName.Default; ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); @@ -80,13 +80,8 @@ public async Task PutDataBoundary() } }; - try { - ArmOperation result = await tenantDataBoundary.UpdateAsync(WaitUntil.Completed, data); - throw new Exception(); - } catch (Exception e) - { - Assert.IsTrue(e.ToString().Contains("does not have authorization to perform action")); - } + var ex = Assert.ThrowsAsync(async () => await tenantDataBoundary.UpdateAsync(WaitUntil.Completed, data)); + Assert.IsTrue(ex.Message.Contains("does not have authorization to perform action")); } } }