diff --git a/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs b/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs index 3bd636dc807c..474849e66341 100644 --- a/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs +++ b/common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs @@ -120,7 +120,7 @@ protected void CleanupResourceGroups() { try { - _cleanupClient.GetManagementGroup(mgmtGroupId).Delete(waitForCompletion: _waitForCleanup); + _cleanupClient.GetManagementGroup(new ResourceIdentifier(mgmtGroupId)).Delete(waitForCompletion: _waitForCleanup); } catch (RequestFailedException e) when (e.Status == 404 || e.Status == 403) { @@ -213,7 +213,7 @@ public void OneTimeCleanupResourceGroups() }); Parallel.ForEach(OneTimeManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId => { - _cleanupClient.GetManagementGroup(mgmtGroupId).Delete(waitForCompletion: _waitForCleanup); + _cleanupClient.GetManagementGroup(new ResourceIdentifier(mgmtGroupId)).Delete(waitForCompletion: _waitForCleanup); }); } diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index e243f852ce78..deaf1136e1cb 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -146,7 +146,7 @@ All should have PrivateAssets="All" set so they don't become package dependencies --> - + diff --git a/sdk/cdn/Azure.ResourceManager.Cdn/samples/Sample1_ManagingCdnOriginGroups.md b/sdk/cdn/Azure.ResourceManager.Cdn/samples/Sample1_ManagingCdnOriginGroups.md index 5a7767b2ffe8..327fcc31286d 100644 --- a/sdk/cdn/Azure.ResourceManager.Cdn/samples/Sample1_ManagingCdnOriginGroups.md +++ b/sdk/cdn/Azure.ResourceManager.Cdn/samples/Sample1_ManagingCdnOriginGroups.md @@ -62,7 +62,7 @@ string originGroupName = "myOriginGroup"; var input3 = new CdnOriginGroupData(); input3.Origins.Add(new WritableSubResource { - Id = $"{endpoint.Id}/origins/myOrigin" + Id = new ResourceIdentifier($"{endpoint.Id}/origins/myOrigin") }); CdnOriginGroupCreateOperation lro3 = await endpoint.GetCdnOriginGroups().CreateOrUpdateAsync(originGroupName, input3); CdnOriginGroup originGroup = lro3.Value; diff --git a/sdk/cdn/Azure.ResourceManager.Cdn/tests/CdnManagementTestBase.cs b/sdk/cdn/Azure.ResourceManager.Cdn/tests/CdnManagementTestBase.cs index d77bdd02c430..bd281be5700c 100644 --- a/sdk/cdn/Azure.ResourceManager.Cdn/tests/CdnManagementTestBase.cs +++ b/sdk/cdn/Azure.ResourceManager.Cdn/tests/CdnManagementTestBase.cs @@ -71,13 +71,13 @@ protected async Task CreateCdnEndpointWithOriginGroup(Profile profi DeepCreatedOriginGroup deepCreatedOriginGroup = ResourceDataHelper.CreateDeepCreatedOriginGroup(); deepCreatedOriginGroup.Origins.Add(new WritableSubResource { - Id = $"{profile.Id}/endpoints/{endpointName}/origins/{deepCreatedOrigin.Name}" + Id = new ResourceIdentifier($"{profile.Id}/endpoints/{endpointName}/origins/{deepCreatedOrigin.Name}") }); input.Origins.Add(deepCreatedOrigin); input.OriginGroups.Add(deepCreatedOriginGroup); input.DefaultOriginGroup = new EndpointPropertiesUpdateParametersDefaultOriginGroup { - Id = $"{profile.Id}/endpoints/{endpointName}/originGroups/{deepCreatedOriginGroup.Name}" + Id = new ResourceIdentifier($"{profile.Id}/endpoints/{endpointName}/originGroups/{deepCreatedOriginGroup.Name}") }; var lro = await profile.GetCdnEndpoints().CreateOrUpdateAsync(endpointName, input); return lro.Value; @@ -109,7 +109,7 @@ protected async Task CreateCdnOriginGroup(CdnEndpoint endpoint, CdnOriginGroupData input = ResourceDataHelper.CreateOriginGroupData(); input.Origins.Add(new WritableSubResource { - Id = $"{endpoint.Id}/origins/{originName}" + Id = new ResourceIdentifier($"{endpoint.Id}/origins/{originName}") }); var lro = await endpoint.GetCdnOriginGroups().CreateOrUpdateAsync(originGroupName, input); return lro.Value; diff --git a/sdk/cdn/Azure.ResourceManager.Cdn/tests/Helper/ResourceDataHelper.cs b/sdk/cdn/Azure.ResourceManager.Cdn/tests/Helper/ResourceDataHelper.cs index 881b74c2cf57..bc26b02b3d3d 100644 --- a/sdk/cdn/Azure.ResourceManager.Cdn/tests/Helper/ResourceDataHelper.cs +++ b/sdk/cdn/Azure.ResourceManager.Cdn/tests/Helper/ResourceDataHelper.cs @@ -90,7 +90,7 @@ public static class ResourceDataHelper }, AzureDnsZone = new WritableSubResource { - Id = "/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/cdntest/providers/Microsoft.Network/dnszones/azuretest.net" + Id = new ResourceIdentifier("/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/cdntest/providers/Microsoft.Network/dnszones/azuretest.net") } }; @@ -127,7 +127,7 @@ public static class ResourceDataHelper { WafPolicy = new WritableSubResource { - Id = "/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/CdnTest/providers/Microsoft.Network/frontdoorWebApplicationFirewallPolicies/testAFDWaf" + Id = new ResourceIdentifier("/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/CdnTest/providers/Microsoft.Network/frontdoorWebApplicationFirewallPolicies/testAFDWaf") } } }; @@ -136,7 +136,7 @@ public static class ResourceDataHelper { Parameters = new CustomerCertificateParameters(new WritableSubResource { - Id = "/subscriptions/87082bb7-c39f-42d2-83b6-4980444c7397/resourceGroups/CdnTest/providers/Microsoft.KeyVault/vaults/testKV4AFD/certificates/testCert" + Id = new ResourceIdentifier("/subscriptions/87082bb7-c39f-42d2-83b6-4980444c7397/resourceGroups/CdnTest/providers/Microsoft.KeyVault/vaults/testKV4AFD/certificates/testCert") }) { UseLatestVersion = true diff --git a/sdk/cdn/Azure.ResourceManager.Cdn/tests/Samples/Sample1_ManagingCdnOriginGroups.cs b/sdk/cdn/Azure.ResourceManager.Cdn/tests/Samples/Sample1_ManagingCdnOriginGroups.cs index f3c917177fb0..46b504da15f8 100644 --- a/sdk/cdn/Azure.ResourceManager.Cdn/tests/Samples/Sample1_ManagingCdnOriginGroups.cs +++ b/sdk/cdn/Azure.ResourceManager.Cdn/tests/Samples/Sample1_ManagingCdnOriginGroups.cs @@ -49,7 +49,7 @@ public async Task CreateOriginGroups() var input3 = new CdnOriginGroupData(); input3.Origins.Add(new WritableSubResource { - Id = $"{endpoint.Id}/origins/myOrigin" + Id = new ResourceIdentifier($"{endpoint.Id}/origins/myOrigin") }); CdnOriginGroupCreateOperation lro3 = await endpoint.GetCdnOriginGroups().CreateOrUpdateAsync(originGroupName, input3); CdnOriginGroup originGroup = lro3.Value; diff --git a/sdk/cdn/Azure.ResourceManager.Cdn/tests/Scenario/AfdSecurityPolicyOperationsTests.cs b/sdk/cdn/Azure.ResourceManager.Cdn/tests/Scenario/AfdSecurityPolicyOperationsTests.cs index 6d847100f2ff..1cff547422f9 100644 --- a/sdk/cdn/Azure.ResourceManager.Cdn/tests/Scenario/AfdSecurityPolicyOperationsTests.cs +++ b/sdk/cdn/Azure.ResourceManager.Cdn/tests/Scenario/AfdSecurityPolicyOperationsTests.cs @@ -55,7 +55,7 @@ public async Task Update() { WafPolicy = new WritableSubResource { - Id = "/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/CdnTest/providers/Microsoft.Network/frontdoorWebApplicationFirewallPolicies/testAFDWaf" + Id = new ResourceIdentifier("/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/CdnTest/providers/Microsoft.Network/frontdoorWebApplicationFirewallPolicies/testAFDWaf") } } }; diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/VirtualMachineTestBase.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/VirtualMachineTestBase.cs index ec512c1f4447..b3476eb37bb1 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/VirtualMachineTestBase.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/VirtualMachineTestBase.cs @@ -33,7 +33,7 @@ protected async Task CreateVirtualNetwork() { var vnetName = Recording.GenerateAssetName("testVNet-"); var subnetName = Recording.GenerateAssetName("testSubnet-"); - ResourceIdentifier vnetId = $"{_resourceGroup.Id}/providers/Microsoft.Network/virtualNetworks/{vnetName}"; + ResourceIdentifier vnetId = new ResourceIdentifier($"{_resourceGroup.Id}/providers/Microsoft.Network/virtualNetworks/{vnetName}"); var addressSpaces = new Dictionary() { { "addressPrefixes", new List() { "10.0.0.0/16" } } @@ -64,7 +64,7 @@ protected ResourceIdentifier GetSubnetId(GenericResource vnet) var properties = vnet.Data.Properties as IDictionary; var subnets = properties["subnets"] as IEnumerable; var subnet = subnets.First() as IDictionary; - return subnet["id"] as string; + return new ResourceIdentifier(subnet["id"] as string); } // WEIRD: second level resources cannot use GenericResourceCollection to create. @@ -72,7 +72,7 @@ protected ResourceIdentifier GetSubnetId(GenericResource vnet) private async Task CreateSubnet(ResourceIdentifier vnetId) { var subnetName = Recording.GenerateAssetName("testSubnet-"); - ResourceIdentifier subnetId = $"{vnetId}/subnets/{subnetName}"; + ResourceIdentifier subnetId = new ResourceIdentifier($"{vnetId}/subnets/{subnetName}"); var input = new GenericResourceData(DefaultLocation) { Properties = new Dictionary() @@ -87,7 +87,7 @@ private async Task CreateSubnet(ResourceIdentifier vnetId) private async Task CreateNetworkInterface(ResourceIdentifier subnetId) { var nicName = Recording.GenerateAssetName("testNic-"); - ResourceIdentifier nicId = $"{_resourceGroup.Id}/providers/Microsoft.Network/networkInterfaces/{nicName}"; + ResourceIdentifier nicId = new ResourceIdentifier($"{_resourceGroup.Id}/providers/Microsoft.Network/networkInterfaces/{nicName}"); var input = new GenericResourceData(DefaultLocation) { Properties = new Dictionary() diff --git a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj index 57942c4b31cc..1cb03e0250a7 100644 --- a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj +++ b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/sdk/core/Azure.Core/tests/TestClients/TestResource.cs b/sdk/core/Azure.Core/tests/TestClients/TestResource.cs index 4a4de9033891..54e3dda4a5d7 100644 --- a/sdk/core/Azure.Core/tests/TestClients/TestResource.cs +++ b/sdk/core/Azure.Core/tests/TestClients/TestResource.cs @@ -15,7 +15,7 @@ public class TestResource : ArmResource { private DiagnosticScopeFactory _diagnostic = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); - protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.Root.ResourceType; public virtual TestResource GetAnotherOperations() { diff --git a/sdk/deviceupdate/Azure.ResourceManager.DeviceUpdate/src/Customization/Models/DeviceUpdateAccountData.Serialization.cs b/sdk/deviceupdate/Azure.ResourceManager.DeviceUpdate/src/Customization/Models/DeviceUpdateAccountData.Serialization.cs index 247b6ae12fd4..f03c7cbc4745 100644 --- a/sdk/deviceupdate/Azure.ResourceManager.DeviceUpdate/src/Customization/Models/DeviceUpdateAccountData.Serialization.cs +++ b/sdk/deviceupdate/Azure.ResourceManager.DeviceUpdate/src/Customization/Models/DeviceUpdateAccountData.Serialization.cs @@ -70,7 +70,7 @@ internal static DeviceUpdateAccountData DeserializeDeviceUpdateAccountData(JsonE } if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) diff --git a/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/Tests/EventHubNamespaceTests.cs b/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/Tests/EventHubNamespaceTests.cs index 32ecad0ff471..774007674fa6 100644 --- a/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/Tests/EventHubNamespaceTests.cs +++ b/sdk/eventhub/Azure.ResourceManager.EventHubs/tests/Tests/EventHubNamespaceTests.cs @@ -316,9 +316,9 @@ public async Task SetGetNetworkRuleSets() //set network rule set string subscriptionId = DefaultSubscription.Id.ToString(); - string subnetId1 = subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1"; - string subnetId2 = subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2"; - string subnetId3 = subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3"; + ResourceIdentifier subnetId1 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1"); + ResourceIdentifier subnetId2 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2"); + ResourceIdentifier subnetId3 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3"); NetworkRuleSetData parameter = new NetworkRuleSetData() { DefaultAction = DefaultAction.Deny, diff --git a/sdk/network/Azure.ResourceManager.Network/src/Generated/Extensions/SubscriptionExtensions.cs b/sdk/network/Azure.ResourceManager.Network/src/Generated/Extensions/SubscriptionExtensions.cs index f98defa60beb..d29104ced041 100644 --- a/sdk/network/Azure.ResourceManager.Network/src/Generated/Extensions/SubscriptionExtensions.cs +++ b/sdk/network/Azure.ResourceManager.Network/src/Generated/Extensions/SubscriptionExtensions.cs @@ -29,7 +29,7 @@ public static partial class SubscriptionExtensions /// Returns a object. public static ApplicationGatewayAvailableSslOptions GetApplicationGatewayAvailableSslOptions(this Subscription subscription) { - return new ApplicationGatewayAvailableSslOptions(subscription, subscription.Id + "/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default"); + return new ApplicationGatewayAvailableSslOptions(subscription, new ResourceIdentifier(subscription.Id + "/providers/Microsoft.Network/applicationGatewayAvailableSslOptions/default")); } #endregion diff --git a/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkServiceClientTestBase.cs b/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkServiceClientTestBase.cs index 4dc354233ac2..5435f34f9ff2 100644 --- a/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkServiceClientTestBase.cs +++ b/sdk/network/Azure.ResourceManager.Network/tests/Helpers/NetworkServiceClientTestBase.cs @@ -687,16 +687,16 @@ public async Task CreateVirtualNetwork(string vnetName, string s return getVnetResponse; } - public static string GetChildLbResourceId(string subscriptionId, string resourceGroupName, string lbname, string childResourceType, string childResourceName) + public static ResourceIdentifier GetChildLbResourceId(string subscriptionId, string resourceGroupName, string lbname, string childResourceType, string childResourceName) { return - string.Format( + new ResourceIdentifier(string.Format( "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}", subscriptionId, resourceGroupName, lbname, childResourceType, - childResourceName); + childResourceName)); } protected ApplicationGatewayCollection GetApplicationGatewayCollection(string resourceGroupName) diff --git a/sdk/network/Azure.ResourceManager.Network/tests/Tests/ApplicationGatewayTests.cs b/sdk/network/Azure.ResourceManager.Network/tests/Tests/ApplicationGatewayTests.cs index 360664fc746d..295e5f807016 100644 --- a/sdk/network/Azure.ResourceManager.Network/tests/Tests/ApplicationGatewayTests.cs +++ b/sdk/network/Azure.ResourceManager.Network/tests/Tests/ApplicationGatewayTests.cs @@ -34,19 +34,19 @@ public async Task ClearChallengeCacheforRecord() _subscription = await ArmClient.GetDefaultSubscriptionAsync(); } - private static string GetChildAppGwResourceId(string subscriptionId, + private static ResourceIdentifier GetChildAppGwResourceId(string subscriptionId, string resourceGroupName, string appGwname, string childResourceType, string childResourceName) { - return string.Format( + return new ResourceIdentifier(string.Format( "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/applicationGateways/{2}/{3}/{4}", subscriptionId, resourceGroupName, appGwname, childResourceType, - childResourceName); + childResourceName)); } private List CreateSslCertificate(string sslCertName, string password) diff --git a/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallPolicyTests.cs b/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallPolicyTests.cs index 995eeee4cbce..d163fecf17b6 100644 --- a/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallPolicyTests.cs +++ b/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallPolicyTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Azure.Core.TestFramework; +using Azure.ResourceManager.Core; using Azure.ResourceManager.Resources; using Azure.ResourceManager.Resources.Models; using Azure.ResourceManager.Network.Models; @@ -67,7 +68,7 @@ public async Task GlobalSetUp() { Name = "fwpip", PublicIPAddress = new WritableSubResource() { Id = _publicIPAddressIdentifier }, - Subnet = new WritableSubResource() { Id = _networkIdentifier.ToString() + "/subnets/AzureFirewallSubnet" }, + Subnet = new WritableSubResource() { Id = _networkIdentifier.AppendChildResource("subnets", "AzureFirewallSubnet") }, }); var firewallLro = await rg.GetAzureFirewalls().CreateOrUpdateAsync(SessionRecording.GenerateAssetName("firewall-"), firewallData); _firewall = firewallLro.Value; diff --git a/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallTests.cs b/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallTests.cs index 3a1dc9256afd..3e835f8756af 100644 --- a/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallTests.cs +++ b/sdk/network/Azure.ResourceManager.Network/tests/Tests/FirewallTests.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using Azure.Core.TestFramework; +using Azure.ResourceManager.Core; using Azure.ResourceManager.Resources; using Azure.ResourceManager.Resources.Models; using Azure.ResourceManager.Network.Models; @@ -99,7 +100,7 @@ public async Task CreateFirewallAsync() { Name = "fwpip", PublicIPAddress = new WritableSubResource() { Id = _publicIPAddressIdentifier }, - Subnet = new WritableSubResource() { Id = _networkIdentifier.ToString() + "/subnets/AzureFirewallSubnet" }, + Subnet = new WritableSubResource() { Id = _networkIdentifier.AppendChildResource("subnets", "AzureFirewallSubnet") }, }); var firewallLro = await (await _resourceGroup.GetAzureFirewalls().CreateOrUpdateAsync(_firewallName, firewallData)).WaitForCompletionAsync(); return firewallLro.Value; diff --git a/sdk/resourcemanager/Azure.ResourceManager/README.md b/sdk/resourcemanager/Azure.ResourceManager/README.md index 208b20a17100..d6c75ecb0458 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/README.md +++ b/sdk/resourcemanager/Azure.ResourceManager/README.md @@ -138,13 +138,9 @@ However, keep in mind that some of those properties could be null. You can usual ### Example: ResourceIdentifier TryGet methods ```C# Snippet:Readme_CastToBaseResourceIdentifier string resourceId = "/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/workshop2021-rg/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"; -// Assume we don't know what type of resource id we have we can cast to the base type ResourceIdentifier id = new ResourceIdentifier(resourceId); -string property; -if (id.TryGetSubscriptionId(out property)) - Console.WriteLine($"Subscription: {property}"); -if (id.TryGetResourceGroupName(out property)) - Console.WriteLine($"ResourceGroup: {property}"); +Console.WriteLine($"Subscription: {id.SubscriptionId}"); +Console.WriteLine($"ResourceGroup: {id.ResourceGroupName}"); // Parent is only null when we reach the top of the chain which is a Tenant Console.WriteLine($"Vnet: {id.Parent.Name}"); // Name will never be null diff --git a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs index 0f810378f61e..7e0ffa5e34f9 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs @@ -69,19 +69,18 @@ public ResourceFilterCollection(Azure.ResourceManager.ResourceType type) { } public static partial class ResourceGroupExtensions { } - public partial class ResourceIdentifier : System.IComparable, System.IEquatable + public sealed partial class ResourceIdentifier : System.IComparable, System.IEquatable { - public static readonly Azure.ResourceManager.ResourceIdentifier RootResourceIdentifier; + public static readonly Azure.ResourceManager.ResourceIdentifier Root; public ResourceIdentifier(string resourceId) { } - public string Location { get { throw null; } protected set { } } - public virtual string Name { get { throw null; } } - public virtual Azure.ResourceManager.ResourceIdentifier Parent { get { throw null; } } - public string Provider { get { throw null; } protected set { } } - public string ResourceGroupName { get { throw null; } protected set { } } - public virtual Azure.ResourceManager.ResourceType ResourceType { get { throw null; } } - public string SubscriptionId { get { throw null; } protected set { } } + public Azure.ResourceManager.Resources.Models.Location Location { get { throw null; } } + public string Name { get { throw null; } } + public Azure.ResourceManager.ResourceIdentifier Parent { get { throw null; } } + public string Provider { get { throw null; } } + public string ResourceGroupName { get { throw null; } } + public Azure.ResourceManager.ResourceType ResourceType { get { throw null; } } + public string SubscriptionId { get { throw null; } } public int CompareTo(Azure.ResourceManager.ResourceIdentifier other) { throw null; } - public static Azure.ResourceManager.ResourceIdentifier Create(string resourceId) { throw null; } public bool Equals(Azure.ResourceManager.ResourceIdentifier other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } @@ -91,15 +90,10 @@ public ResourceIdentifier(string resourceId) { } public static bool operator >(Azure.ResourceManager.ResourceIdentifier left, Azure.ResourceManager.ResourceIdentifier right) { throw null; } public static bool operator >=(Azure.ResourceManager.ResourceIdentifier left, Azure.ResourceManager.ResourceIdentifier right) { throw null; } public static implicit operator string (Azure.ResourceManager.ResourceIdentifier id) { throw null; } - public static implicit operator Azure.ResourceManager.ResourceIdentifier (string other) { throw null; } public static bool operator !=(Azure.ResourceManager.ResourceIdentifier id1, Azure.ResourceManager.ResourceIdentifier id2) { throw null; } public static bool operator <(Azure.ResourceManager.ResourceIdentifier left, Azure.ResourceManager.ResourceIdentifier right) { throw null; } public static bool operator <=(Azure.ResourceManager.ResourceIdentifier left, Azure.ResourceManager.ResourceIdentifier right) { throw null; } public override string ToString() { throw null; } - public virtual bool TryGetLocation(out Azure.ResourceManager.Resources.Models.Location location) { throw null; } - public virtual bool TryGetParent(out Azure.ResourceManager.ResourceIdentifier resourceId) { throw null; } - public virtual bool TryGetResourceGroupName(out string resourceGroupName) { throw null; } - public virtual bool TryGetSubscriptionId(out string subscriptionId) { throw null; } } public partial class ResourceNameFilter : Azure.ResourceManager.GenericResourceFilter, System.IEquatable, System.IEquatable { @@ -132,7 +126,7 @@ public sealed partial class ResourceType : System.IComparable Types { get { throw null; } } public int CompareTo(Azure.ResourceManager.ResourceType other) { throw null; } @@ -696,7 +690,7 @@ protected override void ValidateResourceType(Azure.ResourceManager.ResourceIdent } public partial class GenericResourceData : Azure.ResourceManager.Models.TrackedResource { - public GenericResourceData(string location) : base (default(Azure.ResourceManager.Resources.Models.Location)) { } + public GenericResourceData(Azure.ResourceManager.Resources.Models.Location location) : base (default(Azure.ResourceManager.Resources.Models.Location)) { } public System.DateTimeOffset? ChangedTime { get { throw null; } } public System.DateTimeOffset? CreatedTime { get { throw null; } } public Azure.ResourceManager.Resources.Models.ResourceIdentity Identity { get { throw null; } set { } } @@ -1442,7 +1436,7 @@ public enum SpendingLimit public partial class SubResource { public SubResource() { } - protected internal SubResource(string id) { } + protected internal SubResource(Azure.ResourceManager.ResourceIdentifier id) { } public virtual Azure.ResourceManager.ResourceIdentifier Id { get { throw null; } } } public partial class SubscriptionPolicies @@ -1550,7 +1544,7 @@ public UserAssignedIdentity() { } public partial class WritableSubResource { public WritableSubResource() { } - protected internal WritableSubResource(string id) { } + protected internal WritableSubResource(Azure.ResourceManager.ResourceIdentifier id) { } public virtual Azure.ResourceManager.ResourceIdentifier Id { get { throw null; } set { } } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs index e232345592a5..c63ee621ce43 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs @@ -112,7 +112,7 @@ public ArmClient( _tenant = new Tenant(ClientOptions, Credential, BaseUri, Pipeline); _defaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId) ? null : - new Subscription(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), ResourceIdentifier.RootResourceIdentifier.AppendChildResource(Subscription.ResourceType.Type, defaultSubscriptionId)); + new Subscription(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), ResourceIdentifier.Root.AppendChildResource(Subscription.ResourceType.Type, defaultSubscriptionId)); ClientOptions.ApiVersions.SetProviderClient(this); } @@ -340,7 +340,7 @@ private IReadOnlyList GetGenericResourceOperationsInternal(IEnu var genericResourceOperations = new ChangeTrackingList(); foreach (string id in ids) { - genericResourceOperations.Add(new GenericResource(GetDefaultSubscription(), id)); + genericResourceOperations.Add(new GenericResource(GetDefaultSubscription(), new ResourceIdentifier(id))); } return genericResourceOperations; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ArmCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ArmCollection.cs index a45878ab25d7..deb8854792b8 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ArmCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ArmCollection.cs @@ -24,7 +24,7 @@ protected ArmCollection() /// /// internal ArmCollection(ClientContext clientContext) - : base(clientContext, ResourceIdentifier.RootResourceIdentifier) + : base(clientContext, ResourceIdentifier.Root) { } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/Location.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/Location.cs index 7090c3465499..be98887d307e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/Location.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/Location.cs @@ -301,7 +301,7 @@ private enum NameType /// The display name of the location. /// The display name of the location and its region. internal Location(string name, string displayName, string regionalDisplayName) - :this(name, displayName, regionalDisplayName, GetCanonicalNameFromDisplayName(displayName)) + : this(name, displayName, regionalDisplayName, GetCanonicalNameFromDisplayName(displayName)) { } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/PredefinedTagData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/PredefinedTagData.Serialization.cs index 6a37aed806d5..239938a199f8 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/PredefinedTagData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/PredefinedTagData.Serialization.cs @@ -12,7 +12,7 @@ public partial class PredefinedTagData { internal static PredefinedTagData DeserializeTagDetails(JsonElement element) { - Optional id = default; + Optional id = default; Optional tagName = default; Optional count = default; Optional> values = default; @@ -20,7 +20,7 @@ internal static PredefinedTagData DeserializeTagDetails(JsonElement element) { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("tagName")) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/ProviderData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/ProviderData.Serialization.cs index 590c3a91d4a3..b4ce8b19033b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/ProviderData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/ProviderData.Serialization.cs @@ -19,7 +19,7 @@ public partial class ProviderData { internal static ProviderData DeserializeProvider(JsonElement element) { - Optional id = default; + Optional id = default; Optional @namespace = default; Optional registrationState = default; Optional registrationPolicy = default; @@ -29,7 +29,7 @@ internal static ProviderData DeserializeProvider(JsonElement element) { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("namespace")) @@ -73,7 +73,7 @@ internal static ProviderData DeserializeProvider(JsonElement element) continue; } } - return new ProviderData(id, @namespace.Value, registrationState.Value, registrationPolicy.Value, Optional.ToList(resourceTypes), Optional.ToNullable(providerAuthorizationConsentState)); + return new ProviderData(id.Value, @namespace.Value, registrationState.Value, registrationPolicy.Value, Optional.ToList(resourceTypes), Optional.ToNullable(providerAuthorizationConsentState)); } internal partial class ProviderDataConverter : JsonConverter diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.Serialization.cs index 8fe5a415026f..133e5edc86d1 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.Serialization.cs @@ -23,12 +23,12 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) internal static SubResource DeserializeSubResource(JsonElement element) { - string id = default; + ResourceIdentifier id = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.cs index 27a68a1a5321..fbc274f520dc 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/SubResource.cs @@ -22,7 +22,7 @@ public SubResource() /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - protected internal SubResource(string id) + protected internal SubResource(ResourceIdentifier id) { Id = id; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.Serialization.cs index 01ac59ef3615..ee695870f732 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.Serialization.cs @@ -41,12 +41,12 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) /// Deserialized WritableSubResource object. internal static WritableSubResource DeserializeWritableSubResource(JsonElement element) { - string id = default; + ResourceIdentifier id = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.cs index 4714d5d66c74..7abc3af5897d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/WritableSubResource.cs @@ -22,7 +22,7 @@ public WritableSubResource() /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - protected internal WritableSubResource(string id) + protected internal WritableSubResource(ResourceIdentifier id) { Id = id; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/PredefinedTagData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/PredefinedTagData.cs index 9a9748962866..88dd0362ff62 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/PredefinedTagData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/PredefinedTagData.cs @@ -21,7 +21,7 @@ internal PredefinedTagData() /// The tag name. /// The total number of resources that use the resource tag. When a tag is initially created and has no associated resources, the value is 0. /// The list of tag values. - internal PredefinedTagData(string id, string tagName, PredefinedTagCount count, IReadOnlyList values) : base(id) + internal PredefinedTagData(ResourceIdentifier id, string tagName, PredefinedTagCount count, IReadOnlyList values) : base(id) { TagName = tagName; Count = count; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/ProviderData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/ProviderData.cs index 3b34cacbad63..fdb3af6f0189 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/ProviderData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/ProviderData.cs @@ -31,7 +31,7 @@ public ProviderData() /// The collection of provider resource types. /// The provider authorization consent state. [SerializationConstructor] - internal ProviderData(string id, string @namespace, string registrationState, string registrationPolicy, IReadOnlyList resourceTypes, ProviderAuthorizationConsentState? providerAuthorizationConsentState) : base(id) + internal ProviderData(ResourceIdentifier id, string @namespace, string registrationState, string registrationPolicy, IReadOnlyList resourceTypes, ProviderAuthorizationConsentState? providerAuthorizationConsentState) : base(id) { Namespace = @namespace; RegistrationState = registrationState; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/ManagementGroupData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/ManagementGroupData.cs index 33b2f531f04e..c8ad4f3a6a4f 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/ManagementGroupData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/ManagementGroupData.cs @@ -29,7 +29,7 @@ internal ManagementGroupData() /// The friendly name of the management group. /// The details of a management group. /// The list of children. - internal ManagementGroupData(string id, string type, string name, string tenantId, string displayName, ManagementGroupDetails details, IReadOnlyList children) + internal ManagementGroupData(ResourceIdentifier id, string type, string name, string tenantId, string displayName, ManagementGroupDetails details, IReadOnlyList children) :base(id, name, type) { TenantId = tenantId; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/Models/ManagementGroupData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/Models/ManagementGroupData.Serialization.cs index ec8bc60890d3..10c51419382a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/Models/ManagementGroupData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/ManagementGroup/Models/ManagementGroupData.Serialization.cs @@ -16,7 +16,7 @@ public partial class ManagementGroupData { internal static ManagementGroupData DeserializeManagementGroup(JsonElement element) { - Optional id = default; + Optional id = default; Optional type = default; Optional name = default; Optional tenantId = default; @@ -27,7 +27,7 @@ internal static ManagementGroupData DeserializeManagementGroup(JsonElement eleme { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("type")) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/FeatureData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/FeatureData.cs index 9869e3706648..886c36e664aa 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/FeatureData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/FeatureData.cs @@ -23,7 +23,7 @@ internal FeatureData() /// Properties of the previewed feature. /// The resource ID of the feature. /// The resource type of the feature. - internal FeatureData(string name, FeatureProperties properties, string id, string type) + internal FeatureData(string name, FeatureProperties properties, ResourceIdentifier id, string type) :base(id, name, type) { Properties = properties; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceCollection.cs index 26144daf2638..d941bd3c7f18 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceCollection.cs @@ -39,7 +39,7 @@ internal GenericResourceCollection(ClientContext clientContext, ResourceIdentifi } /// - protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.Root.ResourceType; /// protected override void ValidateResourceType(ResourceIdentifier identifier) @@ -50,11 +50,9 @@ private ResourcesRestOperations RestClient { get { - string subscription; - if (!Id.TryGetSubscriptionId(out subscription)) - { + string subscription = Id.SubscriptionId; + if (subscription == null) subscription = Guid.Empty.ToString(); - } return new ResourcesRestOperations( Diagnostics, @@ -80,7 +78,7 @@ public Response Get(string resourceId, CancellationToken cancel scope.Start(); try { - var apiVersion = GetApiVersion(resourceId, cancellationToken); + var apiVersion = GetApiVersion(new ResourceIdentifier(resourceId), cancellationToken); var result = RestClient.GetById(resourceId, apiVersion, cancellationToken); if (result.Value == null) throw Diagnostics.CreateRequestFailedException(result.GetRawResponse()); @@ -107,7 +105,7 @@ public virtual async Task> GetAsync(string resourceId, scope.Start(); try { - var apiVersion = await GetApiVersionAsync(resourceId, cancellationToken).ConfigureAwait(false); + var apiVersion = await GetApiVersionAsync(new ResourceIdentifier(resourceId), cancellationToken).ConfigureAwait(false); var response = await RestClient.GetByIdAsync(resourceId, apiVersion, cancellationToken).ConfigureAwait(false); if (response.Value == null) throw await Diagnostics.CreateRequestFailedExceptionAsync(response.GetRawResponse()).ConfigureAwait(false); @@ -316,7 +314,7 @@ public virtual ResourceCreateOrUpdateByIdOperation CreateOrUpdate(string resourc scope.Start(); try { - var apiVersion = GetApiVersion(resourceId, cancellationToken); + var apiVersion = GetApiVersion(new ResourceIdentifier(resourceId), cancellationToken); var originalResponse = RestClient.CreateOrUpdateById(resourceId, apiVersion, parameters, cancellationToken); var operation = new ResourceCreateOrUpdateByIdOperation(this, Diagnostics, Pipeline, RestClient.CreateCreateOrUpdateByIdRequest(resourceId, apiVersion, parameters).Request, originalResponse); if (waitForCompletion) @@ -351,7 +349,7 @@ public virtual async Task CreateOrUpdateAsy scope.Start(); try { - var apiVersion = await GetApiVersionAsync(resourceId, cancellationToken).ConfigureAwait(false); + var apiVersion = await GetApiVersionAsync(new ResourceIdentifier(resourceId), cancellationToken).ConfigureAwait(false); var originalResponse = await RestClient.CreateOrUpdateByIdAsync(resourceId, apiVersion, parameters, cancellationToken).ConfigureAwait(false); var operation = new ResourceCreateOrUpdateByIdOperation(this, Diagnostics, Pipeline, RestClient.CreateCreateOrUpdateByIdRequest(resourceId, apiVersion, parameters).Request, originalResponse); if (waitForCompletion) @@ -399,7 +397,7 @@ public virtual Response GetIfExists(string resourceId, Cancella try { - var apiVersion = GetApiVersion(resourceId, cancellationToken); + var apiVersion = GetApiVersion(new ResourceIdentifier(resourceId), cancellationToken); var response = RestClient.GetById(resourceId, apiVersion, cancellationToken); return response.Value == null ? Response.FromValue(null, response.GetRawResponse()) @@ -426,7 +424,7 @@ public virtual async Task> GetIfExistsAsync(string res try { - var apiVersion = await GetApiVersionAsync(resourceId, cancellationToken).ConfigureAwait(false); + var apiVersion = await GetApiVersionAsync(new ResourceIdentifier(resourceId), cancellationToken).ConfigureAwait(false); var response = await RestClient.GetByIdAsync(resourceId, apiVersion, cancellationToken).ConfigureAwait(false); return response.Value == null ? Response.FromValue(null, response.GetRawResponse()) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceData.cs index 1089bb4d49c0..b98b73858afa 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/GenericResourceData.cs @@ -16,7 +16,7 @@ namespace Azure.ResourceManager.Resources public partial class GenericResourceData : TrackedResource { /// Initializes a new instance of GenericResource. - public GenericResourceData(string location) + public GenericResourceData(Location location) : base(location) { } @@ -36,7 +36,7 @@ public GenericResourceData(string location) /// The created time of the resource. This is only present if requested via the $expand query parameter. /// The changed time of the resource. This is only present if requested via the $expand query parameter. /// The provisioning state of the resource. This is only present if requested via the $expand query parameter. - internal GenericResourceData(string id, string name, string type, string location, IDictionary tags, Plan plan, object properties, string kind, string managedBy, Sku sku, ResourceIdentity identity, DateTimeOffset? createdTime, DateTimeOffset? changedTime, string provisioningState) : base(id, name, type, tags, location) + internal GenericResourceData(ResourceIdentifier id, string name, string type, Location location, IDictionary tags, Plan plan, object properties, string kind, string managedBy, Sku sku, ResourceIdentity identity, DateTimeOffset? createdTime, DateTimeOffset? changedTime, string provisioningState) : base(id, name, type, tags, location) { Plan = plan; Properties = properties; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/FeatureData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/FeatureData.Serialization.cs index 539e462bff57..b91adc412244 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/FeatureData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/FeatureData.Serialization.cs @@ -17,7 +17,7 @@ internal static FeatureData DeserializeFeatureResult(JsonElement element) { Optional name = default; Optional properties = default; - Optional id = default; + Optional id = default; Optional type = default; foreach (var property in element.EnumerateObject()) { @@ -38,7 +38,7 @@ internal static FeatureData DeserializeFeatureResult(JsonElement element) } if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("type")) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/GenericResourceData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/GenericResourceData.Serialization.cs index 2f0de90cde58..4acefb956955 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/GenericResourceData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/GenericResourceData.Serialization.cs @@ -79,7 +79,7 @@ internal static GenericResourceData DeserializeGenericResource(JsonElement eleme Optional managedBy = default; Optional sku = default; Optional identity = default; - Optional id = default; + ResourceIdentifier id = default; Optional name = default; Optional type = default; Optional location = default; @@ -163,7 +163,7 @@ internal static GenericResourceData DeserializeGenericResource(JsonElement eleme } if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) @@ -197,7 +197,7 @@ internal static GenericResourceData DeserializeGenericResource(JsonElement eleme continue; } } - return new GenericResourceData(id.Value, name.Value, type.Value, location.Value, Optional.ToDictionary(tags), plan.Value, properties.Value, kind.Value, managedBy.Value, sku.Value, identity.Value, Optional.ToNullable(createdTime), Optional.ToNullable(changedTime), provisioningState.Value); + return new GenericResourceData(id, name.Value, type.Value, location.Value, Optional.ToDictionary(tags), plan.Value, properties.Value, kind.Value, managedBy.Value, sku.Value, identity.Value, Optional.ToNullable(createdTime), Optional.ToNullable(changedTime), provisioningState.Value); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.cs index e7048de50219..f5b79b72089e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.cs @@ -33,7 +33,7 @@ internal LocationExpanded(string id, string subscriptionId, string name, string { Metadata = metadata; Id = id; - ResourceIdentifier subId = id; + ResourceIdentifier subId = new ResourceIdentifier(id); SubscriptionId = subscriptionId ?? subId.SubscriptionId; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/ResourceGroupData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/ResourceGroupData.Serialization.cs index 36f2f0b5edc8..4d14937fad6b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/ResourceGroupData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/ResourceGroupData.Serialization.cs @@ -45,7 +45,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) internal static ResourceGroupData DeserializeResourceGroup(JsonElement element) { - Optional id = default; + Optional id = default; Optional name = default; Optional type = default; Optional properties = default; @@ -56,7 +56,7 @@ internal static ResourceGroupData DeserializeResourceGroup(JsonElement element) { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/SubscriptionData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/SubscriptionData.Serialization.cs index ef6821734d9d..f6ff7b1d011d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/SubscriptionData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/SubscriptionData.Serialization.cs @@ -12,7 +12,7 @@ public partial class SubscriptionData { internal static SubscriptionData DeserializeSubscriptionData(JsonElement element) { - Optional id = default; + Optional id = default; Optional subscriptionId = default; Optional displayName = default; Optional tenantId = default; @@ -25,7 +25,7 @@ internal static SubscriptionData DeserializeSubscriptionData(JsonElement element { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("subscriptionId")) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/TagResourceData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/TagResourceData.Serialization.cs index e8e23043704f..3aadb5af382c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/TagResourceData.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/TagResourceData.Serialization.cs @@ -19,7 +19,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) internal static TagResourceData DeserializeTagsResource(JsonElement element) { - Optional id = default; + Optional id = default; Optional name = default; Optional type = default; Tag properties = default; @@ -27,7 +27,7 @@ internal static TagResourceData DeserializeTagsResource(JsonElement element) { if (property.NameEquals("id")) { - id = property.Value.GetString(); + id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs index e7419433b5d2..9906c6edaf3c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs @@ -30,7 +30,7 @@ public ResourceGroupData(string location) : base(location) /// The location of the resource group. It cannot be changed after the resource group has been created. It must be one of the supported Azure locations. /// The ID of the resource that manages this resource group. /// The tags attached to the resource group. - internal ResourceGroupData(string id, string name, string type, ResourceGroupProperties properties, string location, string managedBy, IDictionary tags) + internal ResourceGroupData(ResourceIdentifier id, string name, string type, ResourceGroupProperties properties, string location, string managedBy, IDictionary tags) : base(id, name, type, tags, location) { Properties = properties; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/RestApiCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/RestApiCollection.cs index 31aaa56e05be..2b32d8bdde02 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/RestApiCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/RestApiCollection.cs @@ -44,7 +44,7 @@ internal RestApiCollection(ClientContext parent, string nameSpace) : base(parent } /// Gets the valid resource type for this object. - protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.Root.ResourceType; /// Gets a list of operations. /// The cancellation token to use. diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs index e36a1d5a59ca..be2949004759 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs @@ -18,7 +18,7 @@ public partial class SubscriptionData : TrackedResource /// The subscription name. /// The tags attached to the subscription. /// The subscription resource type. - internal SubscriptionData(string id, + internal SubscriptionData(ResourceIdentifier id, string displayName, IDictionary tags, string resourceType = "Microsoft.Resources/subscriptions") : base(id, displayName, resourceType, tags, null) @@ -39,7 +39,7 @@ internal SubscriptionData(string id, /// The authorization source of the request. Valid values are one or more combinations of Legacy, RoleBased, Bypassed, Direct and Management. For example, 'Legacy, RoleBased'. /// An array containing the tenants managing the subscription. /// The tags attached to the subscription. - internal SubscriptionData(string id, + internal SubscriptionData(ResourceIdentifier id, string displayName, string subscriptionId, string tenantId, diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TagResourceData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TagResourceData.cs index 4a0a35790354..d006813a0002 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TagResourceData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TagResourceData.cs @@ -28,7 +28,7 @@ public TagResourceData(Tag properties) /// The name of the tags wrapper resource. /// The type of the tags wrapper resource. /// The set of tags. - internal TagResourceData(string id, string name, string type, Tag properties): base(id, name, type) + internal TagResourceData(ResourceIdentifier id, string name, string type, Tag properties): base(id, name, type) { Properties = properties; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Tenant.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Tenant.cs index 15d3c9a7a19e..191d9d7eeb7a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Tenant.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Tenant.cs @@ -36,7 +36,7 @@ protected Tenant() /// The operations object to copy the client parameters from. /// The data model representing the generic azure resource. internal Tenant(ArmResource operations, TenantData tenantData) - : base(operations, ResourceIdentifier.RootResourceIdentifier) + : base(operations, ResourceIdentifier.Root) { _data = tenantData; HasData = true; @@ -52,7 +52,7 @@ internal Tenant(ArmResource operations, TenantData tenantData) /// The base URI of the service. /// The HTTP pipeline for sending and receiving REST requests and responses. internal Tenant(ArmClientOptions options, TokenCredential credential, Uri baseUri, HttpPipeline pipeline) - : base(new ClientContext(options, credential, baseUri, pipeline), ResourceIdentifier.RootResourceIdentifier) + : base(new ClientContext(options, credential, baseUri, pipeline), ResourceIdentifier.Root) { _clientDiagnostics = new ClientDiagnostics(ClientOptions); _providerRestOperations = new ProviderRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Guid.Empty.ToString(), BaseUri); diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TenantCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TenantCollection.cs index e6ab545d5e82..4d56b6e5838c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TenantCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/TenantCollection.cs @@ -37,7 +37,7 @@ internal TenantCollection(ClientContext clientContext) } /// - protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.Root.ResourceType; private TenantsRestOperations RestClient => new TenantsRestOperations(Diagnostics, Pipeline, ClientOptions, BaseUri); diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs index eb744128e130..cb6021f578cf 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs @@ -15,20 +15,18 @@ namespace Azure.ResourceManager /// /// An Azure Resource Manager resource identifier. /// - public class ResourceIdentifier : IEquatable, IComparable + public sealed class ResourceIdentifier : IEquatable, IComparable { private const string RootStringValue = "/"; - - internal const string ProvidersKey = "providers"; - internal const string SubscriptionsKey = "subscriptions"; - internal const string LocationsKey = "locations"; - internal const string ResourceGroupsLowerKey = "resourcegroups"; - internal const string BuiltInResourceNamespace = "Microsoft.Resources"; + private const string ProvidersKey = "providers"; + private const string SubscriptionsKey = "subscriptions"; + private const string LocationsKey = "locations"; + private const string ResourceGroupsLowerKey = "resourcegroups"; /// /// The root of the resource hierarchy. /// - public static readonly ResourceIdentifier RootResourceIdentifier = new ResourceIdentifier(null, Tenant.ResourceType, string.Empty); + public static readonly ResourceIdentifier Root = new ResourceIdentifier(null, Tenant.ResourceType, string.Empty); /// /// For internal use only. @@ -82,7 +80,7 @@ private void Init(ResourceIdentifier parent, ResourceType resourceType, string n { Guid output; if (!Guid.TryParse(name, out output)) - throw new ArgumentOutOfRangeException("resourceId", "Invalid resource id."); + throw new ArgumentOutOfRangeException(nameof(name), $"The GUID for subscription is invalid {name}."); SubscriptionId = name; } @@ -95,7 +93,7 @@ private void Init(ResourceIdentifier parent, ResourceType resourceType, string n if (resourceType == Resources.Provider.ResourceType) Provider = name; - Parent = parent ?? RootResourceIdentifier; + Parent = parent ?? Root; IsChild = isChild; ResourceType = resourceType; Name = name; @@ -110,28 +108,23 @@ private void Init(ResourceIdentifier parent, ResourceType resourceType, string n _ => new ResourceType(parent.ResourceType, resourceTypeName) }; - /// - /// Initializes a new instance of the class. - /// - /// The string representation of a resource Id. - /// The resource identifier. - public static ResourceIdentifier Create(string resourceId) + private static ResourceIdentifier Create(string resourceId) { if (resourceId is null) throw new ArgumentNullException(nameof(resourceId)); if (!resourceId.StartsWith("/", StringComparison.InvariantCultureIgnoreCase)) - throw new ArgumentOutOfRangeException(nameof(resourceId), "Invalid resource id."); + throw new ArgumentOutOfRangeException(nameof(resourceId), "The ResourceIdentifier must start with '/'."); var parts = resourceId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (parts.Count < 2) - throw new ArgumentOutOfRangeException(nameof(resourceId), "Invalid resource id."); + throw new ArgumentOutOfRangeException(nameof(resourceId), "The ResourceIdentifier is too short it must have at least 2 path segments."); var firstToLower = parts[0].ToLowerInvariant(); if (firstToLower != SubscriptionsKey && firstToLower != ProvidersKey) - throw new ArgumentOutOfRangeException(nameof(resourceId), "Invalid resource id."); + throw new ArgumentOutOfRangeException(nameof(resourceId), $"The ResourceIdentifier must start with either '/{SubscriptionsKey}' or '/{ProvidersKey}'."); - return AppendNext(RootResourceIdentifier, parts); + return AppendNext(Root, parts); } private static ResourceIdentifier AppendNext(ResourceIdentifier parent, List parts) @@ -145,11 +138,11 @@ private static ResourceIdentifier AppendNext(ResourceIdentifier parent, List 1 && !string.Equals(parts[0], ProvidersKey, StringComparison.InvariantCultureIgnoreCase)) return AppendNext(new ResourceIdentifier(parent, parts[0], parts[1]), parts.Trim(2)); - throw new ArgumentOutOfRangeException("resourceId", "Invalid resource id."); + throw new ArgumentOutOfRangeException(nameof(parts), "Invalid resource id."); } private object lockObject = new object(); @@ -205,92 +198,44 @@ internal string StringValue /// /// The resource type of the resource. /// - public virtual ResourceType ResourceType { get; internal set; } + public ResourceType ResourceType { get; private set; } /// /// The name of the resource. /// - public virtual string Name { get; internal set; } + public string Name { get; private set; } /// /// The immediate parent containing this resource. /// - public virtual ResourceIdentifier Parent { get; internal set; } + public ResourceIdentifier Parent { get; private set; } /// /// Determines whether this resource is in the same namespace as its parent. /// - internal virtual bool IsChild { get; set; } + internal bool IsChild { get; private set; } /// /// Gets the subscription id if it exists otherwise null. /// - public string SubscriptionId { get; protected set; } + public string SubscriptionId { get; private set; } /// /// Gets the provider namespace if it exists otherwise null. /// - public string Provider { get; protected set; } + public string Provider { get; private set; } /// /// Gets the location if it exists otherwise null. /// - public string Location { get; protected set; } + public Location Location { get; private set; } /// /// The name of the resource group if it exists otherwise null. /// - public string ResourceGroupName { get; protected set; } - - /// - /// Tries to get the resource identifier of the parent of this resource. - /// - /// The resource id of the parent resource. - /// True if the resource has a parent, otherwise false. - public virtual bool TryGetParent(out ResourceIdentifier resourceId) - { - resourceId = Parent; - return resourceId != null; - } - - /// - /// Tries to get the subscription associated with this resource. - /// - /// The resource Id of the subscription for this resource. - /// True if the resource is contained in a subscription, otherwise false. - public virtual bool TryGetSubscriptionId(out string subscriptionId) - { - subscriptionId = SubscriptionId; - return subscriptionId != null; - } + public string ResourceGroupName { get; private set; } - /// - /// Tries to get the resource group associated with this resource. - /// - /// The resource group for this resource. - /// True if the resource is contained in a resource group, otherwise false. - public virtual bool TryGetResourceGroupName(out string resourceGroupName) - { - resourceGroupName = ResourceGroupName; - return resourceGroupName != null; - } - - /// - /// Tries to get the location associated with this resource. - /// - /// The location for thsi resource. - /// True if the resource is contained in a location, otherwise false. - public virtual bool TryGetLocation(out Location location) - { - location = Location; - return location != null; - } - - /// - /// Create the resource id string based on the resource id string of the parent resource. - /// - /// The string representation of this resource id. - internal virtual string ToResourceString() + private string ToResourceString() { if (Parent == null) return string.Empty; @@ -328,7 +273,7 @@ public bool Equals(ResourceIdentifier other) { if (other is null) return false; - return string.Equals(this.ToString(), other.ToString(), StringComparison.InvariantCultureIgnoreCase); + return string.Equals(ToString(), other.ToString(), StringComparison.InvariantCultureIgnoreCase); } /// @@ -342,7 +287,7 @@ public int CompareTo(ResourceIdentifier other) { if (other is null) return 1; - return string.Compare(this.ToString(), other.ToString(), StringComparison.InvariantCultureIgnoreCase); + return string.Compare(ToString(), other.ToString(), StringComparison.InvariantCultureIgnoreCase); } /// @@ -354,7 +299,7 @@ public override bool Equals(object obj) return resourceObj.Equals(this); string stringObj = obj as string; if (!(stringObj is null)) - return this.Equals(ResourceIdentifier.Create(stringObj)); + return Equals(new ResourceIdentifier(stringObj)); return false; } @@ -366,13 +311,7 @@ public override int GetHashCode() } /// - /// Convert a string into a resource identifier. - /// - /// The string representation of a resource identifier. - public static implicit operator ResourceIdentifier(string other) => (other is null ? null : ResourceIdentifier.Create(other)); - - /// - /// Convert a resource identifier to a string + /// Convert a resource identifier to a string. /// /// The resource identifier. public static implicit operator string(ResourceIdentifier id) => id?.ToString(); @@ -380,23 +319,29 @@ public override int GetHashCode() /// /// Operator overloading for '=='. /// - /// Left ResourceIdentifier object to compare. - /// Right ResourceIdentifier object to compare. + /// Left ResourceIdentifier object to compare. + /// Right ResourceIdentifier object to compare. /// public static bool operator ==(ResourceIdentifier id1, ResourceIdentifier id2) { - return ResourceIdentifier.Equals(id1, id2); + if (ReferenceEquals(id1, null)) + return ReferenceEquals(id2, null); + + return id1.Equals(id2); } /// /// Operator overloading for '!='. /// - /// Left ResourceIdentifier object to compare. - /// Right ResourceIdentifier object to compare. + /// Left ResourceIdentifier object to compare. + /// Right ResourceIdentifier object to compare. /// public static bool operator !=(ResourceIdentifier id1, ResourceIdentifier id2) { - return !ResourceIdentifier.Equals(id1, id2); + if (ReferenceEquals(id1, null)) + return !ReferenceEquals(id2, null); + + return !id1.Equals(id2); } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceType.cs index a56fa6ef114c..278f4e849374 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceType.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceType.cs @@ -17,7 +17,7 @@ public sealed class ResourceType : IEquatable, IComparable /// The resource type for the root of the resource hierarchy. /// - public static ResourceType RootResourceType => new ResourceType(string.Empty, string.Empty); + public static ResourceType Root => new ResourceType(string.Empty, string.Empty); /// /// Initializes a new instance of the class. @@ -247,7 +247,7 @@ private void Parse(string resourceIdOrType) // Check if ResourceIdentifier else { - ResourceIdentifier id = resourceIdOrType; + ResourceIdentifier id = new ResourceIdentifier(resourceIdOrType); Type = id.ResourceType.Type; Namespace = id.ResourceType.Namespace; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Samples/Readme.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Samples/Readme.cs index f27c39ddee3e..87c37972eb14 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Samples/Readme.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Samples/Readme.cs @@ -43,13 +43,9 @@ public void CastingToBaseResourceIdentifier() { #region Snippet:Readme_CastToBaseResourceIdentifier string resourceId = "/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/workshop2021-rg/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"; - // Assume we don't know what type of resource id we have we can cast to the base type ResourceIdentifier id = new ResourceIdentifier(resourceId); - string property; - if (id.TryGetSubscriptionId(out property)) - Console.WriteLine($"Subscription: {property}"); - if (id.TryGetResourceGroupName(out property)) - Console.WriteLine($"ResourceGroup: {property}"); + Console.WriteLine($"Subscription: {id.SubscriptionId}"); + Console.WriteLine($"ResourceGroup: {id.ResourceGroupName}"); // Parent is only null when we reach the top of the chain which is a Tenant Console.WriteLine($"Vnet: {id.Parent.Name}"); // Name will never be null diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmClientTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmClientTests.cs index 28b154c2e90c..7c6393bc511d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmClientTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmClientTests.cs @@ -90,14 +90,14 @@ public void GetGenericResourcesOperationsTests() public void GetGenericResourceOperationsSingleIDTests() { string id = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1"; - Assert.AreEqual(id, Client.GetGenericResource(id).Id.StringValue); + Assert.AreEqual(id, Client.GetGenericResource(new ResourceIdentifier(id)).Id.StringValue); } [RecordedTest] public async Task GetGenericResourceOperationsWithSingleValidResource() { string id = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}"; - var genericResourceOperations = Client.GetGenericResource(id); + var genericResourceOperations = Client.GetGenericResource(new ResourceIdentifier(id)); var genericResource = await genericResourceOperations.GetAsync(); Assert.AreEqual(200, genericResource.GetRawResponse().Status); } @@ -106,7 +106,7 @@ public async Task GetGenericResourceOperationsWithSingleValidResource() public void GetGenericResourceOperationsWithSingleInvalidResource() { string id = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1"; - var genericResourceOperations = Client.GetGenericResource(id); + var genericResourceOperations = Client.GetGenericResource(new ResourceIdentifier(id)); RequestFailedException exception = Assert.ThrowsAsync(async () => await genericResourceOperations.GetAsync()); Assert.AreEqual(404, exception.Status); } @@ -155,7 +155,7 @@ public void GetGenericResourceOperationWithNullSetOfIds() [RecordedTest] public void GetGenericResourceOperationWithNullId() { - string x = null; + ResourceIdentifier x = null; Assert.Throws(() => { Client.GetGenericResource(x); }); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/FeatureOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/FeatureOperationsTests.cs index 65a50aa8f76e..fde0bfdfe21a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/FeatureOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/FeatureOperationsTests.cs @@ -18,7 +18,7 @@ public FeatureOperationsTests(bool isAsync) public void NoDataValidation() { ///subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/providers/Microsoft.Features/providers/Microsoft.Compute/features/AHUB - var resource = Client.GetFeature($"/subscriptions/{Guid.NewGuid()}/providers/Microsoft.Features/providers/Microsoft.FakeNamespace/features/fakeFeature"); + var resource = Client.GetFeature(new ResourceIdentifier($"/subscriptions/{Guid.NewGuid()}/providers/Microsoft.Features/providers/Microsoft.FakeNamespace/features/fakeFeature")); Assert.Throws(() => { var data = resource.Data; }); } @@ -34,7 +34,8 @@ public async Task Get() Assert.AreEqual(featureFromCollection.Data.Properties.State, feature.Data.Properties.State); Assert.AreEqual(featureFromCollection.Data.Type, feature.Data.Type); - var ex = Assert.ThrowsAsync(async () => _ = await Client.GetFeature(feature.Data.Id + "x").GetAsync()); + ResourceIdentifier invalidId = new ResourceIdentifier(feature.Data.Id.ToString() + "x"); + var ex = Assert.ThrowsAsync(async () => _ = await Client.GetFeature(invalidId).GetAsync()); Assert.AreEqual(404, ex.Status); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceCollectionTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceCollectionTests.cs index 1f088185a930..b576bc117db4 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceCollectionTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceCollectionTests.cs @@ -151,7 +151,7 @@ public async Task CreateOrUpdate() Assert.ThrowsAsync(async () => _ = await genericResources.CreateOrUpdateAsync(resourceId, null)); Assert.ThrowsAsync(async () => _ = await genericResources.CreateOrUpdateAsync(null, ConstructGenericAvailabilitySet())); var rgId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1"; - Assert.ThrowsAsync(async () => _ = await CreateGenericAvailabilitySetAsync(rgId)); + Assert.ThrowsAsync(async () => _ = await CreateGenericAvailabilitySetAsync(new ResourceIdentifier(rgId))); } [TestCase] @@ -182,7 +182,7 @@ public async Task StartCreateOrUpdate() var rgId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1"; Assert.ThrowsAsync(async () => { - var createOp = await StartCreateGenericAvailabilitySetAsync(rgId); + var createOp = await StartCreateGenericAvailabilitySetAsync(new ResourceIdentifier(rgId)); _ = await createOp.WaitForCompletionAsync(); }); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceOperationsTests.cs index bb3b76cd1599..68dd202e3a60 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/GenericResourceOperationsTests.cs @@ -23,7 +23,7 @@ public async Task GetGenericsConfirmException() var rgName = Recording.GenerateAssetName("testrg"); _ = await (await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(rgName); var asetid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{rgName}/providers/Microsoft.Compute/availabilitySets/testavset"; - var genericResourceOperations = Client.GetGenericResource(asetid); + var genericResourceOperations = Client.GetGenericResource(new ResourceIdentifier(asetid)); RequestFailedException exception = Assert.ThrowsAsync(async () => await genericResourceOperations.GetAsync()); Assert.AreEqual(404, exception.Status); Assert.True(exception.Message.Contains("ResourceNotFound")); @@ -36,7 +36,7 @@ public async Task GetGenericsBadNameSpace() var rgName = Recording.GenerateAssetName("testrg"); _ = await (await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(rgName); var asetid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{rgName}/providers/Microsoft.NotAValidNameSpace123/availabilitySets/testavset"; - var genericResourceOperations = Client.GetGenericResource(asetid); + var genericResourceOperations = Client.GetGenericResource(new ResourceIdentifier(asetid)); InvalidOperationException exception = Assert.ThrowsAsync(async () => await genericResourceOperations.GetAsync()); Assert.IsTrue(exception.Message.Equals($"An invalid resouce id was given {asetid}")); } @@ -80,7 +80,7 @@ public async Task Delete() Assert.DoesNotThrowAsync(async () => await aset.DeleteAsync()); var fakeId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1"; - Assert.ThrowsAsync(async () => _ = await CreateGenericAvailabilitySetAsync(fakeId)); + Assert.ThrowsAsync(async () => _ = await CreateGenericAvailabilitySetAsync(new ResourceIdentifier(fakeId))); } [TestCase] @@ -101,7 +101,7 @@ public async Task StartDelete() var fakeId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1"; Assert.ThrowsAsync(async () => { - var createOp = await StartCreateGenericAvailabilitySetAsync(fakeId); + var createOp = await StartCreateGenericAvailabilitySetAsync(new ResourceIdentifier(fakeId)); _ = await createOp.WaitForCompletionAsync(); }); } @@ -134,7 +134,8 @@ public async Task Get() AssertAreEqual(aset, aset2); - var ex = Assert.ThrowsAsync(async () => _ = await Client.GetGenericResource(aset2.Id + "x").GetAsync()); + ResourceIdentifier fakeId = new ResourceIdentifier(aset2.Id.ToString() + "x"); + var ex = Assert.ThrowsAsync(async () => _ = await Client.GetGenericResource(new ResourceIdentifier(fakeId)).GetAsync()); Assert.AreEqual(404, ex.Status); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs index e79c73602ff1..983927a35a6c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs @@ -20,7 +20,6 @@ public async Task VerifyMetadata() { Assert.IsNotNull(loc.Metadata); Assert.IsNotNull(loc.SubscriptionId); - Assert.IsNotNull(loc.CanonicalName); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ManagementGroupOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ManagementGroupOperationsTests.cs index 9bf22e054ba4..93eca4935168 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ManagementGroupOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ManagementGroupOperationsTests.cs @@ -32,7 +32,8 @@ public async Task Get() { var mgmtGroup = await Client.GetManagementGroup(_mgmtGroup.Id).GetAsync(); CompareMgmtGroups(_mgmtGroup, mgmtGroup.Value); - RequestFailedException ex = Assert.ThrowsAsync(async () => _ = await Client.GetManagementGroup(_mgmtGroup.Id + "x").GetAsync()); + ResourceIdentifier fakeId = new ResourceIdentifier(_mgmtGroup.Id.ToString() + "x"); + RequestFailedException ex = Assert.ThrowsAsync(async () => _ = await Client.GetManagementGroup(new ResourceIdentifier(fakeId)).GetAsync()); Assert.AreEqual(403, ex.Status); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/PreDefinedTagOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/PreDefinedTagOperationsTests.cs index 6fffe3fffb63..c35360577f12 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/PreDefinedTagOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/PreDefinedTagOperationsTests.cs @@ -32,7 +32,7 @@ public void NoDataValidation() { _predefinedTag = null; ///subscriptions/0accec26-d6de-4757-8e74-d080f38eaaab/tagNames/platformsettings.host_environment.service.platform_optedin_for_rootcerts - var resource = Client.GetPreDefinedTag($"/subscriptions/{Guid.NewGuid()}/tagNames/fakeTagName"); + var resource = Client.GetPreDefinedTag(new ResourceIdentifier($"/subscriptions/{Guid.NewGuid()}/tagNames/fakeTagName")); Assert.Throws(() => { var data = resource.Data; }); } @@ -42,10 +42,9 @@ public async Task GetTagsOperation() { _predefinedTag = null; Subscription subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); - var operation = Client.GetPreDefinedTag($"/subscriptions/{subscription.Id.SubscriptionId}/tagNames/fakeTagName"); - string subscriptionId; - Assert.IsTrue(operation.Id.TryGetSubscriptionId(out subscriptionId)); - Assert.AreEqual(subscriptionId, TestEnvironment.SubscriptionId); + var operation = Client.GetPreDefinedTag(new ResourceIdentifier($"/subscriptions/{subscription.Id.SubscriptionId}/tagNames/fakeTagName")); + Assert.NotNull(operation.Id.SubscriptionId); + Assert.AreEqual(operation.Id.SubscriptionId, TestEnvironment.SubscriptionId); } [TestCase] diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ProviderOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ProviderOperationsTests.cs index 9db007bb53c5..ec970cc44692 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ProviderOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ProviderOperationsTests.cs @@ -18,7 +18,7 @@ public ProviderOperationsTests(bool isAsync) public void NoDataValidation() { ///subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/providers/microsoft.insights - var resource = Client.GetProvider($"/subscriptions/{Guid.NewGuid()}/providers/microsoft.FakeNamespace"); + var resource = Client.GetProvider(new ResourceIdentifier($"/subscriptions/{Guid.NewGuid()}/providers/microsoft.FakeNamespace")); Assert.Throws(() => { var data = resource.Data; }); } @@ -31,7 +31,8 @@ public async Task Get() Provider result = response.Value; Assert.IsNotNull(result); - var ex = Assert.ThrowsAsync(async () => await Client.GetProvider(result.Data.Id + "x").GetAsync()); + ResourceIdentifier fakeId = new ResourceIdentifier(result.Data.Id.ToString() + "x"); + var ex = Assert.ThrowsAsync(async () => await Client.GetProvider(new ResourceIdentifier(fakeId)).GetAsync()); Assert.AreEqual(404, ex.Status); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ResourceGroupOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ResourceGroupOperationsTests.cs index cf5985583533..ebac45fb4d8e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ResourceGroupOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ResourceGroupOperationsTests.cs @@ -23,7 +23,7 @@ public ResourceGroupOperationsTests(bool isAsync) public void NoDataValidation() { ////subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/resourceGroups/myRg - var resource = Client.GetResourceGroup($"/subscriptions/{Guid.NewGuid()}/resourceGroups/fakeRg"); + var resource = Client.GetResourceGroup(new ResourceIdentifier($"/subscriptions/{Guid.NewGuid()}/resourceGroups/fakeRg")); Assert.Throws(() => { var data = resource.Data; }); } @@ -50,18 +50,13 @@ public async Task StartDeleteRg() await deleteOp.UpdateStatusAsync(); await deleteOp.WaitForCompletionResponseAsync(); await deleteOp.WaitForCompletionResponseAsync(TimeSpan.FromSeconds(2)); - - var rgOp2 = await subscription.GetResourceGroups().CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"), new ResourceGroupData(Location.WestUS2)); - ResourceGroup rg2 = rgOp.Value; - rg2.Id.Name = null; - Assert.ThrowsAsync(async () => _ = await rg2.DeleteAsync(false)); } [TestCase] [RecordedTest] public void StartDeleteNonExistantRg() { - var rgOp = InstrumentClientExtension(Client.GetResourceGroup($"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/fake")); + var rgOp = InstrumentClientExtension(Client.GetResourceGroup(new ResourceIdentifier($"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/fake"))); var deleteOpTask = rgOp.DeleteAsync(false); RequestFailedException exception = Assert.ThrowsAsync(async () => await deleteOpTask); Assert.AreEqual(404, exception.Status); @@ -83,10 +78,8 @@ public async Task Get() Assert.AreEqual(rg1.Data.ManagedBy, rg2.Data.ManagedBy); Assert.AreEqual(rg1.Data.Tags, rg2.Data.Tags); - rg1.Id.Name = null; - Assert.ThrowsAsync(async () => _ = await rg1.GetAsync()); - - var ex = Assert.ThrowsAsync(async () => await Client.GetResourceGroup(rg1.Data.Id + "x").GetAsync()); + ResourceIdentifier fakeId = new ResourceIdentifier(rg1.Data.Id.ToString() + "x"); + var ex = Assert.ThrowsAsync(async () => await Client.GetResourceGroup(new ResourceIdentifier(fakeId)).GetAsync()); Assert.AreEqual(404, ex.Status); } @@ -112,9 +105,6 @@ public async Task Update() Assert.AreEqual(rg1.Data.Tags, rg2.Data.Tags); Assert.ThrowsAsync(async () => _ = await rg1.UpdateAsync(null)); - - rg1.Id.Name = null; - Assert.ThrowsAsync(async () => _ = await rg1.UpdateAsync(parameters)); } [TestCase] @@ -134,9 +124,6 @@ public async Task StartExportTemplate() var expOp = await rg.ExportTemplateAsync(null, false); _ = await expOp.WaitForCompletionAsync(); }); - - rg.Id.Name = null; - Assert.ThrowsAsync(async () => _ = await rg.ExportTemplateAsync(parameters, false)); } [TestCase] diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionOperationsTests.cs index f679837a6014..69489f8044e8 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionOperationsTests.cs @@ -24,7 +24,7 @@ public SubscriptionOperationsTests(bool isAsync) public void NoDataValidation() { ///subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c - var resource = Client.GetSubscription($"/subscriptions/{Guid.NewGuid()}"); + var resource = Client.GetSubscription(new ResourceIdentifier($"/subscriptions/{Guid.NewGuid()}")); Assert.Throws(() => { var data = resource.Data; }); } @@ -151,7 +151,7 @@ public async Task TestGetSubscription() var subscription = await (await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetAsync(); Assert.NotNull(subscription.Value.Data.Id); - RequestFailedException ex = Assert.ThrowsAsync(async () => _ = await Client.GetSubscription($"/subscriptions/{new Guid()}").GetAsync()); + RequestFailedException ex = Assert.ThrowsAsync(async () => _ = await Client.GetSubscription(new ResourceIdentifier($"/subscriptions/{new Guid()}")).GetAsync()); Assert.AreEqual(404, ex.Status); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/GenericResourceDataTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/GenericResourceDataTests.cs index 658552211ca2..4c20ef76710e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/GenericResourceDataTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/GenericResourceDataTests.cs @@ -19,7 +19,7 @@ public class GenericResourceDataTests public void SerializationTestType1() { string expected = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "Unit", "TestAssets", "GenericResourceData", "SerializationTestType1.json")); - ResourceIdentifier id = Id; + ResourceIdentifier id = new ResourceIdentifier(Id); Plan plan = new Plan("NameForPlan", "PublisherForPlan", "ProductForPlan", "PromotionCodeForPlan", "VersionForPlan"); Sku sku = new Sku("NameForSku", SkuTier.Basic, "SizeForSku", "FamilyForSku", 15464547); GenericResourceData data = new GenericResourceData(id, id.Name, id.ResourceType, Location.EastUS, new Dictionary(), plan, null, "KindForResource", "ManagedByForResource", sku, null, null, null, null); @@ -32,7 +32,7 @@ public void SerializationTestType1() public void SerializationTestType2() { string expected = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "Unit", "TestAssets", "GenericResourceData", "SerializationTestType2.json")); - ResourceIdentifier id = Id; + ResourceIdentifier id = new ResourceIdentifier(Id); var plan = new Plan("NameForPlan", "PublisherForPlan", "ProductForPlan", "PromotionCodeForPlan", "VersionForPlan"); var kind = "KindForResource"; var managedBy = "ManagedByForResource"; @@ -49,7 +49,7 @@ public void SerializationTestType2() public void InvalidSerializationTest() { string expected = "{\"properties\":{\"location\":\"eastus\",\"tags\":{}}}"; - ResourceIdentifier id = Id; + ResourceIdentifier id = new ResourceIdentifier(Id); GenericResourceData data = new GenericResourceData(id, id.Name, id.ResourceType, Location.EastUS, new Dictionary(), null, null, null, null, null, null, null, null, null); var json = JsonHelper.SerializePropertiesToString(data); diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/IdentityTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/IdentityTests.cs index 6d4e8a567313..67e4a6daafec 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/IdentityTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/IdentityTests.cs @@ -34,13 +34,13 @@ public void CheckUserTrueConstructor(string resourceID, bool invalidParameter) if (invalidParameter) { if (resourceID is null) - Assert.Throws(() => { dict1[resourceID] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); + Assert.Throws(() => { dict1[new ResourceIdentifier(resourceID)] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); else - Assert.Throws(() => { dict1[resourceID] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); + Assert.Throws(() => { dict1[new ResourceIdentifier(resourceID)] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); } else { - dict1[resourceID] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict1[new ResourceIdentifier(resourceID)] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity = new ResourceIdentity(dict1, true); Assert.IsNotNull(identity); Assert.IsNotNull(identity.UserAssignedIdentities); @@ -62,13 +62,13 @@ public void CheckUserFalseConstructor(string resourceID, bool invalidParameter) if (invalidParameter) { if (resourceID is null) - Assert.Throws(() => { dict1[resourceID] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); + Assert.Throws(() => { dict1[new ResourceIdentifier(resourceID)] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); else - Assert.Throws(() => { dict1[resourceID] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); + Assert.Throws(() => { dict1[new ResourceIdentifier(resourceID)] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); }); } else { - dict1[resourceID] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict1[new ResourceIdentifier(resourceID)] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity = new ResourceIdentity(system, dict1); Assert.IsNotNull(identity); @@ -100,7 +100,7 @@ public void EqualsNullOtherTest() public void EqualsReferenceTestTrue() { var dict1 = new Dictionary(); - dict1["/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict1[new ResourceIdentifier("/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity = new ResourceIdentity(system, dict1); ResourceIdentity identity1 = identity; @@ -111,11 +111,11 @@ public void EqualsReferenceTestTrue() public void EqualsTestTrue() { var dict1 = new Dictionary(); - dict1["/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict1[new ResourceIdentifier("/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity = new ResourceIdentity(system, dict1); var dict2 = new Dictionary(); - dict2["/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict2[new ResourceIdentifier("/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system2 = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity1 = new ResourceIdentity(system2, dict2); Assert.IsTrue(identity.Equals(identity1)); @@ -125,11 +125,11 @@ public void EqualsTestTrue() public void EqualsTestFalse() { var dict1 = new Dictionary(); - dict1["/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict1[new ResourceIdentifier("/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity = new ResourceIdentity(system, dict1); var dict2 = new Dictionary(); - dict2["/subscriptions/d96407f5-db8f-4325-b582-84ad21310bd8/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict2[new ResourceIdentifier("/subscriptions/d96407f5-db8f-4325-b582-84ad21310bd8/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system2 = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity1 = new ResourceIdentity(system2, dict2); Assert.IsFalse(identity.Equals(identity1)); @@ -139,11 +139,11 @@ public void EqualsTestFalse() public void EqualsTestFalseSameKey() { var dict1 = new Dictionary(); - dict1["/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); + dict1[new ResourceIdentifier("/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(Guid.Empty, Guid.Empty); var system = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity = new ResourceIdentity(system, dict1); var dict2 = new Dictionary(); - dict2["/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest"] = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), Guid.Empty); + dict2[new ResourceIdentifier("/subscriptions/1ab27dfb-d2ee-4283-b1e3-550deaebb8e4/resourceGroups/tester/providers/Microsoft.Web/sites/autotest")] = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), Guid.Empty); var system2 = new SystemAssignedIdentity(Guid.Empty, Guid.Empty); ResourceIdentity identity1 = new ResourceIdentity(system2, dict2); Assert.IsFalse(identity.Equals(identity1)); @@ -281,7 +281,7 @@ public void TestSerializerValidSystemAndUser() SystemAssignedIdentity systemAssignedIdentity = new SystemAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), new Guid("de29bab1-49e1-4705-819b-4dfddceaaa98")); UserAssignedIdentity userAssignedIdentity = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), new Guid("de29bab1-49e1-4705-819b-4dfddceaaa98")); var dict1 = new Dictionary(); - dict1["/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport"] = userAssignedIdentity; + dict1[new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport")] = userAssignedIdentity; ResourceIdentity identity = new ResourceIdentity(systemAssignedIdentity, dict1); string system = "\"principalId\":\"de29bab1-49e1-4705-819b-4dfddceaaa98\",\"tenantId\":\"72f988bf-86f1-41af-91ab-2d7cd011db47\""; string user = "{}"; @@ -302,8 +302,8 @@ public void TestSerializerValidSystemAndMultUser() UserAssignedIdentity userAssignedIdentity1 = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), new Guid("de29bab1-49e1-4705-819b-4dfddceaaa98")); UserAssignedIdentity userAssignedIdentity2 = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011cb47"), new Guid("de29bab1-49e1-4705-819b-4dfddcebaa98")); var dict1 = new Dictionary(); - dict1["/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport1"] = userAssignedIdentity1; - dict1["/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport2"] = userAssignedIdentity2; + dict1[new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport1")] = userAssignedIdentity1; + dict1[new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport2")] = userAssignedIdentity2; ResourceIdentity identity = new ResourceIdentity(systemAssignedIdentity, dict1); string system = "\"principalId\":\"de29bab1-49e1-4705-819b-4dfddceaaa98\",\"tenantId\":\"72f988bf-86f1-41af-91ab-2d7cd011db47\""; string emptyUser = "{}"; @@ -337,7 +337,7 @@ public void TestSerializerValidUserEmptySystem() { UserAssignedIdentity userAssignedIdentity = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), new Guid("de29bab1-49e1-4705-819b-4dfddceaaa98")); var dict1 = new Dictionary(); - dict1["/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport"] = userAssignedIdentity; + dict1[new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport")] = userAssignedIdentity; ResourceIdentity identity = new ResourceIdentity(dict1, true); string system = "\"principalId\":\"null\",\"tenantId\":\"null\""; string user = "{}"; @@ -356,7 +356,7 @@ public void TestSerializerValidUserNullSystem() { UserAssignedIdentity userAssignedIdentity = new UserAssignedIdentity(new Guid("72f988bf-86f1-41af-91ab-2d7cd011db47"), new Guid("de29bab1-49e1-4705-819b-4dfddceaaa98")); var dict1 = new Dictionary(); - dict1["/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport"] = userAssignedIdentity; + dict1[new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/nbhatia_test/providers/Microsoft.Web/sites/autoreport")] = userAssignedIdentity; ResourceIdentity identity = new ResourceIdentity(dict1, false); string user = "{}"; string expected = "{\"identity\":{" + diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationResourceIdentifierTests.cs index d3a08735cad4..88f1f07b161a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationResourceIdentifierTests.cs @@ -17,7 +17,7 @@ public void LocationFromDiffNamespaceWithChildResouce() string resourceId = $"{LocationInDifferentNamespace}/publishers/128technology"; var id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); - Assert.AreEqual("westus2", id.Location); + Assert.AreEqual("westus2", id.Location.ToString()); Assert.AreEqual("db1ab6f0-4769-4b27-930e-01e2ef9c123c", id.SubscriptionId); Assert.AreEqual("Microsoft.Compute/locations/publishers", id.ResourceType.ToString()); Assert.AreEqual("128technology", id.Name); @@ -32,7 +32,7 @@ public void LocationWithChildResouce() string resourceId = $"{LocationBaseResourceId}/myResourceType/myResourceName"; var id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); - Assert.AreEqual("westus2", id.Location); + Assert.AreEqual("westus2", id.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", id.SubscriptionId); Assert.AreEqual("Microsoft.Resources/subscriptions/locations/myResourceType", id.ResourceType.ToString()); Assert.AreEqual("myResourceName", id.Name); @@ -47,7 +47,7 @@ public void LocationWithChildSingleton() string resourceId = $"{LocationBaseResourceId}/myResourceType/myResourceName/mySingletonResource"; var id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); - Assert.AreEqual("westus2", id.Location); + Assert.AreEqual("westus2", id.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", id.SubscriptionId); Assert.AreEqual("Microsoft.Resources/subscriptions/locations/myResourceType/mySingletonResource", id.ResourceType.ToString()); Assert.AreEqual(string.Empty, id.Name); @@ -56,7 +56,7 @@ public void LocationWithChildSingleton() var parentId = id.Parent; Assert.AreEqual($"{LocationBaseResourceId}/myResourceType/myResourceName", parentId.ToString()); - Assert.AreEqual("westus2", parentId.Location); + Assert.AreEqual("westus2", parentId.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", parentId.SubscriptionId); Assert.AreEqual("Microsoft.Resources/subscriptions/locations/myResourceType", parentId.ResourceType.ToString()); Assert.AreEqual("myResourceName", parentId.Name); @@ -72,7 +72,7 @@ public void LocationWithProviderResource() string resourceId = $"{LocationBaseResourceId}/providers/myProvider/myResourceType/myResourceName"; var id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); - Assert.AreEqual("westus2", id.Location); + Assert.AreEqual("westus2", id.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", id.SubscriptionId); Assert.AreEqual("myProvider/myResourceType", id.ResourceType.ToString()); Assert.AreEqual("myResourceName", id.Name); @@ -88,7 +88,7 @@ public void LocationWithProviderResourceWithChild() string resourceId = $"{LocationBaseResourceId}/providers/myProvider/myResourceType/myResourceName/myChildResource/myChildResourceName"; var id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); - Assert.AreEqual("westus2", id.Location); + Assert.AreEqual("westus2", id.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", id.SubscriptionId); Assert.AreEqual("myProvider/myResourceType/myChildResource", id.ResourceType.ToString()); Assert.AreEqual("myChildResourceName", id.Name); @@ -97,7 +97,7 @@ public void LocationWithProviderResourceWithChild() var parentId = id.Parent; Assert.AreEqual($"{LocationBaseResourceId}/providers/myProvider/myResourceType/myResourceName", parentId.ToString()); - Assert.AreEqual("westus2", parentId.Location); + Assert.AreEqual("westus2", parentId.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", parentId.SubscriptionId); Assert.AreEqual("myProvider/myResourceType", parentId.ResourceType.ToString()); Assert.AreEqual("myResourceName", parentId.Name); @@ -113,7 +113,7 @@ public void LocationWithExtensionResource() string resourceId = $"{LocationBaseResourceId}/providers/myProvider/myResourceType/myResourceName/providers/mySecondNamespace/myChildResource/myChildResourceName"; var id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); - Assert.AreEqual("westus2", id.Location); + Assert.AreEqual("westus2", id.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", id.SubscriptionId); Assert.AreEqual("mySecondNamespace/myChildResource", id.ResourceType.ToString()); Assert.AreEqual("myChildResourceName", id.Name); @@ -122,7 +122,7 @@ public void LocationWithExtensionResource() var parentId = id.Parent; Assert.AreEqual($"{LocationBaseResourceId}/providers/myProvider/myResourceType/myResourceName", parentId.ToString()); - Assert.AreEqual("westus2", parentId.Location); + Assert.AreEqual("westus2", parentId.Location.ToString()); Assert.AreEqual("17fecd63-33d8-4e43-ac6f-0aafa111b38d", parentId.SubscriptionId); Assert.AreEqual("myProvider/myResourceType", parentId.ResourceType.ToString()); Assert.AreEqual("myResourceName", parentId.Name); @@ -135,18 +135,15 @@ public void LocationWithExtensionResource() [Test] public void TryGetPropertiesForLocationResource() { - ResourceIdentifier id1 = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2/providers/Contoso.Widgets/widgets/myWidget"; - string subscription; - Assert.AreEqual(true, id1.TryGetSubscriptionId(out subscription)); - Assert.AreEqual("6b085460-5f21-477e-ba44-1035046e9101", subscription); - Location location; - Assert.AreEqual(true, id1.TryGetLocation(out location)); - Assert.AreEqual(Location.WestUS2, location); - Assert.AreEqual(false, id1.TryGetResourceGroupName(out _)); - ResourceIdentifier expectedId = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2"; - ResourceIdentifier parentId; - Assert.AreEqual(true, id1.TryGetParent(out parentId)); - Assert.IsTrue(expectedId.Equals(parentId)); + ResourceIdentifier id1 = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2/providers/Contoso.Widgets/widgets/myWidget"); + Assert.NotNull(id1.SubscriptionId); + Assert.AreEqual("6b085460-5f21-477e-ba44-1035046e9101", id1.SubscriptionId); + Assert.NotNull(id1.Location); + Assert.AreEqual(Location.WestUS2, id1.Location); + Assert.Null(id1.ResourceGroupName); + ResourceIdentifier expectedId = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2"); + Assert.NotNull(id1.Parent); + Assert.IsTrue(expectedId.Equals(id1.Parent)); } [TestCase(LocationResourceId, "Microsoft.Authorization", "roleAssignments", "MyRoleAssignemnt")] @@ -162,7 +159,7 @@ public void TryGetPropertiesForLocationResource() public void TestAppendLocationProviderResource(string resourceId, string providerNamespace, string resourceTypeName, string resourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (providerNamespace is null || resourceTypeName is null || resourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendProviderResource(providerNamespace, resourceTypeName, resourceName)); else if (string.IsNullOrWhiteSpace(providerNamespace) || string.IsNullOrWhiteSpace(resourceTypeName) || string.IsNullOrWhiteSpace(resourceName)) @@ -185,7 +182,7 @@ public void TestAppendLocationProviderResource(string resourceId, string provide [TestCase(LocationResourceId, "wheels", "wheel1/wheel2")] public void TestAppendLocationChildResource(string resourceId, string childTypeName, string childResourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (childTypeName is null || childResourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendChildResource(childTypeName, childResourceName)); else if (string.IsNullOrWhiteSpace(childTypeName) || string.IsNullOrWhiteSpace(childResourceName)) diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs index a52f4a084a36..f189de39e44a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs @@ -216,23 +216,23 @@ public void CanCastLocationToString(string name, string expected) Assert.AreEqual(expected, strLocation); } - [TestCase ("West US", "West US")] - [TestCase ("west-us", "West US")] - [TestCase ("westus", "West US")] - [TestCase ("Private Cloud", "Private Cloud")] - [TestCase ("private-cloud", "Private Cloud")] - [TestCase ("privatecloud", "privatecloud")] - [TestCase ("1$S#@$%^", "1$S#@$%^")] - [TestCase ("","")] - [TestCase (" ", " ")] - [TestCase (null,null)] + [TestCase("West US", "West US")] + [TestCase("west-us", "West US")] + [TestCase("westus", "West US")] + [TestCase("Private Cloud", "Private Cloud")] + [TestCase("private-cloud", "Private Cloud")] + [TestCase("privatecloud", "privatecloud")] + [TestCase("1$S#@$%^", "1$S#@$%^")] + [TestCase("", "")] + [TestCase(" ", " ")] + [TestCase(null, null)] public void CanCastStringToLocation(string name, string expected) { Location location1 = name; if (name == null) - Assert.Throws(()=> { string x = location1.DisplayName; }); + Assert.Throws(() => { string x = location1.DisplayName; }); else - Assert.AreEqual(expected, location1.DisplayName); + Assert.AreEqual(expected, location1.DisplayName); } [Test] diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs index 8ca6b6c6644d..11403762a1cb 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs @@ -16,7 +16,7 @@ public class ResourceGroupResourceIdentifierTests : ResourceIdentifierTests public void CanParseRPIds(string subscription, string resourceGroup, string provider, string type, string name) { var resourceId = $"/subscriptions/{subscription}/resourceGroups/{Uri.EscapeDataString(resourceGroup)}/providers/{provider}/{type}/{Uri.EscapeDataString(name)}"; - ResourceIdentifier subject = resourceId; + ResourceIdentifier subject = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, subject.ToString()); Assert.AreEqual(subscription, subject.SubscriptionId); Assert.AreEqual(resourceGroup, Uri.UnescapeDataString(subject.ResourceGroupName)); @@ -29,7 +29,7 @@ public void CanParseRPIds(string subscription, string resourceGroup, string prov public void CanParseProxyResource(string subscription, string rg, string resourceNamespace, string resource, string type) { string id = $"/subscriptions/{subscription}/resourceGroups/{rg}/providers/{resourceNamespace}/{resource}"; - ResourceIdentifier subject = id; + ResourceIdentifier subject = new ResourceIdentifier(id); Assert.AreEqual(id, subject.ToString()); Assert.AreEqual(subscription, subject.SubscriptionId); Assert.AreEqual(resourceNamespace, subject.ResourceType.Namespace); @@ -39,7 +39,7 @@ public void CanParseProxyResource(string subscription, string rg, string resourc [Test] public void CanParseResourceGroups() { - ResourceIdentifier subject = "/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575/resourceGroups/myRg"; + ResourceIdentifier subject = new ResourceIdentifier("/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575/resourceGroups/myRg"); Assert.AreEqual("/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575/resourceGroups/myRg", subject.ToString()); Assert.AreEqual("0c2f6471-1bf0-4dda-aec3-cb9272f09575", subject.SubscriptionId); Assert.AreEqual("myRg", subject.ResourceGroupName); @@ -53,7 +53,7 @@ public void CanParseResourceGroups() public void CanParseChildResources(string parentName, string name) { var resourceId = $"/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575/resourceGroups/myRg/providers/Microsoft.Network/virtualNetworks/{Uri.EscapeDataString(parentName)}/subnets/{Uri.EscapeDataString(name)}"; - ResourceIdentifier subject = resourceId; + ResourceIdentifier subject = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, subject.ToString()); Assert.AreEqual("0c2f6471-1bf0-4dda-aec3-cb9272f09575", subject.SubscriptionId); Assert.AreEqual("myRg", Uri.UnescapeDataString(subject.ResourceGroupName)); @@ -63,7 +63,7 @@ public void CanParseChildResources(string parentName, string name) Assert.AreEqual(name, Uri.UnescapeDataString(subject.Name)); // check parent type parsing - ResourceIdentifier parentResource = $"/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575/resourceGroups/myRg/providers/Microsoft.Network/virtualNetworks/{Uri.EscapeDataString(parentName)}"; + ResourceIdentifier parentResource = new ResourceIdentifier($"/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575/resourceGroups/myRg/providers/Microsoft.Network/virtualNetworks/{Uri.EscapeDataString(parentName)}"); Assert.AreEqual(parentResource, subject.Parent); Assert.AreEqual(parentResource.ToString(), subject.Parent.ToString()); Assert.AreEqual("0c2f6471-1bf0-4dda-aec3-cb9272f09575", ((ResourceIdentifier)subject.Parent).SubscriptionId); @@ -95,18 +95,15 @@ public void EqualsObj() [Test] public void TryGetPropertiesForResourceGroupResource() { - ResourceIdentifier id1 = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg/providers/Contoso.Widgets/widgets/myWidget"; - string subscription; - Assert.AreEqual(true, id1.TryGetSubscriptionId(out subscription)); - Assert.AreEqual("6b085460-5f21-477e-ba44-1035046e9101", subscription); - Assert.AreEqual(false, id1.TryGetLocation(out _)); - string resourceGroupName; - Assert.AreEqual(true, id1.TryGetResourceGroupName(out resourceGroupName)); - Assert.AreEqual("myRg", resourceGroupName); - ResourceIdentifier expectedId = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg"; - ResourceIdentifier parentId; - Assert.AreEqual(true, id1.TryGetParent(out parentId)); - Assert.IsTrue(expectedId.Equals(parentId)); + ResourceIdentifier id1 = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg/providers/Contoso.Widgets/widgets/myWidget"); + Assert.NotNull(id1.SubscriptionId); + Assert.AreEqual("6b085460-5f21-477e-ba44-1035046e9101", id1.SubscriptionId); + Assert.Null(id1.Location); + Assert.NotNull(id1.ResourceGroupName); + Assert.AreEqual("myRg", id1.ResourceGroupName); + ResourceIdentifier expectedId = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg"); + Assert.NotNull(id1.Parent); + Assert.IsTrue(expectedId.Equals(id1.Parent)); } [TestCase(ResourceGroupResourceId, "Microsoft.Authorization", "roleAssignments", "MyRoleAssignemnt")] @@ -122,7 +119,7 @@ public void TryGetPropertiesForResourceGroupResource() public void TestAppendResourceGroupProviderResource(string resourceId, string providerNamespace, string resourceTypeName, string resourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (providerNamespace is null || resourceTypeName is null || resourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendProviderResource(providerNamespace, resourceTypeName, resourceName)); else if (string.IsNullOrWhiteSpace(providerNamespace) || string.IsNullOrWhiteSpace(resourceTypeName) || string.IsNullOrWhiteSpace(resourceName)) @@ -146,7 +143,7 @@ public void TestAppendResourceGroupProviderResource(string resourceId, string pr [TestCase(ResourceGroupResourceId, "wheels", "wheel1/wheel2")] public void TestAppendResourceGroupChildResource(string resourceId, string childTypeName, string childResourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (childTypeName is null || childResourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendChildResource(childTypeName, childResourceName)); else if (string.IsNullOrWhiteSpace(childTypeName) || string.IsNullOrWhiteSpace(childResourceName)) diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierExtensionsTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierExtensionsTests.cs index 1ef12f9fde7f..ab4a2330c0c4 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierExtensionsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierExtensionsTests.cs @@ -12,7 +12,7 @@ class ResourceIdentifierExtensionsTests [TestCase("/providers/Microsoft.Management/managementGroups/group0/providers/Microsoft.Authorization/policyAssignments/assignment", "policyAssignments/assignment")] public void SubstringAfterProviderNamespaceTest(string resourceId, string expected) { - ResourceIdentifier id = resourceId; + ResourceIdentifier id = new ResourceIdentifier(resourceId); string result = id.SubstringAfterProviderNamespace(); Assert.AreEqual(expected, result); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs index 24a110d559bd..f5c47c907c22 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs @@ -1,6 +1,8 @@ using Azure.ResourceManager.Resources.Models; +using Azure.ResourceManager.Core; using NUnit.Framework; using System; +using System.Collections.Generic; namespace Azure.ResourceManager.Tests { @@ -16,15 +18,23 @@ public class ResourceIdentifierTests const string SubscriptionResourceId = "/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575"; const string TenantResourceId = "/providers/Microsoft.Billing/billingAccounts/3984c6f4-2d2a-4b04-93ce-43cf4824b698%3Ae2f1492a-a492-468d-909f-bf7fe6662c01_2019-05-31"; - [SetUp] - public void Setup() + [Test] + public void Sort() { + List list = new List(); + ResourceIdentifier id = new ResourceIdentifier(TrackedResourceId); + ResourceIdentifier childId = id.AppendChildResource("myChild", "myChildName"); + list.Add(childId); + list.Add(id); + Assert.AreEqual(childId.Name, list[0].Name); + list.Sort(); + Assert.AreEqual(id.Name, list[0].Name); } [TestCase(TenantResourceId)] public void CanParseTenant(string id) { - ResourceIdentifier asIdentifier = id; + ResourceIdentifier asIdentifier = new ResourceIdentifier(id); Assert.AreEqual(asIdentifier.ResourceType.Namespace, "Microsoft.Billing"); Assert.AreEqual(asIdentifier.ResourceType.Type, "billingAccounts"); Assert.AreEqual(asIdentifier.Name, "3984c6f4-2d2a-4b04-93ce-43cf4824b698%3Ae2f1492a-a492-468d-909f-bf7fe6662c01_2019-05-31"); @@ -37,7 +47,7 @@ public void CanParseTenant(string id) [TestCase("/providers")] public void InvalidTenantID(string id) { - Assert.Throws(() => { ResourceIdentifier subject = id; }); + Assert.Throws(() => { ResourceIdentifier subject = new ResourceIdentifier(id); }); } [TestCase("")] @@ -49,11 +59,9 @@ public void InvalidTenantID(string id) [TestCase("/0c2f6471-1bf0-4dda-aec3-cb9272f09575/myRg/")] public void InvalidRPIds(string invalidID) { - Assert.Throws(() => { ResourceIdentifier subject = invalidID; }); - Assert.Throws(() => { ResourceIdentifier subject = ResourceIdentifier.Create(invalidID); }); + Assert.Throws(() => { ResourceIdentifier subject = new ResourceIdentifier(invalidID); }); } - [TestCase(null)] [TestCase(TrackedResourceId)] [TestCase(ChildResourceId)] [TestCase(ResourceGroupResourceId)] @@ -66,7 +74,7 @@ public void ImplicitConstructor(string resourceProviderID) string y; ResourceIdentifier z; - z = x; + z = new ResourceIdentifier(x); y = z; if (resourceProviderID is null) @@ -90,11 +98,11 @@ public void PublicConstructor(string resourceProviderID) { if (resourceProviderID is null) { - Assert.Throws(() => { ResourceIdentifier myResource = ResourceIdentifier.Create(resourceProviderID); }); + Assert.Throws(() => { ResourceIdentifier myResource = new ResourceIdentifier(resourceProviderID); }); } else { - ResourceIdentifier myResource = ResourceIdentifier.Create(resourceProviderID); + ResourceIdentifier myResource = new ResourceIdentifier(resourceProviderID); Assert.AreEqual(myResource.ToString(), resourceProviderID); } } @@ -102,8 +110,8 @@ public void PublicConstructor(string resourceProviderID) [TestCase(LocationResourceId, "Microsoft.Authorization", "roleAssignments", "myRa")] public void CanParseExtensionResourceIds(string baseId, string extensionNamespace, string extensionType, string extensionName) { - ResourceIdentifier targetResourceId = baseId; - ResourceIdentifier subject = $"{baseId}/providers/{extensionNamespace}/{extensionType}/{extensionName}"; + ResourceIdentifier targetResourceId = new ResourceIdentifier(baseId); + ResourceIdentifier subject = new ResourceIdentifier($"{baseId}/providers/{extensionNamespace}/{extensionType}/{extensionName}"); ResourceType expectedType = $"{extensionNamespace}/{extensionType}"; Assert.AreNotEqual(targetResourceId.ResourceType, subject.ResourceType); Assert.AreEqual(expectedType, subject.ResourceType); @@ -117,7 +125,7 @@ public void CanParseExtensionResourceIds(string baseId, string extensionNamespac Description = "From ServiceBus")] public void CanParseResourceIdsWithSubscriptionsOfOtherResourceTypes(string resourceId, string expectedResourcetype) { - ResourceIdentifier subject = resourceId; + ResourceIdentifier subject = new ResourceIdentifier(resourceId); Assert.AreEqual(expectedResourcetype, subject.ResourceType.ToString()); } @@ -142,7 +150,7 @@ protected void ValidateLocationBaseResource(ResourceIdentifier locationResource, { Assert.AreEqual(expectedId, locationResource.ToString()); Assert.AreEqual(expectedChild, locationResource.IsChild); - Assert.AreEqual("westus2", locationResource.Location); + Assert.AreEqual("westus2", locationResource.Location.ToString()); Assert.AreEqual("westus2", locationResource.Name); Assert.IsNull(locationResource.Provider); Assert.AreEqual(expectedResourcetype, locationResource.ResourceType.ToString()); @@ -175,7 +183,7 @@ protected void ValidateTenantResource(ResourceIdentifier tenantResource) public ResourceIdentifier ConvertToResourceId(string resourceId) { - ResourceIdentifier subject = resourceId; + ResourceIdentifier subject = new ResourceIdentifier(resourceId); return subject; } @@ -188,8 +196,8 @@ public ResourceIdentifier ConvertToResourceId(string resourceId) [TestCase(null, TrackedResourceId, false)] public void EqualsToResourceIdentifier(string resourceProviderID1, string resourceProviderID2, bool expected) { - ResourceIdentifier a = resourceProviderID1; - ResourceIdentifier b = resourceProviderID2; + ResourceIdentifier a = resourceProviderID1 == null ? null : new ResourceIdentifier(resourceProviderID1); + ResourceIdentifier b = resourceProviderID2 == null ? null : new ResourceIdentifier(resourceProviderID2); if (a != null) Assert.AreEqual(expected, a.Equals(b)); @@ -205,7 +213,7 @@ public void EqualsToResourceIdentifier(string resourceProviderID1, string resour [TestCase(null, TrackedResourceId, false)] public void EqualsToString(string resourceProviderID1, string resourceProviderID2, bool expected) { - ResourceIdentifier a = resourceProviderID1; + ResourceIdentifier a = resourceProviderID1 == null ? null : new ResourceIdentifier(resourceProviderID1); if (a != null) Assert.AreEqual(expected, a.Equals(resourceProviderID2)); @@ -223,23 +231,19 @@ public void EqualsToString(string resourceProviderID1, string resourceProviderID Description = "ResourceGroupResourceIdentifier")] public void TryGetPropertiesForGenericResource(string resourceId, string subscription, string location, string resourceGroup, string parent) { - ResourceIdentifier id1 = resourceId; - string outputSubscription; - Assert.AreEqual(!(subscription is null), id1.TryGetSubscriptionId(out outputSubscription)); + ResourceIdentifier id1 = new ResourceIdentifier(resourceId); + Assert.AreEqual(subscription is null, id1.SubscriptionId is null); if (!(subscription is null)) - Assert.AreEqual(subscription, outputSubscription); - Location outputLocation; - Assert.AreEqual(!(location is null), id1.TryGetLocation(out outputLocation)); + Assert.AreEqual(subscription, id1.SubscriptionId); + Assert.AreEqual(location is null, id1.Location is null); if (!(location is null)) - Assert.AreEqual(location, outputLocation.Name); - string outputResourceGroup; - Assert.AreEqual(!(resourceGroup is null), id1.TryGetResourceGroupName(out outputResourceGroup)); + Assert.AreEqual(location, id1.Location.Name); + Assert.AreEqual(resourceGroup is null, id1.ResourceGroupName is null); if (!(resourceGroup is null)) - Assert.AreEqual(resourceGroup, outputResourceGroup); - ResourceIdentifier outputParent; - Assert.AreEqual(!(parent is null), id1.TryGetParent(out outputParent)); + Assert.AreEqual(resourceGroup, id1.ResourceGroupName); + Assert.AreEqual(parent is null, id1.Parent is null); if (!(parent is null)) - Assert.AreEqual(parent, outputParent.ToString()); + Assert.AreEqual(parent, id1.Parent.ToString()); } [TestCase("/providers/Contoso.Widgets/widgets/myWidget", Description = "TenantResourceIdentifier")] @@ -251,7 +255,7 @@ public void TryGetPropertiesForGenericResource(string resourceId, string subscri Description = "ResourceGroupResourceIdentifier")] public void ResourceIdRetainsOriginalInput(string resourceId) { - ResourceIdentifier id = resourceId; + ResourceIdentifier id = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, id.ToString()); } @@ -259,12 +263,10 @@ public void ResourceIdRetainsOriginalInput(string resourceId) [TestCase(TrackedResourceId, ChildResourceId, -1)] [TestCase(ChildResourceId, TrackedResourceId, 1)] [TestCase(TrackedResourceId, null, 1)] - [TestCase(null, TrackedResourceId, -1)] - [TestCase(null, null, 0)] public void CompareToResourceProvider(string resourceProviderID1, string resourceProviderID2, int expected) { - ResourceIdentifier a = resourceProviderID1; - ResourceIdentifier b = (ResourceIdentifier)resourceProviderID2; + ResourceIdentifier a = new ResourceIdentifier(resourceProviderID1); + ResourceIdentifier b = resourceProviderID2 == null ? null : new ResourceIdentifier(resourceProviderID2); if (a != null) Assert.AreEqual(expected, a.CompareTo(b)); @@ -274,14 +276,12 @@ public void CompareToResourceProvider(string resourceProviderID1, string resourc [TestCase(TrackedResourceId, ChildResourceId, -1)] [TestCase(ChildResourceId, TrackedResourceId, 1)] [TestCase(TrackedResourceId, null, 1)] - [TestCase(null, TrackedResourceId, -1)] - [TestCase(null, null, 0)] public void CompareToString(string resourceProviderID1, string resourceProviderID2, int expected) { - ResourceIdentifier a = resourceProviderID1; + ResourceIdentifier a = new ResourceIdentifier(resourceProviderID1); string b = resourceProviderID2; if (a != null) - Assert.AreEqual(expected, a.CompareTo(b)); + Assert.AreEqual(expected, a.CompareTo(resourceProviderID2 == null ? null : new ResourceIdentifier(b))); } [TestCase(TrackedResourceId, TrackedResourceId, true, "object")] @@ -300,10 +300,10 @@ public void CompareToString(string resourceProviderID1, string resourceProviderI [TestCase(null, TrackedResourceId, false, "string")] public void EqualsOperator(string resourceProviderID1, string resourceProviderID2, bool expected, string comparisonType) { - ResourceIdentifier a = resourceProviderID1; + ResourceIdentifier a = resourceProviderID1 == null ? null : new ResourceIdentifier(resourceProviderID1); if (comparisonType == "object") { - ResourceIdentifier b = resourceProviderID2; + ResourceIdentifier b = resourceProviderID2 == null ? null : new ResourceIdentifier(resourceProviderID2); Assert.AreEqual(expected, a == b); } else @@ -328,10 +328,10 @@ public void EqualsOperator(string resourceProviderID1, string resourceProviderID [TestCase(null, TrackedResourceId, true, "string")] public void NotEqualsOperator(string resourceProviderID1, string resourceProviderID2, bool expected, string comparisonType) { - ResourceIdentifier a = resourceProviderID1; + ResourceIdentifier a = resourceProviderID1 == null ? null : new ResourceIdentifier(resourceProviderID1); if (comparisonType == "object") { - ResourceIdentifier b = resourceProviderID2; + ResourceIdentifier b = resourceProviderID2 == null ? null : new ResourceIdentifier(resourceProviderID2); Assert.AreEqual(expected, a != b); } else @@ -345,8 +345,8 @@ public void NotEqualsOperator(string resourceProviderID1, string resourceProvide [TestCase(false, ChildResourceId, TrackedResourceId)] public void LessThanOperator(bool expected, string string1, string string2) { - ResourceIdentifier id1 = string1; - ResourceIdentifier id2 = string2; + ResourceIdentifier id1 = new ResourceIdentifier(string1); + ResourceIdentifier id2 = new ResourceIdentifier(string2); Assert.AreEqual(expected, id1 < id2); } @@ -355,8 +355,8 @@ public void LessThanOperator(bool expected, string string1, string string2) [TestCase(false, ChildResourceId, TrackedResourceId)] public void LessThanOrEqualOperator(bool expected, string string1, string string2) { - ResourceIdentifier id1 = string1; - ResourceIdentifier id2 = string2; + ResourceIdentifier id1 = new ResourceIdentifier(string1); + ResourceIdentifier id2 = new ResourceIdentifier(string2); Assert.AreEqual(expected, id1 <= id2); } @@ -365,8 +365,8 @@ public void LessThanOrEqualOperator(bool expected, string string1, string string [TestCase(true, ChildResourceId, TrackedResourceId)] public void GreaterThanOperator(bool expected, string string1, string string2) { - ResourceIdentifier id1 = string1; - ResourceIdentifier id2 = string2; + ResourceIdentifier id1 = new ResourceIdentifier(string1); + ResourceIdentifier id2 = new ResourceIdentifier(string2); Assert.AreEqual(expected, id1 > id2); } @@ -375,15 +375,15 @@ public void GreaterThanOperator(bool expected, string string1, string string2) [TestCase(true, ChildResourceId, TrackedResourceId)] public void GreaterThanOrEqualOperator(bool expected, string string1, string string2) { - ResourceIdentifier id1 = string1; - ResourceIdentifier id2 = string2; + ResourceIdentifier id1 = new ResourceIdentifier(string1); + ResourceIdentifier id2 = new ResourceIdentifier(string2); Assert.AreEqual(expected, id1 >= id2); } [Test] public void LessThanNull() { - ResourceIdentifier id = TrackedResourceId; + ResourceIdentifier id = new ResourceIdentifier(TrackedResourceId); Assert.IsTrue(null < id); Assert.IsFalse(id < null); } @@ -391,7 +391,7 @@ public void LessThanNull() [Test] public void LessThanOrEqualNull() { - ResourceIdentifier id = TrackedResourceId; + ResourceIdentifier id = new ResourceIdentifier(TrackedResourceId); Assert.IsTrue(null <= id); Assert.IsFalse(id <= null); } @@ -399,7 +399,7 @@ public void LessThanOrEqualNull() [Test] public void GreaterThanNull() { - ResourceIdentifier id = TrackedResourceId; + ResourceIdentifier id = new ResourceIdentifier(TrackedResourceId); Assert.IsFalse(null > id); Assert.IsTrue(id > null); } @@ -407,7 +407,7 @@ public void GreaterThanNull() [Test] public void GreaterThanOrEqualNull() { - ResourceIdentifier id = TrackedResourceId; + ResourceIdentifier id = new ResourceIdentifier(TrackedResourceId); Assert.IsFalse(null >= id); Assert.IsTrue(id >= null); } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceListOperationsTest.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceListOperationsTest.cs index 358d56aaccd8..32df93805ed0 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceListOperationsTest.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceListOperationsTest.cs @@ -39,7 +39,7 @@ private static GenericResourceData GetGenericResource( string managedBy, string location) { - ResourceIdentifier id = $"/subscriptions/{Guid.NewGuid().ToString()}/resourceGroups/myResourceGroup/providers/Microsoft.Widgets/widgets/myWidget"; + ResourceIdentifier id = new ResourceIdentifier($"/subscriptions/{Guid.NewGuid()}/resourceGroups/myResourceGroup/providers/Microsoft.Widgets/widgets/myWidget"); return new GenericResourceData(id, id.Name, id.ResourceType, location, tags, plan, null, kind, managedBy, sku, null, null, null, null); } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionProviderIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionProviderIdentifierTests.cs index ffbbe2b40a41..12bd81222798 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionProviderIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionProviderIdentifierTests.cs @@ -11,7 +11,7 @@ public void ImplicitConstructorWithProvider(string resourceProviderID) { string x = resourceProviderID; string y; - ResourceIdentifier z = x; + ResourceIdentifier z = new ResourceIdentifier(x); y = z; Assert.AreEqual("Microsoft.Insights", z.Provider); @@ -36,7 +36,7 @@ public void ImplicitConstructorWithSubnet(string resourceProviderID) { string x = resourceProviderID; string y; - ResourceIdentifier z = x; + ResourceIdentifier z = new ResourceIdentifier(x); y = z; Assert.AreEqual("Microsoft.Insights", z.Provider); @@ -67,7 +67,7 @@ public void ImplicitConstructorWithVNet(string resourceProviderID) { string x = resourceProviderID; string y; - ResourceIdentifier z = x; + ResourceIdentifier z = new ResourceIdentifier(x); y = z; Assert.AreEqual("Microsoft.Insights", z.Provider); diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionResourceIdentifierTests.cs index ac7d4e071f8e..00ac96997371 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/SubscriptionResourceIdentifierTests.cs @@ -11,7 +11,7 @@ public class SubscriptionResourceIdentifierTests : ResourceIdentifierTests [Test] public void CanParseSubscriptions() { - ResourceIdentifier subject = "/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575"; + ResourceIdentifier subject = new ResourceIdentifier("/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575"); Assert.AreEqual("/subscriptions/0c2f6471-1bf0-4dda-aec3-cb9272f09575", subject.ToString()); Assert.AreEqual("0c2f6471-1bf0-4dda-aec3-cb9272f09575", subject.SubscriptionId); Assert.AreEqual("Microsoft.Resources", subject.ResourceType.Namespace); @@ -23,56 +23,50 @@ public void CanParseSubscriptions() [TestCase("/subscriptions/17fecd63-33d8-4e43-ac6f-0aafa111b38d/providers/Contoso.Widgets/widgets/myWidget/flanges/myFlange", Description = "Child of a subscription resource")] public void CanParseValidSubscriptionResource(string resourceId) { - ResourceIdentifier subscription = resourceId; + ResourceIdentifier subscription = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, subscription.ToString()); } [TestCase("/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/tagNames/azsecpack", Description = "No provider tagname")] public void CanParseValidNoProviderResource(string resourceId) { - ResourceIdentifier subscription = resourceId; + ResourceIdentifier subscription = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, subscription.ToString()); } [Test] public void TryGetPropertiesForSubscriptionResource() { - ResourceIdentifier id1 = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/providers/Contoso.Widgets/widgets/myWidget"; - string subscription; - Assert.AreEqual(true, id1.TryGetSubscriptionId(out subscription)); - Assert.AreEqual("6b085460-5f21-477e-ba44-1035046e9101", subscription); - Assert.AreEqual(false, id1.TryGetLocation(out _)); - Assert.AreEqual(false, id1.TryGetResourceGroupName(out _)); - ResourceIdentifier expectedId = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"; - ResourceIdentifier parentId; - Assert.AreEqual(true, id1.TryGetParent(out parentId)); - Assert.IsTrue(expectedId.Equals(parentId)); + ResourceIdentifier id1 = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/providers/Contoso.Widgets/widgets/myWidget"); + Assert.NotNull(id1.SubscriptionId); + Assert.AreEqual("6b085460-5f21-477e-ba44-1035046e9101", id1.SubscriptionId); + Assert.Null(id1.Location); + Assert.Null(id1.ResourceGroupName); + ResourceIdentifier expectedId = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"); + Assert.NotNull(id1.Parent); + Assert.IsTrue(expectedId.Equals(id1.Parent)); } [Test] public void TryGetPropertiesForSubscriptionProvider() { - ResourceIdentifier id1 = "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/providers/Microsoft.Compute"; - string subscription; - Assert.AreEqual(true, id1.TryGetSubscriptionId(out subscription)); - Assert.AreEqual("db1ab6f0-4769-4b27-930e-01e2ef9c123c", subscription); - Assert.AreEqual(false, id1.TryGetLocation(out _)); - Assert.AreEqual(false, id1.TryGetResourceGroupName(out _)); - ResourceIdentifier expectedId = "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c"; - ResourceIdentifier parentId; - Assert.AreEqual(true, id1.TryGetParent(out parentId)); - Assert.IsTrue(expectedId.Equals(parentId)); + ResourceIdentifier id1 = new ResourceIdentifier("/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/providers/Microsoft.Compute"); + Assert.NotNull(id1.SubscriptionId); + Assert.AreEqual("db1ab6f0-4769-4b27-930e-01e2ef9c123c", id1.SubscriptionId); + Assert.Null(id1.Location); + Assert.Null(id1.ResourceGroupName); + ResourceIdentifier expectedId = new ResourceIdentifier("/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c"); + Assert.NotNull(id1.Parent); + Assert.IsTrue(expectedId.Equals(id1.Parent)); } [Test] public void ThrowOnMistypedResource() { - ResourceIdentifier subscription = "/providers/Contoso.Widgets/widgets/myWidget"; + ResourceIdentifier subscription = new ResourceIdentifier("/providers/Contoso.Widgets/widgets/myWidget"); Assert.IsNotNull(subscription); Assert.DoesNotThrow(() => subscription = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2")); Assert.DoesNotThrow(() => subscription = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg")); - Assert.DoesNotThrow(() => subscription = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2"); - Assert.DoesNotThrow(() => subscription = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg"); } [TestCase(SubscriptionResourceId, "Microsoft.Authorization", "roleAssignments", "MyRoleAssignemnt")] @@ -88,7 +82,7 @@ public void ThrowOnMistypedResource() public void TestAppendSubscriptionProviderResource(string resourceId, string providerNamespace, string resourceTypeName, string resourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (providerNamespace is null || resourceTypeName is null || resourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendProviderResource(providerNamespace, resourceTypeName, resourceName)); else if (string.IsNullOrWhiteSpace(providerNamespace) || string.IsNullOrWhiteSpace(resourceTypeName) || string.IsNullOrWhiteSpace(resourceName)) @@ -111,7 +105,7 @@ public void TestAppendSubscriptionProviderResource(string resourceId, string pro [TestCase(SubscriptionResourceId, "wheels", "wheel1/wheel2")] public void TestAppendSubscriptionChildResource(string resourceId, string childTypeName, string childResourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (childTypeName is null || childResourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendChildResource(childTypeName, childResourceName)); else if (string.IsNullOrWhiteSpace(childTypeName) || string.IsNullOrWhiteSpace(childResourceName)) diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantProviderIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantProviderIdentifierTests.cs index 6b071b952df6..236ce3fc9f5d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantProviderIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantProviderIdentifierTests.cs @@ -10,7 +10,7 @@ public void ImplicitConstructorProviderOnly(string resourceProviderID) { string x = resourceProviderID; string y; - ResourceIdentifier z = x; + ResourceIdentifier z = new ResourceIdentifier(x); y = z; Assert.IsNotNull(z.Parent); @@ -35,7 +35,7 @@ public void ImplicitConstructorVirtualMachine(string resourceProviderID) { string x = resourceProviderID; string y; - ResourceIdentifier z = x; + ResourceIdentifier z = new ResourceIdentifier(x); y = z; Assert.AreEqual("myVmName", z.Name); @@ -61,7 +61,7 @@ public void ImplicitConstructorSubnet(string resourceProviderID) { string x = resourceProviderID; string y; - ResourceIdentifier z = x; + ResourceIdentifier z = new ResourceIdentifier(x); y = z; Assert.AreEqual("testsubnet", z.Name); diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantResourceIdentifierTests.cs index 2c89685192e6..22403cf0a833 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/TenantResourceIdentifierTests.cs @@ -11,22 +11,21 @@ public class TenantResourceIdentifierTests : ResourceIdentifierTests [TestCase("/providers/Contoso.Widgets/widgets/myWidget/flanges/myFlange", Description = "Child of a subscription resource")] public void CanParseValidTenantResource(string resourceId) { - ResourceIdentifier tenant = resourceId; + ResourceIdentifier tenant = new ResourceIdentifier(resourceId); Assert.AreEqual(resourceId, tenant.ToString()); } [Test] public void TryGetPropertiesForTenantResource() { - ResourceIdentifier id1 = "/providers/Contoso.Widgets/widgets/myWidget"; - Assert.AreEqual(false, id1.TryGetSubscriptionId(out _)); - Assert.AreEqual(false, id1.TryGetLocation(out _)); - Assert.AreEqual(false, id1.TryGetResourceGroupName(out _)); - Assert.AreEqual(true, id1.TryGetParent(out _)); - ResourceIdentifier id2 = "/providers/Contoso.Widgets/widgets/myWidget/flages/myFlange"; - ResourceIdentifier parent; - Assert.AreEqual(true, id2.TryGetParent(out parent)); - Assert.AreEqual(true, id1.Equals(parent)); + ResourceIdentifier id1 = new ResourceIdentifier("/providers/Contoso.Widgets/widgets/myWidget"); + Assert.Null(id1.SubscriptionId); + Assert.Null(id1.Location); + Assert.Null(id1.ResourceGroupName); + Assert.NotNull(id1.Parent); + ResourceIdentifier id2 = new ResourceIdentifier("/providers/Contoso.Widgets/widgets/myWidget/flages/myFlange"); + Assert.NotNull(id2.Parent); + Assert.AreEqual(true, id1.Equals(id2.Parent)); } [Test] @@ -36,9 +35,6 @@ public void ThrowOnMistypedResource() Assert.DoesNotThrow(() => tenant = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101")); Assert.DoesNotThrow(() => tenant = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2")); Assert.DoesNotThrow(() => tenant = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg")); - Assert.DoesNotThrow(() => tenant = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"); - Assert.DoesNotThrow(() => tenant = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2"); - Assert.DoesNotThrow(() => tenant = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg"); } [TestCase("/providers/Microsoft.Widgets/widgets/MyWidget", "Microsoft.Authorization", "roleAssignments", "MyRoleAssignemnt")] @@ -54,7 +50,7 @@ public void ThrowOnMistypedResource() [TestCase("/providers/Microsoft.Widgets/widgets/MyWidget/things/MyThing", "Microsoft.Authorization", "roleAssignments", "MyRole/Assignemnt")] public void TestAppendTenantProviderResource(string resourceId, string providerNamespace, string resourceTypeName, string resourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (providerNamespace is null || resourceTypeName is null || resourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendProviderResource(providerNamespace, resourceTypeName, resourceName)); else if (string.IsNullOrWhiteSpace(providerNamespace) || string.IsNullOrWhiteSpace(resourceTypeName) || string.IsNullOrWhiteSpace(resourceName)) @@ -78,7 +74,7 @@ public void TestAppendTenantProviderResource(string resourceId, string providerN [TestCase("/providers/Microsoft.Widgets/widgets/MyWidget/things/MyThing", "wheels", "wheel1/wheel2")] public void TestAppendTenantChildResource(string resourceId, string childTypeName, string childResourceName) { - ResourceIdentifier resource = resourceId; + ResourceIdentifier resource = new ResourceIdentifier(resourceId); if (childTypeName is null || childResourceName is null) Assert.Throws(typeof(ArgumentNullException), () => resource.AppendChildResource(childTypeName, childResourceName)); else if (string.IsNullOrWhiteSpace(childTypeName) || string.IsNullOrWhiteSpace(childResourceName)) diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/WritableSubResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/WritableSubResourceTests.cs index b6deeea54c1c..e9f1f430ed60 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/WritableSubResourceTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/WritableSubResourceTests.cs @@ -11,7 +11,7 @@ public class WritableSubResourceTests [Test] public void Deserialization() { - var id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"; + var id = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); var expected = "{\"id\":\"" + id + "\"}"; var resource1 = new WritableSubResource(id); var jsonString = JsonHelper.SerializeToString(resource1); @@ -21,7 +21,7 @@ public void Deserialization() Assert.AreEqual(jsonString, JsonHelper.SerializeToString(resource2)); var resource3 = new WritableSubResource(); - resource3.Id = id; + resource3.Id = new ResourceIdentifier(id); Assert.AreEqual(jsonString, JsonHelper.SerializeToString(resource3)); } } diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/DeploymentCollection.cs b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/DeploymentCollection.cs index 457fe3280468..29389f7a600b 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/DeploymentCollection.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/DeploymentCollection.cs @@ -41,7 +41,7 @@ internal DeploymentCollection(ArmResource parent) : base(parent) } /// Gets the valid resource type for this object. - protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.Root.ResourceType; /// Verify that the input resource Id is a valid collection for this type. /// The input resource Id to check. diff --git a/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Azure.ResourceManager.ServiceBus.Tests.csproj b/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Azure.ResourceManager.ServiceBus.Tests.csproj index 9010fbd70e48..96ed640b3f7f 100644 --- a/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Azure.ResourceManager.ServiceBus.Tests.csproj +++ b/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Azure.ResourceManager.ServiceBus.Tests.csproj @@ -3,9 +3,9 @@ - - - + + + diff --git a/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Tests/ServiceBusNamespaceTests.cs b/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Tests/ServiceBusNamespaceTests.cs index d7b0d0575fed..ad29860a6374 100644 --- a/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Tests/ServiceBusNamespaceTests.cs +++ b/sdk/servicebus/Azure.ResourceManager.ServiceBus/tests/Tests/ServiceBusNamespaceTests.cs @@ -209,7 +209,7 @@ public async Task CreateGetDeletePrivateEndPointConnection() { PrivateEndpoint = new WritableSubResource() { - Id = serviceBusNamespace2.Id.ToString() + Id = serviceBusNamespace2.Id } }; PrivateEndpointConnection privateEndpointConnection = (await privateEndpointConnectionCollection.CreateOrUpdateAsync(connectionName, parameter)).Value; @@ -383,9 +383,9 @@ public async Task SetGetNetworkRuleSets() //set network rule set string subscriptionId = DefaultSubscription.Id.ToString(); - string subnetId1 = subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1"; - string subnetId2 = subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2"; - string subnetId3 = subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3"; + ResourceIdentifier subnetId1 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1"); + ResourceIdentifier subnetId2 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2"); + ResourceIdentifier subnetId3 = new ResourceIdentifier(subscriptionId + "/resourcegroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3"); NetworkRuleSetData parameter = new NetworkRuleSetData() { DefaultAction = DefaultAction.Deny,