From 8c441ff7b9517b3929852abae72fe3424f390ed9 Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Thu, 16 Dec 2021 16:17:27 -0800 Subject: [PATCH] update Location in preparation to move to Azure.Core (#25464) * finalize changes for RI and Loc objects * remove regionaldisplayname implicit and ctor expect name only change private dictionary to use name directly factory method to convert from displayName * add copy from static in ctor case * remove conditional application of to name logic * assert regionaldisplayname still shows up after moving to locationExpanded * switch to properties vs fields * add param check to ctor for required name * move FromDisplayName to an internal method on the single class that needs it for now * remove IComparable on location * Convert location to struct * update from feedback * remove null check on struct * update keyvault tests * revert recording change and update vault create to use displayname * update to use displayname in all vault tests * update api * update location to implicitly convert either displayname or name * update api * Revert "update to use displayname in all vault tests" This reverts commit 282fb9f315d4ed5908dba7739be3be9c3e0bcb68. * Revert "revert recording change and update vault create to use displayname" This reverts commit f1f6c2e0aec1d6882d6763fbbc637aaf36ef5645. * Revert "update keyvault tests" This reverts commit 1448e7ce71422c8104dbdbf0fec15dd0730d591c. * temp fix to get autorest updated * temp change to get private build out for back compat * Revert "temp fix to get autorest updated" This reverts commit 6a04eb740ccd250e2aac5276e24dcdb7a238ccb5. * Revert "temp change to get private build out for back compat" This reverts commit dd68c21182976c1fa19bffc6c6bb896fc67d8115. * Update AutoRest C# version to 3.0.0-beta.20211214.1 * Revert "Update AutoRest C# version to 3.0.0-beta.20211214.1" This reverts commit ef5364297439eeef56ce2f7d993cd9849df272b8. * temp change for ci * undo temp change Co-authored-by: azure-sdk --- .../Azure.ResourceManager.netstandard2.0.cs | 113 ++--- .../Azure.ResourceManager/src/ArmResource.cs | 5 +- .../src/Custom/Resources/Models/Location.cs | 392 +++++------------- .../Resources/Models/LocationExpanded.cs | 17 + .../Models/Location.Serialization.cs | 52 --- .../Resources/Models/Location.cs | 55 --- .../Models/LocationExpanded.Serialization.cs | 21 +- .../Resources/Models/LocationExpanded.cs | 15 +- .../Resources/ResourceGroupCollection.cs | 3 - .../Resources/ResourceGroupData.cs | 8 +- .../Resources/SubscriptionData.cs | 30 +- .../src/ResourceIdentifier.cs | 2 +- .../tests/Scenario/ArmBuilderTests.cs | 18 +- .../tests/Scenario/LocationExpandedTests.cs | 6 + .../Unit/LocationResourceIdentifierTests.cs | 20 +- .../tests/Unit/LocationTests.cs | 301 +++----------- .../ResourceGroupResourceIdentifierTests.cs | 2 +- .../tests/Unit/ResourceIdentifierTests.cs | 4 +- 18 files changed, 329 insertions(+), 735 deletions(-) create mode 100644 sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/LocationExpanded.cs delete mode 100644 sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.Serialization.cs delete mode 100644 sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.cs 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 6a98e84c9e1b..a9e7f6484da7 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs @@ -73,7 +73,7 @@ public sealed partial class ResourceIdentifier : System.IComparable System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } - public partial class SubscriptionData : Azure.ResourceManager.Models.TrackedResource + public partial class SubscriptionData { - internal SubscriptionData() : base (default(Azure.ResourceManager.Resources.Models.Location)) { } + internal SubscriptionData() { } public string AuthorizationSource { get { throw null; } } public string DisplayName { get { throw null; } } + public virtual Azure.ResourceManager.ResourceIdentifier Id { get { throw null; } } public System.Collections.Generic.IReadOnlyList ManagedByTenants { get { throw null; } } public Azure.ResourceManager.Resources.Models.SubscriptionState? State { get { throw null; } } public string SubscriptionGuid { get { throw null; } } public Azure.ResourceManager.Resources.Models.SubscriptionPolicies SubscriptionPolicies { get { throw null; } } + public System.Collections.Generic.IDictionary Tags { get { throw null; } } public string TenantId { get { throw null; } } } public partial class TagResource : Azure.ResourceManager.Core.ArmResource @@ -1049,75 +1051,76 @@ public partial class FeatureProperties internal FeatureProperties() { } public string State { get { throw null; } } } - public partial class Location : System.IComparable, System.IEquatable - { - public static readonly Azure.ResourceManager.Resources.Models.Location AustraliaCentral; - public static readonly Azure.ResourceManager.Resources.Models.Location AustraliaCentral2; - public static readonly Azure.ResourceManager.Resources.Models.Location AustraliaEast; - public static readonly Azure.ResourceManager.Resources.Models.Location AustraliaSoutheast; - public static readonly Azure.ResourceManager.Resources.Models.Location BrazilSouth; - public static readonly Azure.ResourceManager.Resources.Models.Location BrazilSoutheast; - public static readonly Azure.ResourceManager.Resources.Models.Location CanadaCentral; - public static readonly Azure.ResourceManager.Resources.Models.Location CanadaEast; - public static readonly Azure.ResourceManager.Resources.Models.Location CentralIndia; - public static readonly Azure.ResourceManager.Resources.Models.Location CentralUS; - public static readonly Azure.ResourceManager.Resources.Models.Location EastAsia; - public static readonly Azure.ResourceManager.Resources.Models.Location EastUS; - public static readonly Azure.ResourceManager.Resources.Models.Location EastUS2; - public static readonly Azure.ResourceManager.Resources.Models.Location FranceCentral; - public static readonly Azure.ResourceManager.Resources.Models.Location FranceSouth; - public static readonly Azure.ResourceManager.Resources.Models.Location GermanyNorth; - public static readonly Azure.ResourceManager.Resources.Models.Location GermanyWestCentral; - public static readonly Azure.ResourceManager.Resources.Models.Location JapanEast; - public static readonly Azure.ResourceManager.Resources.Models.Location JapanWest; - public static readonly Azure.ResourceManager.Resources.Models.Location KoreaCentral; - public static readonly Azure.ResourceManager.Resources.Models.Location KoreaSouth; - public static readonly Azure.ResourceManager.Resources.Models.Location NorthCentralUS; - public static readonly Azure.ResourceManager.Resources.Models.Location NorthEurope; - public static readonly Azure.ResourceManager.Resources.Models.Location NorwayWest; - public static readonly Azure.ResourceManager.Resources.Models.Location SouthAfricaNorth; - public static readonly Azure.ResourceManager.Resources.Models.Location SouthAfricaWest; - public static readonly Azure.ResourceManager.Resources.Models.Location SouthCentralUS; - public static readonly Azure.ResourceManager.Resources.Models.Location SoutheastAsia; - public static readonly Azure.ResourceManager.Resources.Models.Location SouthIndia; - public static readonly Azure.ResourceManager.Resources.Models.Location SwitzerlandNorth; - public static readonly Azure.ResourceManager.Resources.Models.Location SwitzerlandWest; - public static readonly Azure.ResourceManager.Resources.Models.Location UAECentral; - public static readonly Azure.ResourceManager.Resources.Models.Location UAENorth; - public static readonly Azure.ResourceManager.Resources.Models.Location UKSouth; - public static readonly Azure.ResourceManager.Resources.Models.Location UKWest; - public static readonly Azure.ResourceManager.Resources.Models.Location WestCentralUS; - public static readonly Azure.ResourceManager.Resources.Models.Location WestEurope; - public static readonly Azure.ResourceManager.Resources.Models.Location WestIndia; - public static readonly Azure.ResourceManager.Resources.Models.Location WestUS; - public static readonly Azure.ResourceManager.Resources.Models.Location WestUS2; - protected Location() { } - public string CanonicalName { get { throw null; } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct Location : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public Location(string location) { throw null; } + public Location(string name, string displayName) { throw null; } + public static Azure.ResourceManager.Resources.Models.Location AustraliaCentral { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location AustraliaCentral2 { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location AustraliaEast { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location AustraliaSoutheast { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location BrazilSouth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location BrazilSoutheast { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location CanadaCentral { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location CanadaEast { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location CentralIndia { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location CentralUS { get { throw null; } } public string DisplayName { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location EastAsia { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location EastUS { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location EastUS2 { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location FranceCentral { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location FranceSouth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location GermanyNorth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location GermanyWestCentral { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location JapanEast { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location JapanWest { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location KoreaCentral { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location KoreaSouth { get { throw null; } } public string Name { get { throw null; } } - public string RegionalDisplayName { get { throw null; } } - public int CompareTo(Azure.ResourceManager.Resources.Models.Location other) { throw null; } + public static Azure.ResourceManager.Resources.Models.Location NorthCentralUS { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location NorthEurope { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location NorwayWest { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SouthAfricaNorth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SouthAfricaWest { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SouthCentralUS { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SoutheastAsia { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SouthIndia { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SwitzerlandNorth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location SwitzerlandWest { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location UAECentral { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location UAENorth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location UKSouth { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location UKWest { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location WestCentralUS { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location WestEurope { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location WestIndia { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location WestUS { get { throw null; } } + public static Azure.ResourceManager.Resources.Models.Location WestUS2 { get { throw null; } } public bool Equals(Azure.ResourceManager.Resources.Models.Location other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public static bool operator ==(Azure.ResourceManager.Resources.Models.Location left, Azure.ResourceManager.Resources.Models.Location right) { throw null; } - public static bool operator >(Azure.ResourceManager.Resources.Models.Location left, Azure.ResourceManager.Resources.Models.Location right) { throw null; } - public static bool operator >=(Azure.ResourceManager.Resources.Models.Location left, Azure.ResourceManager.Resources.Models.Location right) { throw null; } public static implicit operator string (Azure.ResourceManager.Resources.Models.Location other) { throw null; } public static implicit operator Azure.ResourceManager.Resources.Models.Location (string other) { throw null; } public static bool operator !=(Azure.ResourceManager.Resources.Models.Location left, Azure.ResourceManager.Resources.Models.Location right) { throw null; } - public static bool operator <(Azure.ResourceManager.Resources.Models.Location left, Azure.ResourceManager.Resources.Models.Location right) { throw null; } - public static bool operator <=(Azure.ResourceManager.Resources.Models.Location left, Azure.ResourceManager.Resources.Models.Location right) { throw null; } public override string ToString() { throw null; } } - public partial class LocationExpanded : Azure.ResourceManager.Resources.Models.Location + public partial class LocationExpanded { protected LocationExpanded() { } + public string DisplayName { get { throw null; } } public string Id { get { throw null; } } public Azure.ResourceManager.Resources.Models.LocationMetadata Metadata { get { throw null; } } + public string Name { get { throw null; } } + public string RegionalDisplayName { get { throw null; } } public string SubscriptionId { get { throw null; } } + public static implicit operator Azure.ResourceManager.Resources.Models.Location (Azure.ResourceManager.Resources.Models.LocationExpanded location) { throw null; } } public partial class LocationMetadata { diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ArmResource.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ArmResource.cs index c18c7e6934b9..05fa14ff2e24 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ArmResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ArmResource.cs @@ -10,6 +10,7 @@ using Azure.ResourceManager.Resources; using Azure.ResourceManager.Resources.Models; using System.Linq; +using System.Text; namespace Azure.ResourceManager.Core { @@ -129,7 +130,7 @@ protected IEnumerable ListAvailableLocations(ResourceType resourceType var theResource = resourcePageableProvider.ResourceTypes.FirstOrDefault(r => resourceType.Type.Equals(r.ResourceType)); if (theResource is null) throw new InvalidOperationException($"{resourceType.Type} not found for {resourceType.Type}"); - return theResource.Locations.Select(l => (Location)l); + return theResource.Locations.Select(l => new Location(l)); } /// @@ -146,7 +147,7 @@ protected async Task> ListAvailableLocationsAsync(Resource var theResource = resourcePageableProvider.ResourceTypes.FirstOrDefault(r => resourceType.Type.Equals(r.ResourceType)); if (theResource is null) throw new InvalidOperationException($"{resourceType.Type} not found for {resourceType.Type}"); - return theResource.Locations.Select(l => (Location)l); + return theResource.Locations.Select(l => new Location(l)); } } } 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 be98887d307e..93e60b2784a6 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/Location.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/Location.cs @@ -4,305 +4,287 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Globalization; using System.Text; -using System.Text.RegularExpressions; namespace Azure.ResourceManager.Resources.Models { /// /// Represents an Azure geography region where supported resource providers live. /// - public partial class Location : IEquatable, IComparable + public readonly struct Location : IEquatable { + private const char Space = ' '; + + private static Dictionary PublicCloudLocations { get; } = new Dictionary(); + #region Public Cloud Locations /// /// Public cloud location for East Asia. /// - public static readonly Location EastAsia = new Location { Name = "eastasia", CanonicalName = "east-asia", DisplayName = "East Asia", RegionalDisplayName = "(Asia Pacific) East Asia" }; + public static Location EastAsia { get; } = CreateStaticReference("eastasia", "East Asia"); /// /// Public cloud location for Southeast Asia. /// - public static readonly Location SoutheastAsia = new Location { Name = "southeastasia", CanonicalName = "southeast-asia", DisplayName = "Southeast Asia", RegionalDisplayName = "(Asia Pacific) Southeast Asia" }; + public static Location SoutheastAsia { get; } = CreateStaticReference("southeastasia", "Southeast Asia"); /// /// Public cloud location for Central US. /// - public static readonly Location CentralUS = new Location { Name = "centralus", CanonicalName = "central-us", DisplayName = "Central US", RegionalDisplayName = "(US) Central US" }; + public static Location CentralUS { get; } = CreateStaticReference("centralus", "Central US"); /// /// Public cloud location for East US. /// - public static readonly Location EastUS = new Location { Name = "eastus", CanonicalName = "east-us", DisplayName = "East US", RegionalDisplayName = "(US) East US" }; + public static Location EastUS { get; } = CreateStaticReference("eastus", "East US"); /// /// Public cloud location for East US 2. /// - public static readonly Location EastUS2 = new Location { Name = "eastus2", CanonicalName = "east-us-2", DisplayName = "East US 2", RegionalDisplayName = "(US) East US 2" }; + public static Location EastUS2 { get; } = CreateStaticReference("eastus2", "East US 2"); /// /// Public cloud location for West US. /// - public static readonly Location WestUS = new Location { Name = "westus", CanonicalName = "west-us", DisplayName = "West US", RegionalDisplayName = "(US) West US" }; + public static Location WestUS { get; } = CreateStaticReference("westus", "West US"); /// /// Public cloud location for North Central US. /// - public static readonly Location NorthCentralUS = new Location { Name = "northcentralus", CanonicalName = "north-central-us", DisplayName = "North Central US", RegionalDisplayName = "(US) North Central US" }; + public static Location NorthCentralUS { get; } = CreateStaticReference("northcentralus", "North Central US"); /// /// Public cloud location for South Central US. /// - public static readonly Location SouthCentralUS = new Location { Name = "southcentralus", CanonicalName = "south-central-us", DisplayName = "South Central US", RegionalDisplayName = "(US) South Central US" }; + public static Location SouthCentralUS { get; } = CreateStaticReference("southcentralus", "South Central US"); /// /// Public cloud location for North Europe. /// - public static readonly Location NorthEurope = new Location { Name = "northeurope", CanonicalName = "north-europe", DisplayName = "North Europe", RegionalDisplayName = "(Europe) North Europe" }; + public static Location NorthEurope { get; } = CreateStaticReference("northeurope", "North Europe"); /// /// Public cloud location for West Europe. /// - public static readonly Location WestEurope = new Location { Name = "westeurope", CanonicalName = "west-europe", DisplayName = "West Europe", RegionalDisplayName = "(Europe) West Europe" }; + public static Location WestEurope { get; } = CreateStaticReference("westeurope", "West Europe"); /// /// Public cloud location for Japan West. /// - public static readonly Location JapanWest = new Location { Name = "japanwest", CanonicalName = "japan-west", DisplayName = "Japan West", RegionalDisplayName = "(Asia Pacific) Japan West" }; + public static Location JapanWest { get; } = CreateStaticReference("japanwest", "Japan West"); /// /// Public cloud location for Japan East. /// - public static readonly Location JapanEast = new Location { Name = "japaneast", CanonicalName = "japan-east", DisplayName = "Japan East", RegionalDisplayName = "(Asia Pacific) Japan East" }; + public static Location JapanEast { get; } = CreateStaticReference("japaneast", "Japan East"); /// /// Public cloud location for Brazil South. /// - public static readonly Location BrazilSouth = new Location { Name = "brazilsouth", CanonicalName = "brazil-south", DisplayName = "Brazil South", RegionalDisplayName = "(South America) Brazil South" }; + public static Location BrazilSouth { get; } = CreateStaticReference("brazilsouth", "Brazil South"); /// /// Public cloud location for Australia East. /// - public static readonly Location AustraliaEast = new Location { Name = "australiaeast", CanonicalName = "australia-east", DisplayName = "Australia East", RegionalDisplayName = "(Asia Pacific) Australia East" }; + public static Location AustraliaEast { get; } = CreateStaticReference("australiaeast", "Australia East"); /// /// Public cloud location for Australia Southeast. /// - public static readonly Location AustraliaSoutheast = new Location { Name = "australiasoutheast", CanonicalName = "australia-southeast", DisplayName = "Australia Southeast", RegionalDisplayName = "(Asia Pacific) Australia Southeast" }; + public static Location AustraliaSoutheast { get; } = CreateStaticReference("australiasoutheast", "Australia Southeast"); /// /// Public cloud location for South India. /// - public static readonly Location SouthIndia = new Location { Name = "southindia", CanonicalName = "south-india", DisplayName = "South India", RegionalDisplayName = "(Asia Pacific) South India" }; + public static Location SouthIndia { get; } = CreateStaticReference("southindia", "South India"); /// /// Public cloud location for Central India. /// - public static readonly Location CentralIndia = new Location { Name = "centralindia", CanonicalName = "central-india", DisplayName = "Central India", RegionalDisplayName = "(Asia Pacific) Central India" }; + public static Location CentralIndia { get; } = CreateStaticReference("centralindia", "Central India"); /// /// Public cloud location for West India. /// - public static readonly Location WestIndia = new Location { Name = "westindia", CanonicalName = "west-india", DisplayName = "West India", RegionalDisplayName = "(Asia Pacific) West India" }; + public static Location WestIndia { get; } = CreateStaticReference("westindia", "West India"); /// /// Public cloud location for Canada Central. /// - public static readonly Location CanadaCentral = new Location { Name = "canadacentral", CanonicalName = "canada-central", DisplayName = "Canada Central", RegionalDisplayName = "(Canada) Canada Central" }; + public static Location CanadaCentral { get; } = CreateStaticReference("canadacentral", "Canada Central"); /// /// Public cloud location for Canada East. /// - public static readonly Location CanadaEast = new Location { Name = "canadaeast", CanonicalName = "canada-east", DisplayName = "Canada East", RegionalDisplayName = "(Canada) Canada East" }; + public static Location CanadaEast { get; } = CreateStaticReference("canadaeast", "Canada East"); /// /// Public cloud location for UK South. /// - public static readonly Location UKSouth = new Location { Name = "uksouth", CanonicalName = "uk-south", DisplayName = "UK South", RegionalDisplayName = "(Europe) UK South" }; + public static Location UKSouth { get; } = CreateStaticReference("uksouth", "UK South"); /// /// Public cloud location for UK West. /// - public static readonly Location UKWest = new Location { Name = "ukwest", CanonicalName = "uk-west", DisplayName = "UK West", RegionalDisplayName = "(Europe) UK West" }; + public static Location UKWest { get; } = CreateStaticReference("ukwest", "UK West"); /// /// Public cloud location for West Central US. /// - public static readonly Location WestCentralUS = new Location { Name = "westcentralus", CanonicalName = "west-central-us", DisplayName = "West Central US", RegionalDisplayName = "(US) West Central US" }; + public static Location WestCentralUS { get; } = CreateStaticReference("westcentralus", "West Central US"); /// /// Public cloud location for West US 2. /// - public static readonly Location WestUS2 = new Location { Name = "westus2", CanonicalName = "west-us-2", DisplayName = "West US 2", RegionalDisplayName = "(US) West US 2" }; + public static Location WestUS2 { get; } = CreateStaticReference("westus2", "West US 2"); /// /// Public cloud location for Korea Central. /// - public static readonly Location KoreaCentral = new Location { Name = "koreacentral", CanonicalName = "korea-central", DisplayName = "Korea Central", RegionalDisplayName = "(Asia Pacific) Korea Central" }; + public static Location KoreaCentral { get; } = CreateStaticReference("koreacentral", "Korea Central"); /// /// Public cloud location for Korea South. /// - public static readonly Location KoreaSouth = new Location { Name = "koreasouth", CanonicalName = "korea-south", DisplayName = "Korea South", RegionalDisplayName = "(Asia Pacific) Korea South" }; + public static Location KoreaSouth { get; } = CreateStaticReference("koreasouth", "Korea South"); /// /// Public cloud location for France Central. /// - public static readonly Location FranceCentral = new Location { Name = "francecentral", CanonicalName = "france-central", DisplayName = "France Central", RegionalDisplayName = "(Europe) France Central" }; + public static Location FranceCentral { get; } = CreateStaticReference("francecentral", "France Central"); /// /// Public cloud location for France South. /// - public static readonly Location FranceSouth = new Location { Name = "francesouth", CanonicalName = "france-south", DisplayName = "France South", RegionalDisplayName = "(Europe) France South" }; + public static Location FranceSouth { get; } = CreateStaticReference("francesouth", "France South"); /// /// Public cloud location for Australia Central. /// - public static readonly Location AustraliaCentral = new Location { Name = "australiacentral", CanonicalName = "australia-central", DisplayName = "Australia Central", RegionalDisplayName = "(Asia Pacific) Australia Central" }; + public static Location AustraliaCentral { get; } = CreateStaticReference("australiacentral", "Australia Central"); /// /// Public cloud location for Australia Central 2. /// - public static readonly Location AustraliaCentral2 = new Location { Name = "australiacentral2", CanonicalName = "australia-central-2", DisplayName = "Australia Central 2", RegionalDisplayName = "(Asia Pacific) Australia Central 2" }; + public static Location AustraliaCentral2 { get; } = CreateStaticReference("australiacentral2", "Australia Central 2"); /// /// Public cloud location for UAE Central. /// - public static readonly Location UAECentral = new Location { Name = "uaecentral", CanonicalName = "uae-central", DisplayName = "UAE Central", RegionalDisplayName = "(Middle East) UAE Central" }; + public static Location UAECentral { get; } = CreateStaticReference("uaecentral", "UAE Central"); /// /// Public cloud location for UAE North. /// - public static readonly Location UAENorth = new Location { Name = "uaenorth", CanonicalName = "uae-north", DisplayName = "UAE North", RegionalDisplayName = "(Middle East) UAE North" }; + public static Location UAENorth { get; } = CreateStaticReference("uaenorth", "UAE North"); /// /// Public cloud location for South Africa North. /// - public static readonly Location SouthAfricaNorth = new Location { Name = "southafricanorth", CanonicalName = "south-africa-north", DisplayName = "South Africa North", RegionalDisplayName = "(Africa) South Africa North" }; + public static Location SouthAfricaNorth { get; } = CreateStaticReference("southafricanorth", "South Africa North"); /// /// Public cloud location for South Africa West. /// - public static readonly Location SouthAfricaWest = new Location { Name = "southafricawest", CanonicalName = "south-africa-west", DisplayName = "South Africa West", RegionalDisplayName = "(Africa) South Africa West" }; + public static Location SouthAfricaWest { get; } = CreateStaticReference("southafricawest", "South Africa West"); /// /// Public cloud location for Switzerland North. /// - public static readonly Location SwitzerlandNorth = new Location { Name = "switzerlandnorth", CanonicalName = "switzerland-north", DisplayName = "Switzerland North", RegionalDisplayName = "(Europe) Switzerland North" }; + public static Location SwitzerlandNorth { get; } = CreateStaticReference("switzerlandnorth", "Switzerland North"); /// /// Public cloud location for Switzerland West. /// - public static readonly Location SwitzerlandWest = new Location { Name = "switzerlandwest", CanonicalName = "switzerland-west", DisplayName = "Switzerland West", RegionalDisplayName = "(Europe) Switzerland West" }; + public static Location SwitzerlandWest { get; } = CreateStaticReference("switzerlandwest", "Switzerland West"); /// /// Public cloud location for Germany North. /// - public static readonly Location GermanyNorth = new Location { Name = "germanynorth", CanonicalName = "germany-north", DisplayName = "Germany North", RegionalDisplayName = "(Europe) Germany North" }; + public static Location GermanyNorth { get; } = CreateStaticReference("germanynorth", "Germany North"); /// /// Public cloud location for Germany West Central. /// - public static readonly Location GermanyWestCentral = new Location { Name = "germanywestcentral", CanonicalName = "germany-west-central", DisplayName = "Germany West Central", RegionalDisplayName = "(Europe) Germany West Central" }; + public static Location GermanyWestCentral { get; } = CreateStaticReference("germanywestcentral", "Germany West Central"); /// /// Public cloud location for Norway West. /// - public static readonly Location NorwayWest = new Location { Name = "norwaywest", CanonicalName = "norway-west", DisplayName = "Norway West", RegionalDisplayName = "(Europe) Norway West" }; + public static Location NorwayWest { get; } = CreateStaticReference("norwaywest", "Norway West"); /// /// Public cloud location for Brazil Southeast. /// - public static readonly Location BrazilSoutheast = new Location { Name = "brazilsoutheast", CanonicalName = "brazil-southeast", DisplayName = "Brazil Southeast", RegionalDisplayName = "(South America) Brazil Southeast" }; + public static Location BrazilSoutheast { get; } = CreateStaticReference("brazilsoutheast", "Brazil Southeast"); #endregion - private static readonly Dictionary PublicCloudLocations = new Dictionary() - { - { "EASTASIA", EastAsia }, - { "SOUTHEASTASIA", SoutheastAsia }, - { "CENTRALUS", CentralUS }, - { "EASTUS", EastUS }, - { "EASTUS2", EastUS2 }, - { "WESTUS", WestUS }, - { "NORTHCENTRALUS", NorthCentralUS }, - { "SOUTHCENTRALUS", SouthCentralUS }, - { "NORTHEUROPE", NorthEurope }, - { "WESTEUROPE", WestEurope }, - { "JAPANWEST", JapanWest }, - { "JAPANEAST", JapanEast }, - { "BRAZILSOUTH", BrazilSouth }, - { "AUSTRALIAEAST", AustraliaEast }, - { "AUSTRALIASOUTHEAST", AustraliaSoutheast }, - { "SOUTHINDIA", SouthIndia }, - { "CENTRALINDIA", CentralIndia }, - { "WESTINDIA", WestIndia }, - { "CANADACENTRAL", CanadaCentral }, - { "CANADAEAST", CanadaEast }, - { "UKSOUTH", UKSouth }, - { "UKWEST", UKWest }, - { "WESTCENTRALUS", WestCentralUS }, - { "WESTUS2", WestUS2 }, - { "KOREACENTRAL", KoreaCentral }, - { "KOREASOUTH", KoreaSouth }, - { "FRANCECENTRAL", FranceCentral }, - { "FRANCESOUTH", FranceSouth }, - { "AUSTRALIACENTRAL", AustraliaCentral }, - { "AUSTRALIACENTRAL2", AustraliaCentral2 }, - { "UAECENTRAL", UAECentral }, - { "UAENORTH", UAENorth }, - { "SOUTHAFRICANORTH", SouthAfricaNorth }, - { "SOUTHAFRICAWEST", SouthAfricaWest }, - { "SWITZERLANDNORTH", SwitzerlandNorth }, - { "SWITZERLANDWEST", SwitzerlandWest }, - { "GERMANYNORTH", GermanyNorth }, - { "GERMANYWESTCENTRAL", GermanyWestCentral }, - { "NORWAYWEST", NorwayWest }, - { "BRAZILSOUTHEAST", BrazilSoutheast }, - }; - - private const string CanonicalPattern = "^[a-z]+(-[a-z]+)+(-[1-9])?$"; - private const string DisplayPattern = "^[A-Z]+[a-z]*( [A-Z]+[a-z]*)+( [1-9])?$"; - private const string RegexDash = @"-"; - private const string RegexWhitespace = @" "; - - private Location(string location) + + /// Initializes a new instance of Location. + /// The location name or the display name. + public Location(string location) { - switch (DetectNameType(location)) + if (ReferenceEquals(location, null)) + throw new ArgumentNullException(nameof(location)); + + Name = GetNameFromDisplayName(location, out bool wasConverted); + var lookUp = wasConverted ? Name : location.ToLowerInvariant(); + if (PublicCloudLocations.TryGetValue(lookUp, out Location loc)) { - case NameType.Name: - Name = location; - CanonicalName = location; - DisplayName = location; - break; - case NameType.CanonicalName: - Name = GetDefaultNameFromCanonicalName(location); - CanonicalName = location; - DisplayName = GetDisplayNameFromCanonicalName(location); - break; - case NameType.DisplayName: - Name = GetDefaultNameFromDisplayName(location); - CanonicalName = GetCanonicalNameFromDisplayName(location); - DisplayName = location; - break; + Name = loc.Name; + DisplayName = loc.DisplayName; + } + else + { + DisplayName = wasConverted ? location : null; } - } - - private enum NameType - { - Name, - CanonicalName, - DisplayName, } /// Initializes a new instance of Location. /// The location name. /// 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)) + public Location(string name, string displayName) + { + if (ReferenceEquals(name, null)) + throw new ArgumentNullException(nameof(name)); + + Name = name; + DisplayName = displayName; + } + + private static string GetNameFromDisplayName(string name, out bool foundSpace) { + foundSpace = false; + StringBuilder sb = new StringBuilder(); + foreach (char c in name) + { + if (c == Space) + { + foundSpace = true; + continue; + } + + sb.Append(char.ToLowerInvariant(c)); + } + return foundSpace ? sb.ToString() : name; + } + + /// + /// Gets a location name consisting of only lowercase characters without white spaces or any separation character between words, e.g. "westus". + /// + public string Name { get; } + + /// + /// Gets a location display name consisting of titlecase words or alphanumeric characters separated by whitespaces, e.g. "West US". + /// + public string DisplayName { get; } + + private static Location CreateStaticReference(string name, string displayName) + { + Location location = new Location(name, displayName); + PublicCloudLocations.Add(name, location); + return location; } /// @@ -317,36 +299,21 @@ public override string ToString() /// /// Creates a new location implicitly from a string. /// - /// String to be assigned in the Name, CanonicalName or DisplayName form. + /// String to be assigned in the Name form. public static implicit operator Location(string other) { - if (ReferenceEquals(other, null)) - return null; - - var normalizedName = NormalizationUtility(other); - Location value; - if (PublicCloudLocations.TryGetValue(normalizedName, out value)) + if (!ReferenceEquals(other, null)) { - return value; + Location value; + if (PublicCloudLocations.TryGetValue(other, out value)) + { + return value; + } } return new Location(other); } - /// - /// Creates a string implicitly from a Location object. - /// - /// Location object to be assigned. - public static implicit operator string(Location other) - { - if (ReferenceEquals(other, null)) - { - return null; - } - - return other.ToString(); - } - /// /// Detects if a location object is equal to another location instance or a string representing the location name. /// @@ -354,104 +321,22 @@ public static implicit operator string(Location other) /// True or false. public bool Equals(Location other) { - if (ReferenceEquals(other, null)) - return false; - - return Name == other.Name && CanonicalName == other.CanonicalName && DisplayName == other.DisplayName; + return Name == other.Name; } /// - /// Compares this Location name to another Location to expose if it is greater, less or equal than this one. + /// Creates a string implicitly from a Location object. /// - /// Location object or name as a string. - /// -1 for less than, 0 for equals, 1 for greater than. - public int CompareTo(Location other) - { - if (ReferenceEquals(other, null)) - { - return 1; - } - - return string.Compare(Name, other.Name, StringComparison.InvariantCulture); - } - - private static string NormalizationUtility(string value) - { - if (string.IsNullOrEmpty(value)) - { - return value; - } - - var sb = new StringBuilder(value.Length); - for (var index = 0; index < value.Length; ++index) - { - var c = value[index]; - if (char.IsLetterOrDigit(c)) - { - sb.Append(c); - } - } - - return sb.ToString().ToUpperInvariant(); - } - - private static NameType DetectNameType(string location) - { - if (Regex.IsMatch(location, CanonicalPattern)) - { - return NameType.CanonicalName; - } - else if (Regex.IsMatch(location, DisplayPattern)) - { - return NameType.DisplayName; - } - else - { - return NameType.Name; - } - } - - private static string GetCanonicalNameFromDisplayName(string name) - { - return name.Replace(RegexWhitespace, RegexDash).ToLower(CultureInfo.InvariantCulture); - } - - private static string GetDisplayNameFromCanonicalName(string name) - { - char[] chName = name.ToCharArray(); - chName[0] = char.ToUpper(chName[0], CultureInfo.InvariantCulture); - - for (int i = 0; i < chName.Length - 1; i++) - { - if (chName[i] == '-') - { - chName[i] = ' '; - chName[i + 1] = char.ToUpper(chName[i + 1], CultureInfo.InvariantCulture); - } - } - - return new string(chName); - } - - private static string GetDefaultNameFromCanonicalName(string name) - { - return name.Replace(RegexDash, string.Empty); - } - - private static string GetDefaultNameFromDisplayName(string name) + /// Location object to be assigned. + public static implicit operator string(Location other) { - return name.Replace(RegexWhitespace, string.Empty).ToLower(CultureInfo.InvariantCulture); + return other.ToString(); } /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) { - if (ReferenceEquals(this, obj)) - { - return true; - } - if (ReferenceEquals(obj, null)) { return false; @@ -478,11 +363,6 @@ public override int GetHashCode() /// True if they are equal, otherwise false. public static bool operator ==(Location left, Location right) { - if (ReferenceEquals(left, null)) - { - return ReferenceEquals(right, null); - } - return left.Equals(right); } @@ -494,51 +374,7 @@ public override int GetHashCode() /// True if they are not equal, otherwise false. public static bool operator !=(Location left, Location right) { - return !(left == right); - } - - /// - /// Compares one with another instance. - /// - /// The object on the left side of the operator. - /// The object on the right side of the operator. - /// True if the left object is less than the right. - public static bool operator <(Location left, Location right) - { - return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; - } - - /// - /// Compares one with another instance. - /// - /// The object on the left side of the operator. - /// The object on the right side of the operator. - /// True if the left object is less than or equal to the right. - public static bool operator <=(Location left, Location right) - { - return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; - } - - /// - /// Compares one with another instance. - /// - /// The object on the left side of the operator. - /// The object on the right side of the operator. - /// True if the left object is greater than the right. - public static bool operator >(Location left, Location right) - { - return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; - } - - /// - /// Compares one with another instance. - /// - /// The object on the left side of the operator. - /// The object on the right side of the operator. - /// True if the left object is greater than or equal to the right. - public static bool operator >=(Location left, Location right) - { - return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + return !left.Equals(right); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/LocationExpanded.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/LocationExpanded.cs new file mode 100644 index 000000000000..b5706861a1bc --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Custom/Resources/Models/LocationExpanded.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.ResourceManager.Resources.Models +{ + public partial class LocationExpanded + { + /// + /// Convert LocationExpanded into a Location object. + /// + /// The location to convert. + public static implicit operator Location(LocationExpanded location) + { + return new Location(location.Name, location.DisplayName); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.Serialization.cs deleted file mode 100644 index fd7463c8a6a8..000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.Serialization.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System.Text.Json; -using Azure.Core; - -namespace Azure.ResourceManager.Resources.Models -{ - public partial class Location - { - internal static Location DeserializeLocation(JsonElement element) - { - Optional name = default; - Optional displayName = default; - Optional regionalDisplayName = default; - Optional metadata = default; - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("name")) - { - name = property.Value.GetString(); - continue; - } - if (property.NameEquals("displayName")) - { - displayName = property.Value.GetString(); - continue; - } - if (property.NameEquals("regionalDisplayName")) - { - regionalDisplayName = property.Value.GetString(); - continue; - } - if (property.NameEquals("metadata")) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - property.ThrowNonNullablePropertyIsNull(); - continue; - } - metadata = LocationMetadata.DeserializeLocationMetadata(property.Value); - continue; - } - } - return new Location(name.Value, displayName.Value, regionalDisplayName.Value); - } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.cs deleted file mode 100644 index 86eb4ce2b7b5..000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/Location.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using System.Text.RegularExpressions; - -namespace Azure.ResourceManager.Resources.Models -{ - /// - /// Represents an Azure geography region where supported resource providers live. - /// - public partial class Location - { - /// - /// Initializes a new instance of the class. - /// - protected Location() - { - } - - /// Initializes a new instance of Location. - /// The location name. - /// The display name of the location. - /// The display name of the location and its region. - /// The canonical name of the location. - internal Location(string name, string displayName, string regionalDisplayName, string canonicalName) - { - Name = name; - DisplayName = displayName; - RegionalDisplayName = regionalDisplayName; - CanonicalName = canonicalName; - } - - /// - /// Gets a location canonical name consisting of only lowercase chararters with a '-' between words, e.g. "west-us". - /// - public string CanonicalName { get; private set; } - - /// The display name of the location and its region. - public string RegionalDisplayName { get; private set; } - - /// - /// Gets a location name consisting of only lowercase characters without white spaces or any separation character between words, e.g. "westus". - /// - public string Name { get; private set; } - - /// - /// Gets a location display name consisting of titlecase words or alphanumeric characters separated by whitespaces, e.g. "West US" - /// - public string DisplayName { get; private set; } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.Serialization.cs index e2b0e11e3dd3..2ef4eeae2eb0 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.Serialization.cs @@ -14,10 +14,12 @@ public partial class LocationExpanded { internal static LocationExpanded DeserializeLocationExpanded(JsonElement element) { - Location loc = DeserializeLocation(element); + Optional name = default; + Optional displayName = default; Optional metadata = default; Optional id = default; Optional subscriptionId = default; + Optional regionalDisplayName = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) @@ -25,11 +27,26 @@ internal static LocationExpanded DeserializeLocationExpanded(JsonElement element id = property.Value.GetString(); continue; } + if (property.NameEquals("name")) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("displayName")) + { + displayName = property.Value.GetString(); + continue; + } if (property.NameEquals("subscriptionId")) { subscriptionId = property.Value.GetString(); continue; } + if (property.NameEquals("regionalDisplayName")) + { + regionalDisplayName = property.Value.GetString(); + continue; + } if (property.NameEquals("metadata")) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -41,7 +58,7 @@ internal static LocationExpanded DeserializeLocationExpanded(JsonElement element continue; } } - return new LocationExpanded(id.Value, subscriptionId.Value, loc.Name, loc.DisplayName, loc.RegionalDisplayName, metadata.Value); + return new LocationExpanded(id.Value, subscriptionId.Value, name.Value, displayName.Value, regionalDisplayName.Value, metadata.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 f5b79b72089e..869bc4e93f30 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/Models/LocationExpanded.cs @@ -12,7 +12,7 @@ namespace Azure.ResourceManager.Resources.Models /// /// Represents an Azure geography region where supported resource providers live. /// - public partial class LocationExpanded : Location + public partial class LocationExpanded { /// /// Initializes a new instance of the class. @@ -29,14 +29,22 @@ protected LocationExpanded() /// /// internal LocationExpanded(string id, string subscriptionId, string name, string displayName, string regionalDisplayName, LocationMetadata metadata) - : base(name, displayName, regionalDisplayName) { Metadata = metadata; Id = id; ResourceIdentifier subId = new ResourceIdentifier(id); SubscriptionId = subscriptionId ?? subId.SubscriptionId; + RegionalDisplayName = regionalDisplayName; + Name = name; + DisplayName = displayName; } + /// Gets a location name consisting of only lowercase characters without white spaces or any separation character between words, e.g. "westus". + public string Name { get; private set; } + + /// Gets a location display name consisting of titlecase words or alphanumeric characters separated by whitespaces, e.g. "West US". + public string DisplayName { get; private set; } + /// Metadata of the location, such as lat/long, paired region, and others. public LocationMetadata Metadata { get; } @@ -45,5 +53,8 @@ internal LocationExpanded(string id, string subscriptionId, string name, string /// SubscriptionId the Location is under. public string SubscriptionId { get; } + + /// The display name of the location and its region. + public string RegionalDisplayName { get; } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupCollection.cs index b66262ed93ee..a58128c7e57e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupCollection.cs @@ -158,9 +158,6 @@ public virtual async Task> CheckIfExistsAsync(string resourceGrou /// Location cannot be null. internal ResourceGroupBuilder Construct(Location location, IDictionary tags = default, string managedBy = default) { - if (location is null) - throw new ArgumentNullException(nameof(location)); - var model = new ResourceGroupData(location); if (!(tags is null)) model.Tags.ReplaceWith(tags); diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs index 9906c6edaf3c..8dcd12952a06 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/ResourceGroupData.cs @@ -14,12 +14,8 @@ public partial class ResourceGroupData : TrackedResource /// Initializes a new instance of ResourceGroupData. /// 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. /// is null. - public ResourceGroupData(string location) : base(location) + public ResourceGroupData(Location location) : base(location) { - if (location == null) - { - throw new ArgumentNullException(nameof(location)); - } } /// Initializes a new instance of ResourceGroupData. @@ -30,7 +26,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(ResourceIdentifier id, string name, string type, ResourceGroupProperties properties, string location, string managedBy, IDictionary tags) + internal ResourceGroupData(ResourceIdentifier id, string name, string type, ResourceGroupProperties properties, Location location, string managedBy, IDictionary tags) : base(id, name, type, tags, location) { Properties = properties; diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs index be2949004759..a1c9157af8e4 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/PsuedoGenerated/Resources/SubscriptionData.cs @@ -11,28 +11,14 @@ namespace Azure.ResourceManager.Resources /// /// A class representing the subscription data model. /// - public partial class SubscriptionData : TrackedResource + public partial class SubscriptionData { - /// Initializes a new instance of class. - /// The subscription id. - /// The subscription name. - /// The tags attached to the subscription. - /// The subscription resource type. - internal SubscriptionData(ResourceIdentifier id, - string displayName, - IDictionary tags, - string resourceType = "Microsoft.Resources/subscriptions") : base(id, displayName, resourceType, tags, null) - { - ManagedByTenants = new ChangeTrackingList(); - } - /// /// Initializes a new instance of the class. /// /// The subscription id. /// The subscription ID. /// The subscription name. - /// The subscription resource type. /// The subscription tenant ID. /// The subscription state. Possible values are Enabled, Warned, PastDue, Disabled, and Deleted. /// The subscription policies. @@ -47,9 +33,7 @@ internal SubscriptionData(ResourceIdentifier id, SubscriptionPolicies subscriptionPolicies, string authorizationSource, IReadOnlyList managedByTenants, - IDictionary tags, - string resourceType = "Microsoft.Resources/subscriptions") - : base(id, displayName, resourceType, tags, null) + IDictionary tags) { SubscriptionGuid = subscriptionId; DisplayName = displayName; @@ -58,6 +42,8 @@ internal SubscriptionData(ResourceIdentifier id, SubscriptionPolicies = subscriptionPolicies; AuthorizationSource = authorizationSource; ManagedByTenants = managedByTenants; + Tags = tags; + Id = id; } /// @@ -94,5 +80,13 @@ internal SubscriptionData(ResourceIdentifier id, /// Gets an array containing the tenants managing the subscription. /// public IReadOnlyList ManagedByTenants { get; } + + /// Resource tags. + public IDictionary Tags { get; } + + /// + /// Gets the ARM resource identifier. + /// + public virtual ResourceIdentifier Id { get; } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs index cb6021f578cf..4f8e50e477d2 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceIdentifier.cs @@ -228,7 +228,7 @@ internal string StringValue /// /// Gets the location if it exists otherwise null. /// - public Location Location { get; private set; } + public Location? Location { get; private set; } /// /// The name of the resource group if it exists otherwise null. diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmBuilderTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmBuilderTests.cs index 18a7990a2938..cc1738e425e7 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmBuilderTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/ArmBuilderTests.cs @@ -8,25 +8,23 @@ namespace Azure.ResourceManager.Tests { public class ArmBuilderTests : ResourceManagerTestBase { - private ArmClient _client; - public ArmBuilderTests(bool isAsync) : base(isAsync)//, RecordedTestMode.Record) { } - [SetUp] - public void SetUp() - { - _client = GetArmClient(); - } - [TestCase(null)] [TestCase(" ")] [RecordedTest] public void TestCreateOrUpdate(string value) { - Assert.ThrowsAsync(async delegate { await (await _client.GetDefaultSubscriptionAsync()).GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(value); }); + Assert.ThrowsAsync(async delegate + { + Subscription subscription = await Client.GetDefaultSubscriptionAsync(); + ResourceGroupCollection rgCollection = subscription.GetResourceGroups(); + ResourceGroupBuilder rgBuilder = rgCollection.Construct(Location.WestUS2); + await rgBuilder.CreateOrUpdateAsync(value); + }); } [TestCase(null)] @@ -34,7 +32,7 @@ public void TestCreateOrUpdate(string value) [RecordedTest] public void TestStartCreateOrUpdate(string value) { - Assert.ThrowsAsync(async delegate { await (await _client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(value, false); }); + Assert.ThrowsAsync(async delegate { await (await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(Location.WestUS2).CreateOrUpdateAsync(value, false); }); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs index 983927a35a6c..ced577a33111 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LocationExpandedTests.cs @@ -20,6 +20,12 @@ public async Task VerifyMetadata() { Assert.IsNotNull(loc.Metadata); Assert.IsNotNull(loc.SubscriptionId); + Assert.IsNotNull(loc.RegionalDisplayName); + + Location locStruct = loc; + + Assert.AreEqual(loc.Name, locStruct.Name); + Assert.AreEqual(loc.DisplayName, locStruct.DisplayName); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationResourceIdentifierTests.cs index 88f1f07b161a..7f5c98b31600 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.ToString()); + 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.ToString()); + 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.ToString()); + 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.ToString()); + 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.ToString()); + 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.ToString()); + 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.ToString()); + 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.ToString()); + 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.ToString()); + 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); @@ -138,7 +138,7 @@ public void TryGetPropertiesForLocationResource() 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.IsTrue(id1.Location.HasValue); Assert.AreEqual(Location.WestUS2, id1.Location); Assert.Null(id1.ResourceGroupName); ResourceIdentifier expectedId = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2"); diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs index f189de39e44a..04fa94da162c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/LocationTests.cs @@ -1,4 +1,5 @@ -using Azure.ResourceManager.Resources.Models; +using Azure.ResourceManager.Core; +using Azure.ResourceManager.Resources.Models; using NUnit.Framework; using System; @@ -7,45 +8,41 @@ namespace Azure.ResourceManager.Tests [Parallelizable] public class LocationTests { - [TestCase("westus", "westus", "west-us", "West US")] - [TestCase("west-us", "westus", "west-us", "West US")] - [TestCase("West US", "westus", "west-us", "West US")] - [TestCase("privatecloud", "privatecloud", "privatecloud", "privatecloud")] - [TestCase("private-cloud", "privatecloud", "private-cloud", "Private Cloud")] - [TestCase("Private Cloud", "privatecloud", "private-cloud", "Private Cloud")] - [TestCase("@$!()*&", "@$!()*&", "@$!()*&", "@$!()*&")] - [TestCase("W3$t U$ 2", "W3$t U$ 2", "W3$t U$ 2", "W3$t U$ 2")] - [TestCase("", "", "", "")] - [TestCase(" ", " ", " ", " ")] - [TestCase(null, null, null, null)] - public void CanCreateLocation(string name, string expectedName, string expectedCanonincalName, string expectedDisplayName) - { - Location location = name; - if (name == null) - { - Assert.IsNull(location); - } - else - { - Assert.AreEqual(expectedName, location.Name); - Assert.AreEqual(expectedCanonincalName, location.CanonicalName); - Assert.AreEqual(expectedDisplayName, location.DisplayName); - } - } - - [TestCase("USNorth")] - [TestCase("Us West 12")] - [TestCase("Us West 1a")] - [TestCase(" Us West 1")] - [TestCase("Us West 1 ")] - [TestCase("*Us West")] - [TestCase("Us *West")] - [TestCase("Us West *")] - [TestCase("")] - public void NameTypeIsName(string location) + [TestCase("WestUS2", "westus2", "West US 2")] + [TestCase("WestUS4", "WestUS4", null)] + [TestCase("West US 2", "westus2", "West US 2")] + [TestCase("WEst Us 2", "westus2", "West US 2")] + [TestCase("West Us 3", "westus3", "West Us 3")] + [TestCase("West-Us 2", "west-us2", "West-Us 2")] + [TestCase(" West Us 2", "westus2", "West US 2")] + [TestCase(" ", "", " ")] + [TestCase("", "", null)] + [TestCase("Us West", "uswest", "Us West")] + [TestCase("A B C 5", "abc5", "A B C 5")] + public void ConvertFromDisplayName(string input, string expectedName, string expectedDisplayName) + { + Location loc = input; + Assert.AreEqual(expectedName, loc.Name); + Assert.AreEqual(expectedDisplayName, loc.DisplayName); + } + + [TestCase("northcentralus", "northcentralus", "North Central US")] + [TestCase("westus2", "westus2", "West US 2")] + [TestCase("uswest1a", "uswest1a", null)] + [TestCase("uswest1", "uswest1", null)] + [TestCase("westus", "westus", "West US")] + [TestCase("westus ", "westus", "West US")] + [TestCase("Westus", "westus", "West US")] + [TestCase("XWestus", "XWestus", null)] + [TestCase("*uswest", "*uswest", null)] + [TestCase("us*west", "us*west", null)] + [TestCase("uswest*", "uswest*", null)] + [TestCase("", "", null)] + public void NameTypeIsName(string location, string expectedName, string expectedDisplayName) { Location loc = location; - Assert.IsTrue(loc.Name == loc.DisplayName && loc.Name == loc.CanonicalName); + Assert.AreEqual(expectedName, loc.Name); + Assert.AreEqual(expectedDisplayName, loc.DisplayName); } [TestCase("us-west")] @@ -56,22 +53,8 @@ public void NameTypeIsName(string location) public void NameTypeIsCanonical(string location) { Location loc = location; - Assert.IsTrue(loc.CanonicalName == location && loc.Name != location && loc.DisplayName != location); - } - - [TestCase("Us West")] - [TestCase("US West")] - [TestCase("USa West")] - [TestCase("West US")] - [TestCase("West USa")] - [TestCase("Us West West")] - [TestCase("Us West 2")] - [TestCase("Us West West 2")] - [TestCase("A B C 5")] - public void NameTypeIsDisplayName(string location) - { - Location loc = location; - Assert.IsTrue(loc.DisplayName == location && loc.Name != location && loc.CanonicalName != location); + Assert.AreEqual(location, loc.Name); + Assert.IsNull(loc.DisplayName); } [TestCase(true, "West Us", "West Us")] @@ -83,22 +66,20 @@ public void NameTypeIsDisplayName(string location) [TestCase(false, "West US", "")] [TestCase(false, "West US", "!#()@(#@")] [TestCase(false, "West US", "W3$t U$")] - [TestCase(false, "West US", null)] public void EqualsToLocation(bool expected, string left, string right) { Location loc1 = left; Location loc2 = right; Assert.AreEqual(expected, loc1.Equals(loc2)); - Assert.AreEqual(expected, loc1.GetHashCode() == loc2?.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({loc1.GetHashCode()}, {loc2?.GetHashCode()})"); + if(right != null) + Assert.AreEqual(expected, loc1.GetHashCode() == loc2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({loc1.GetHashCode()}, {loc2.GetHashCode()})"); + } - if (expected) - { - Assert.AreEqual(0, loc1.CompareTo(loc2)); - } - else - { - Assert.AreNotEqual(0, loc1.CompareTo(loc2)); - } + [Test] + public void NullNameInCtor() + { + Assert.Throws(() => { new Location(null, null); }); + Assert.DoesNotThrow(() => { new Location("test", null); }); } [Test] @@ -128,193 +109,37 @@ public void EqualsToObject() [TestCase(false, "West Us", "")] [TestCase(false, "West Us", "!#()@(#@")] [TestCase(false, "West Us", "W3$t U$")] - [TestCase(false, "West Us", null)] public void EqualsToString(bool expected, string left, string right) { Location location = left; Assert.AreEqual(expected, location.Equals(right)); - - if (expected) - { - Assert.AreEqual(0, location.CompareTo(right)); - } - else - { - Assert.AreNotEqual(0, location.CompareTo(right)); - } } - [TestCase("", "")] - [TestCase("West US", "westus")] - [TestCase("west-us", "westus")] - [TestCase("westus2", "westus2")] - [TestCase("private-cloud", "privatecloud")] - public void CanParseToString(string name, string expected) + [TestCase("West US", "westus", "West US")] + [TestCase("west-us", "west-us", null)] + [TestCase("westus", "westus", "West US")] + [TestCase("Private Cloud", "privatecloud", "Private Cloud")] + [TestCase("Private-cloud", "Private-cloud", null)] + [TestCase("privatecloud", "privatecloud", null)] + [TestCase("1$S#@$%^", "1$S#@$%^", null)] + [TestCase("", "", null)] + [TestCase(" ", "", " ")] + [TestCase(null, null, null)] + public void CanCastLocationToString(string name, string expectedName, string expectedDisplayName) { - Location location1 = name; - Assert.AreEqual(expected, location1.ToString()); - } - - [TestCase("West US", "West US", 0)] - [TestCase("West US", "west-us", 0)] - [TestCase("West US", "westus", 0)] - [TestCase("Central Europe", "Central Europe", 0)] - [TestCase("Central Europe", "central-europe", 0)] - [TestCase("Central Europe", "centraleurope", 0)] - [TestCase("South US", "East US", 1)] - [TestCase("South US", "east-us", 1)] - [TestCase("South US", "West US", -1)] - [TestCase("South US", "west-us", -1)] - [TestCase("South US", null, 1)] - public void CompareToObject(string left, string right, int expected) - { - Location location1 = left; - Location location2 = right; - Assert.AreEqual(expected, location1.CompareTo(location2)); - if (right != null) + if (name == null) { - Assert.AreEqual(expected * -1, location2.CompareTo(location1)); + Assert.Throws(()=> { Location location = name; }); } - } - - [TestCase("West US", "West US", 0)] - [TestCase("West US", "west-us", 0)] - [TestCase("West US", "westus", 0)] - [TestCase("Central Europe", "Central Europe", 0)] - [TestCase("Central Europe", "central-europe", 0)] - [TestCase("Central Europe", "centraleurope", 0)] - [TestCase("South US", "East US", 1)] - [TestCase("South US", "east-us", 1)] - [TestCase("South US", "West US", -1)] - [TestCase("South US", "west-us", -1)] - [TestCase("South US", null, 1)] - public void CompareToString(string left, string right, int expected) - { - Location location1 = left; - Assert.AreEqual(expected, location1.CompareTo(right)); - if (right != null) + else { - location1 = right; - Assert.AreEqual(expected * -1, location1.CompareTo(left)); + Location location = name; + string strLocation = location; + Assert.AreEqual(expectedName, strLocation); + Assert.AreEqual(expectedDisplayName, location.DisplayName); } } - [TestCase("West US", "westus")] - [TestCase("west-us", "westus")] - [TestCase("westus", "westus")] - [TestCase("Private Cloud", "privatecloud")] - [TestCase("private-cloud", "privatecloud")] - [TestCase("privatecloud", "privatecloud")] - [TestCase("1$S#@$%^", "1$S#@$%^")] - [TestCase("", "")] - [TestCase(" ", " ")] - [TestCase(null, null)] - public void CanCastLocationToString(string name, string expected) - { - Location location = name; - string strLocation = location; - 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)] - public void CanCastStringToLocation(string name, string expected) - { - Location location1 = name; - if (name == null) - Assert.Throws(() => { string x = location1.DisplayName; }); - else - Assert.AreEqual(expected, location1.DisplayName); - } - - [Test] - public void LessThanNull() - { - Location loc = Location.WestUS2; - Assert.IsTrue(null < loc); - Assert.IsFalse(loc < null); - } - - [Test] - public void LessThanOrEqualNull() - { - Location loc = Location.WestUS2; - Assert.IsTrue(null <= loc); - Assert.IsFalse(loc <= null); - } - - [Test] - public void GreaterThanNull() - { - Location loc = Location.WestUS2; - Assert.IsFalse(null > loc); - Assert.IsTrue(loc > null); - } - - [Test] - public void GreaterThanOrEqualNull() - { - Location loc = Location.WestUS2; - Assert.IsFalse(null >= loc); - Assert.IsTrue(loc >= null); - } - - [Test] - public void EqualOperatorNull() - { - Location loc = Location.WestUS2; - Assert.IsFalse(loc == null); - Assert.IsFalse(null == loc); - } - - [TestCase(false, "WESTUS2", "EASTUS2")] - [TestCase(true, "EASTUS2", "WESTUS2")] - [TestCase(false, "WESTUS2", "WESTUS2")] - public void LessThanOperator(bool expected, string string1, string string2) - { - Location loc1 = string1; - Location loc2 = string2; - Assert.AreEqual(expected, loc1 < loc2); - } - - [TestCase(false, "WESTUS2", "EASTUS2")] - [TestCase(true, "EASTUS2", "WESTUS2")] - [TestCase(true, "WESTUS2", "WESTUS2")] - public void LessThanOrEqualOperator(bool expected, string string1, string string2) - { - Location loc1 = string1; - Location loc2 = string2; - Assert.AreEqual(expected, loc1 <= loc2); - } - - [TestCase(true, "WESTUS2", "EASTUS2")] - [TestCase(false, "EASTUS2", "WESTUS2")] - [TestCase(false, "WESTUS2", "WESTUS2")] - public void GreaterThanOperator(bool expected, string string1, string string2) - { - Location loc1 = string1; - Location loc2 = string2; - Assert.AreEqual(expected, loc1 > loc2); - } - - [TestCase(true, "WESTUS2", "EASTUS2")] - [TestCase(false, "EASTUS2", "WESTUS2")] - [TestCase(true, "WESTUS2", "WESTUS2")] - public void GreaterThanOrEqualOperator(bool expected, string string1, string string2) - { - Location loc1 = string1; - Location loc2 = string2; - Assert.AreEqual(expected, loc1 >= loc2); - } - [TestCase(false, "WESTUS2", "EASTUS2")] [TestCase(false, "EASTUS2", "WESTUS2")] [TestCase(true, "WESTUS2", "WESTUS2")] diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs index 11403762a1cb..ad18e9775354 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceGroupResourceIdentifierTests.cs @@ -98,7 +98,7 @@ public void TryGetPropertiesForResourceGroupResource() 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.IsFalse(id1.Location.HasValue); Assert.NotNull(id1.ResourceGroupName); Assert.AreEqual("myRg", id1.ResourceGroupName); ResourceIdentifier expectedId = new ResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/resourceGroups/myRg"); diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs index f5c47c907c22..80f456c1bf8d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Unit/ResourceIdentifierTests.cs @@ -235,9 +235,9 @@ public void TryGetPropertiesForGenericResource(string resourceId, string subscri Assert.AreEqual(subscription is null, id1.SubscriptionId is null); if (!(subscription is null)) Assert.AreEqual(subscription, id1.SubscriptionId); - Assert.AreEqual(location is null, id1.Location is null); + Assert.AreEqual(location is null, !id1.Location.HasValue); if (!(location is null)) - Assert.AreEqual(location, id1.Location.Name); + Assert.AreEqual(location, id1.Location?.Name); Assert.AreEqual(resourceGroup is null, id1.ResourceGroupName is null); if (!(resourceGroup is null)) Assert.AreEqual(resourceGroup, id1.ResourceGroupName);