|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Azure.Core; |
| 7 | +using Azure.Core.TestFramework; |
| 8 | +using Azure.Identity; |
| 9 | +using Azure.ResourceManager.Resources.Models; |
| 10 | +using NUnit.Framework; |
| 11 | + |
| 12 | +namespace Azure.ResourceManager.Resources.Tests |
| 13 | +{ |
| 14 | + public class DataBoundaryOperationsTests : ResourcesTestBase |
| 15 | + { |
| 16 | + public DataBoundaryOperationsTests(bool isAsync) |
| 17 | + : base(isAsync)//, RecordedTestMode.Record |
| 18 | + { |
| 19 | + } |
| 20 | + |
| 21 | + [TestCase] |
| 22 | + [RecordedTest] |
| 23 | + public async Task GetDataBoundaryTenant() |
| 24 | + { |
| 25 | + DataBoundaryName name = DataBoundaryName.Default; |
| 26 | + ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); |
| 27 | + TenantDataBoundaryResource tenantDataBoundary = Client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); |
| 28 | + |
| 29 | + TenantDataBoundaryResource result = await tenantDataBoundary.GetAsync(); |
| 30 | + |
| 31 | + DataBoundaryData resourceData = result.Data; |
| 32 | + |
| 33 | + Assert.AreEqual(DataBoundaryRegion.EU, resourceData.Properties.DataBoundary); |
| 34 | + } |
| 35 | + |
| 36 | + [TestCase] |
| 37 | + [RecordedTest] |
| 38 | + public async Task GetDataBoundaryScoped() |
| 39 | + { |
| 40 | + DataBoundaryName name = DataBoundaryName.Default; |
| 41 | + string scope = "/subscriptions/2145a411-d149-4010-84d4-40fe8a55db44"; |
| 42 | + ResourceIdentifier resourceId = DataBoundaryResource.CreateResourceIdentifier(scope, name); |
| 43 | + DataBoundaryResource dataBoundary = Client.GetDataBoundaryResource(resourceId); |
| 44 | + DataBoundaryResource result = await dataBoundary.GetAsync(name); |
| 45 | + DataBoundaryData resourceData = result.Data; |
| 46 | + Assert.AreEqual(DataBoundaryRegion.Global, resourceData.Properties.DataBoundary); |
| 47 | + Assert.AreEqual(DataBoundaryProvisioningState.Succeeded, resourceData.Properties.ProvisioningState); |
| 48 | + } |
| 49 | + |
| 50 | + [TestCase] |
| 51 | + [RecordedTest] |
| 52 | + public async Task GetDataBoundaryScopedCollection() |
| 53 | + { |
| 54 | + DataBoundaryName name = DataBoundaryName.Default; |
| 55 | + string scope = "subscriptions/2145a411-d149-4010-84d4-40fe8a55db44"; |
| 56 | + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); |
| 57 | + DataBoundaryCollection collection = Client.GetDataBoundaries(scopeId); |
| 58 | + |
| 59 | + DataBoundaryResource result = await collection.GetAsync(name); |
| 60 | + |
| 61 | + DataBoundaryData resourceData = result.Data; |
| 62 | + |
| 63 | + Assert.AreEqual(DataBoundaryRegion.Global, resourceData.Properties.DataBoundary); |
| 64 | + Assert.AreEqual(DataBoundaryProvisioningState.Succeeded, resourceData.Properties.ProvisioningState); |
| 65 | + } |
| 66 | + |
| 67 | + [TestCase] |
| 68 | + [RecordedTest] |
| 69 | + public void PutDataBoundary() |
| 70 | + { |
| 71 | + DataBoundaryName name = DataBoundaryName.Default; |
| 72 | + ResourceIdentifier tenantDataBoundaryResourceId = TenantDataBoundaryResource.CreateResourceIdentifier(name); |
| 73 | + TenantDataBoundaryResource tenantDataBoundary = Client.GetTenantDataBoundaryResource(tenantDataBoundaryResourceId); |
| 74 | + |
| 75 | + DataBoundaryData data = new DataBoundaryData() |
| 76 | + { |
| 77 | + Properties = new DataBoundaryProperties() |
| 78 | + { |
| 79 | + DataBoundary = DataBoundaryRegion.EU, |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + var ex = Assert.ThrowsAsync<RequestFailedException>(async () => await tenantDataBoundary.UpdateAsync(WaitUntil.Completed, data)); |
| 84 | + Assert.IsTrue(ex.Message.Contains("does not have authorization to perform action")); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments