From 36e056b10dbba98deee721e6eb81a22128e9f645 Mon Sep 17 00:00:00 2001 From: m-nash Date: Tue, 29 Jun 2021 19:21:23 -0700 Subject: [PATCH 1/4] fix CA1036 --- .../src/ApiVersionsBase.cs | 66 ++++--- .../src/Azure.ResourceManager.Core.csproj | 3 +- .../src/Generated/Models/Plan.cs | 107 ++++++++++- .../src/Generated/Models/Sku.cs | 106 ++++++++++- .../src/Resources/LocationData.cs | 102 +++++++++- .../src/Resources/Resource.cs | 46 +---- .../src/Resources/ResourceIdentifier.cs | 44 +++++ .../src/Resources/ResourceType.cs | 65 +++++-- .../src/Resources/SubResource.cs | 33 +--- .../src/Resources/WritableSubResource.cs | 33 +--- .../tests/Unit/ApiVersionsBaseTests.cs | 40 ++++ .../tests/Unit/LocationTests.cs | 122 +++++++++++- .../tests/Unit/PlanTests.cs | 177 +++++++++++++---- .../tests/Unit/ResourceIdentifierTests.cs | 72 +++++++ .../tests/Unit/ResourceTests.cs | 65 ------- .../tests/Unit/ResourceTypeTests.cs | 80 ++++++++ .../tests/Unit/SkuTests.cs | 179 +++++++++++++----- .../tests/Unit/SubResourceTests.cs | 60 ------ .../tests/Unit/WritableSubResourceTests.cs | 65 ------- 19 files changed, 1028 insertions(+), 437 deletions(-) delete mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTests.cs delete mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs index f66ed787f113d..fa1eae6820712 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs @@ -30,10 +30,7 @@ protected ApiVersionsBase(string value) /// public static bool operator <(ApiVersionsBase left, ApiVersionsBase right) { - if (ReferenceEquals(null, left)) - return !ReferenceEquals(null, right); - - return left.CompareTo(right) == -1; + return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; } /// @@ -44,10 +41,7 @@ protected ApiVersionsBase(string value) /// public static bool operator >(ApiVersionsBase left, ApiVersionsBase right) { - if (ReferenceEquals(null, left)) - return false; - - return left.CompareTo(right) == 1; + return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; } /// @@ -69,47 +63,37 @@ public static implicit operator string(ApiVersionsBase version) /// /// API version value. public virtual ResourceType ResourceType {get; } - + /// /// Overrides == operator for comparing ApiVersionsBase object with string object. /// - /// The ApiVersionsBase object to compare. - /// The API version value in string to compare. + /// The ApiVersionsBase object to compare. + /// The API version value in string to compare. /// Comparison result in boolean. Equal returns true otherwise returns false. - public static bool operator ==(ApiVersionsBase first, string second) + public static bool operator ==(ApiVersionsBase left, string right) { - if (ReferenceEquals(null, first)) + if (ReferenceEquals(null, left)) { - return ReferenceEquals(null, second); + return ReferenceEquals(null, right); } - if (ReferenceEquals(null, second)) + if (ReferenceEquals(null, right)) { return false; } - return first.Equals(second); + return left.Equals(right); } /// /// Overrides != operator for comparing ApiVersionsBase object with string object. /// - /// The ApiVersionsBase object to compare. - /// The API version value in string to compare. + /// The ApiVersionsBase object to compare. + /// The API version value in string to compare. /// Comparison result in boolean. Equal returns false otherwise returns true. - public static bool operator !=(ApiVersionsBase first, string second) + public static bool operator !=(ApiVersionsBase left, string right) { - if (ReferenceEquals(null, first)) - { - return !ReferenceEquals(null, second); - } - - if (ReferenceEquals(null, second)) - { - return true; - } - - return !first.Equals(second); + return !(left == right); } /// @@ -205,5 +189,27 @@ public override int GetHashCode() { return _value.GetHashCode(); } + + /// + /// + /// + /// + /// + /// + public static bool operator <=(ApiVersionsBase left, ApiVersionsBase right) + { + return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >=(ApiVersionsBase left, ApiVersionsBase right) + { + return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj index 152ad5c686c14..5f533803aea22 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj @@ -8,12 +8,13 @@ This is a beta preview vesion. This version uses a next-generation code generator that introduces important breaking changes, but also new features (such as intuitive authentication, custom HTTP pipeline, distributed tracing and much more). azure;management;resource - $(NoWarn);AZC0008;AZC0107;CA2214;CA1036;CA1067;CA1065;SA1028 + $(NoWarn);CA2214;CA1067;CA1065;SA1028 true + diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs index 00eac4c30ac14..284086ffac619 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using System; +using System.Globalization; +using Azure.Core; namespace Azure.ResourceManager.Core { @@ -64,7 +66,7 @@ internal Plan(string name, string publisher, string product, string promotionCod /// -1 for less than, 0 for equals, 1 for greater than. public int CompareTo(Plan other) { - if (other == null) + if (ReferenceEquals(other, null)) return 1; if (ReferenceEquals(this, other)) @@ -90,7 +92,7 @@ public int CompareTo(Plan other) /// True if they are equals, otherwise false. public bool Equals(Plan other) { - if (other == null) + if (ReferenceEquals(other, null)) return false; if (ReferenceEquals(this, other)) @@ -102,5 +104,106 @@ public bool Equals(Plan other) string.Equals(Publisher, other.Publisher, StringComparison.InvariantCultureIgnoreCase) && string.Equals(Version, other.Version, StringComparison.InvariantCultureIgnoreCase); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (ReferenceEquals(obj, null)) + { + return false; + } + + if (obj is not Plan other) + return false; + + return Equals(other); + } + + /// + public override int GetHashCode() + { + return HashCodeBuilder.Combine( + Name?.ToLower(CultureInfo.InvariantCulture), + Publisher?.ToLower(CultureInfo.InvariantCulture), + Product?.ToLower(CultureInfo.InvariantCulture), + PromotionCode?.ToLower(CultureInfo.InvariantCulture), + Version?.ToLower(CultureInfo.InvariantCulture)); + } + + /// + /// + /// + /// + /// + /// + public static bool operator ==(Plan left, Plan right) + { + if (ReferenceEquals(left, null)) + { + return ReferenceEquals(right, null); + } + + return left.Equals(right); + } + + /// + /// + /// + /// + /// + /// + public static bool operator !=(Plan left, Plan right) + { + return !(left == right); + } + + /// + /// + /// + /// + /// + /// + public static bool operator <(Plan left, Plan right) + { + return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator <=(Plan left, Plan right) + { + return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >(Plan left, Plan right) + { + return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >=(Plan left, Plan right) + { + return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs index dd62f6ccac739..dee4274b0475a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using System; +using System.Globalization; +using Azure.Core; namespace Azure.ResourceManager.Core { @@ -76,7 +78,7 @@ public int CompareTo(Sku other) if (other == null) return 1; - if (object.ReferenceEquals(this, other)) + if (ReferenceEquals(this, other)) return 0; int compareResult = 0; @@ -112,5 +114,107 @@ public bool Equals(Sku other) string.Equals(Tier, other.Tier, StringComparison.InvariantCultureIgnoreCase) && long.Equals(Capacity, other.Capacity); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (ReferenceEquals(obj, null)) + { + return false; + } + + if (obj is not Sku other) + return false; + + return Equals(other); + } + + /// + public override int GetHashCode() + { + return HashCodeBuilder.Combine( + Name?.ToLower(CultureInfo.InvariantCulture), + Model?.ToLower(CultureInfo.InvariantCulture), + Family?.ToLower(CultureInfo.InvariantCulture), + Size?.ToLower(CultureInfo.InvariantCulture), + Tier?.ToLower(CultureInfo.InvariantCulture), + Capacity); + } + + /// + /// Compares this instance with another object and determines if they are equals. + /// + /// The sku on the left side of the operator. + /// The sku on the right side of the operator. + /// True if they are equals, otherwise false. + public static bool operator ==(Sku left, Sku right) + { + if (ReferenceEquals(left, null)) + { + return ReferenceEquals(right, null); + } + + return left.Equals(right); + } + + /// + /// Compares this instance with another object and determines if they are not equal. + /// + /// The sku on the left side of the operator. + /// The sku on the right side of the operator. + /// True if they are not equals, otherwise false. + public static bool operator !=(Sku left, Sku right) + { + return !(left == right); + } + + /// + /// Compares one with another instance. + /// + /// The sku on the left side of the operator. + /// The sku on the right side of the operator. + /// True if the left Sku is less than the right. + public static bool operator <(Sku left, Sku right) + { + return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; + } + + /// + /// Compares one with another instance. + /// + /// The sku on the left side of the operator. + /// The sku on the right side of the operator. + /// True if the left Sku is less than or equal to the right. + public static bool operator <=(Sku left, Sku right) + { + return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; + } + + /// + /// Compares one with another instance. + /// + /// The sku on the left side of the operator. + /// The sku on the right side of the operator. + /// True if the left Sku is greater than the right. + public static bool operator >(Sku left, Sku right) + { + return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; + } + + /// + /// Compares one with another instance. + /// + /// The sku on the left side of the operator. + /// The sku on the right side of the operator. + /// True if the left Sku is greater than or equal to the right. + public static bool operator >=(Sku left, Sku right) + { + return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs index a9770d8b24bd6..4e68a7b5ab260 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs @@ -328,7 +328,7 @@ private enum NameType /// String to be assigned in the Name, CanonicalName or DisplayName form. public static implicit operator LocationData(string other) { - if (other == null) + if (ReferenceEquals(other, null)) return null; var normalizedName = NormalizationUtility(other); @@ -347,7 +347,7 @@ public static implicit operator LocationData(string other) /// Location object to be assigned. public static implicit operator string(LocationData other) { - if (other == null) + if (ReferenceEquals(other, null)) { return null; } @@ -362,7 +362,7 @@ public static implicit operator string(LocationData other) /// True or false. public bool Equals(LocationData other) { - if (other == null) + if (ReferenceEquals(other, null)) return false; return Name == other.Name && CanonicalName == other.CanonicalName && DisplayName == other.DisplayName; @@ -459,5 +459,101 @@ private static string GetDefaultNameFromDisplayName(string name) { return name.Replace(RegexWhitespace, string.Empty).ToLower(CultureInfo.InvariantCulture); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (ReferenceEquals(obj, null)) + { + return false; + } + + if (obj is not LocationData other) + return false; + + return Equals(other); + } + + /// + public override int GetHashCode() + { + return Name.GetHashCode(); + } + + /// + /// + /// + /// + /// + /// + public static bool operator ==(LocationData left, LocationData right) + { + if (ReferenceEquals(left, null)) + { + return ReferenceEquals(right, null); + } + + return left.Equals(right); + } + + /// + /// + /// + /// + /// + /// + public static bool operator !=(LocationData left, LocationData right) + { + return !(left == right); + } + + /// + /// + /// + /// + /// + /// + public static bool operator <(LocationData left, LocationData right) + { + return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator <=(LocationData left, LocationData right) + { + return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >(LocationData left, LocationData right) + { + return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >=(LocationData left, LocationData right) + { + return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs index befebf7f9a56b..8c6085ce34c56 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs @@ -9,8 +9,8 @@ namespace Azure.ResourceManager.Core /// A class representing the base resource used by all azure resources. /// [ReferenceType(typeof(TenantResourceIdentifier))] - public abstract class Resource : IEquatable>, IEquatable, - IComparable>, IComparable where TIdentifier : TenantResourceIdentifier + public abstract class Resource + where TIdentifier : TenantResourceIdentifier { /// /// Initializes an empty instance of . @@ -46,47 +46,5 @@ protected internal Resource(TIdentifier id, string name, ResourceType type) /// Gets the resource type. /// public virtual ResourceType Type { get; } - - /// - public virtual int CompareTo(Resource other) - { - if (other == null) - return 1; - - if (ReferenceEquals(this, other)) - return 0; - - int compareResult = 0; - if ((compareResult = string.Compare(Id, other.Id, StringComparison.InvariantCultureIgnoreCase)) == 0 && - (compareResult = string.Compare(Name, other.Name, StringComparison.InvariantCultureIgnoreCase)) == 0 && - (compareResult = Type.CompareTo(other.Type)) == 0) - return 0; - - return compareResult; - } - - /// - public virtual int CompareTo(string other) - { - return string.Compare(Id, other, StringComparison.InvariantCultureIgnoreCase); - } - - /// - public virtual bool Equals(Resource other) - { - if (Id == null) - return false; - - return Id.Equals(other?.Id); - } - - /// - public virtual bool Equals(string other) - { - if (Id == null) - return false; - - return Id.Equals(other); - } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs index 7961bfa2bf1a5..478a095b1be70 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs @@ -526,5 +526,49 @@ public override int GetHashCode() { return !ResourceIdentifier.Equals(id1,id2); } + + /// + /// + /// + /// + /// + /// + public static bool operator <(ResourceIdentifier left, ResourceIdentifier right) + { + return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator <=(ResourceIdentifier left, ResourceIdentifier right) + { + return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >(ResourceIdentifier left, ResourceIdentifier right) + { + return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >=(ResourceIdentifier left, ResourceIdentifier right) + { + return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs index 41b837798b81d..75000f75c5316 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace Azure.ResourceManager.Core @@ -52,10 +53,6 @@ internal ResourceType(ResourceType parent, string childType) { } - private ResourceType() - { - } - /// /// Gets the resource type Namespace. /// @@ -136,10 +133,7 @@ public static implicit operator string(ResourceType other) /// False if they are equal, otherwise True. public static bool operator !=(ResourceType left, ResourceType right) { - if (left is null) - return !(right is null); - - return !left.Equals(right); + return !(left == right); } /// @@ -186,26 +180,29 @@ public override string ToString() /// public override bool Equals(object other) { + if (ReferenceEquals(this, other)) + return true; + if (other is null) return false; var resourceObj = other as ResourceType; - if (!(resourceObj is null)) + if (resourceObj is not null) return Equals(resourceObj); var stringObj = other as string; - if (stringObj != null) + if (stringObj is not null) return Equals(stringObj); - return base.Equals(other); + return false; } /// public override int GetHashCode() { - return ToString().GetHashCode(); + return ToString().ToLower(CultureInfo.InvariantCulture).GetHashCode(); } /// @@ -247,5 +244,49 @@ private void Parse(string resourceIdOrType) Namespace = id.ResourceType.Namespace; } } + + /// + /// + /// + /// + /// + /// + public static bool operator <(ResourceType left, ResourceType right) + { + return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator <=(ResourceType left, ResourceType right) + { + return ReferenceEquals(left, null) || left.CompareTo(right) <= 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >(ResourceType left, ResourceType right) + { + return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; + } + + /// + /// + /// + /// + /// + /// + public static bool operator >=(ResourceType left, ResourceType right) + { + return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs index ca0e7e62b93c7..f876b63ab7844 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -30,8 +30,7 @@ protected internal SubResource(string id) : base(id) { } /// [ReferenceType(typeof(ResourceIdentifier))] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")] - public partial class SubResource : IEquatable>, IEquatable, - IComparable>, IComparable + public partial class SubResource where TIdentifier : ResourceIdentifier { /// @@ -55,35 +54,5 @@ protected internal SubResource(string id) /// /// public virtual TIdentifier Id { get; } - - /// - public int CompareTo(string other) - { - return string.Compare(Id, other, StringComparison.InvariantCultureIgnoreCase); - } - - /// - public int CompareTo(SubResource other) - { - if (other is null) - return 1; - - if (ReferenceEquals(this, other)) - return 0; - - return Id.CompareTo(other.Id); - } - - /// - public bool Equals(SubResource other) - { - return Id.Equals(other?.Id); - } - - /// - public bool Equals(string other) - { - return Id.Equals(other); - } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs index 6427d54739054..6c5506660b7bf 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; namespace Azure.ResourceManager.Core { @@ -30,8 +31,7 @@ protected internal WritableSubResource(string id) : base(id) { } /// [ReferenceType(typeof(ResourceIdentifier))] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")] - public partial class WritableSubResource : IEquatable>, IEquatable, - IComparable>, IComparable + public partial class WritableSubResource where TIdentifier : ResourceIdentifier { /// @@ -55,34 +55,5 @@ protected internal WritableSubResource(string id) /// /// public virtual TIdentifier Id { get; set; } - - /// - public int CompareTo(string other) - { - return string.Compare(Id, other, StringComparison.InvariantCultureIgnoreCase); - } - - /// - public int CompareTo(WritableSubResource other) - { - if (other is null) - return 1; - - if (ReferenceEquals(this, other)) - return 0; - return Id.CompareTo(other.Id); - } - - /// - public bool Equals(WritableSubResource other) - { - return Id.Equals(other?.Id); - } - - /// - public bool Equals(string other) - { - return Id.Equals(other); - } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ApiVersionsBaseTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ApiVersionsBaseTests.cs index 5c8e8b8f6ac55..f5ed047125f40 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ApiVersionsBaseTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ApiVersionsBaseTests.cs @@ -225,9 +225,20 @@ public void TestGreaterThanTrue(string leftString, string rightString) Assert.IsTrue(left > right); } + [TestCase("2019-12-01", null)] + [TestCase("2020-06-01", "2019-12-01")] + [TestCase("2020-06-01", "2020-06-01")] + public void TestGreaterThanOrEqualTrue(string leftString, string rightString) + { + FakeResourceApiVersions left = ConvertFromString(leftString); + FakeResourceApiVersions right = ConvertFromString(rightString); + Assert.IsTrue(left >= right); + } + [TestCase(null, "2019-12-01")] [TestCase("2019-12-01", "2020-06-01")] [TestCase(null, null)] + [TestCase("2020-06-01", "2020-06-01")] public void TestGreaterThanFalse(string leftString, string rightString) { FakeResourceApiVersions left = ConvertFromString(leftString); @@ -235,6 +246,15 @@ public void TestGreaterThanFalse(string leftString, string rightString) Assert.IsFalse(left > right); } + [TestCase(null, "2019-12-01")] + [TestCase("2019-12-01", "2020-06-01")] + public void TestGreaterThanOrEqualFalse(string leftString, string rightString) + { + FakeResourceApiVersions left = ConvertFromString(leftString); + FakeResourceApiVersions right = ConvertFromString(rightString); + Assert.IsFalse(left >= right); + } + [TestCase(null, "2019-12-01")] [TestCase("2019-12-01-foobar", "2019-12-01-preview-1")] public void TestLessThanTrue(string leftString, string rightString) @@ -244,9 +264,20 @@ public void TestLessThanTrue(string leftString, string rightString) Assert.IsTrue(left < right); } + [TestCase(null, "2019-12-01")] + [TestCase("2019-12-01-foobar", "2019-12-01-preview-1")] + [TestCase("2020-06-01", "2020-06-01")] + public void TestLessThanOrEqualTrue(string leftString, string rightString) + { + FakeResourceApiVersions left = ConvertFromString(leftString); + FakeResourceApiVersions right = ConvertFromString(rightString); + Assert.IsTrue(left <= right); + } + [TestCase("2019-12-01", null)] [TestCase("2020-06-01", "2019-12-01-foobar")] [TestCase(null, null)] + [TestCase("2020-06-01", "2020-06-01")] public void TestLessThanFalse(string leftString, string rightString) { FakeResourceApiVersions left = ConvertFromString(leftString); @@ -254,6 +285,15 @@ public void TestLessThanFalse(string leftString, string rightString) Assert.IsFalse(left < right); } + [TestCase("2019-12-01", null)] + [TestCase("2020-06-01", "2019-12-01-foobar")] + public void TestLessThanOrEqualFalse(string leftString, string rightString) + { + FakeResourceApiVersions left = ConvertFromString(leftString); + FakeResourceApiVersions right = ConvertFromString(rightString); + Assert.IsFalse(left <= right); + } + [TestCase] public void ValidateClone() { diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/LocationTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/LocationTests.cs index db1d3d214c681..584a90de1c7cb 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/LocationTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/LocationTests.cs @@ -83,11 +83,12 @@ public void NameTypeIsDisplayName(string location) [TestCase(false, "West US", "!#()@(#@")] [TestCase(false, "West US", "W3$t U$")] [TestCase(false, "West US", null)] - public void EqualsToObject(bool expected, string left, string right) + public void EqualsToLocation(bool expected, string left, string right) { LocationData loc1 = left; LocationData 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 (expected) { @@ -99,6 +100,24 @@ public void EqualsToObject(bool expected, string left, string right) } } + [Test] + public void EqualsToObject() + { + LocationData loc = LocationData.WestUS2; + + object intLoc = 5; + Assert.IsFalse(loc.Equals(intLoc)); + + object nullLoc = null; + Assert.IsFalse(loc.Equals(nullLoc)); + + object sameLoc = loc; + Assert.IsTrue(loc.Equals(sameLoc)); + + object loc2 = LocationData.EastUS2; + Assert.IsFalse(loc.Equals(loc2)); + } + [TestCase(true, "West Us", "West Us")] [TestCase(true, "West Us", "WestUs")] [TestCase(true, "!#()@(#@", "!#()@(#@")] @@ -222,5 +241,106 @@ public void CanAccessDefaultLocation() LocationData location = LocationData.Default; Assert.IsTrue(location.Equals(LocationData.Default)); } + + [Test] + public void LessThanNull() + { + LocationData loc = LocationData.WestUS2; + Assert.IsTrue(null < loc); + Assert.IsFalse(loc < null); + } + + [Test] + public void LessThanOrEqualNull() + { + LocationData loc = LocationData.WestUS2; + Assert.IsTrue(null <= loc); + Assert.IsFalse(loc <= null); + } + + [Test] + public void GreaterThanNull() + { + LocationData loc = LocationData.WestUS2; + Assert.IsFalse(null > loc); + Assert.IsTrue(loc > null); + } + + [Test] + public void GreaterThanOrEqualNull() + { + LocationData loc = LocationData.WestUS2; + Assert.IsFalse(null >= loc); + Assert.IsTrue(loc >= null); + } + + [Test] + public void EqualOperatorNull() + { + LocationData loc = LocationData.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) + { + LocationData loc1 = string1; + LocationData 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) + { + LocationData loc1 = string1; + LocationData 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) + { + LocationData loc1 = string1; + LocationData 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) + { + LocationData loc1 = string1; + LocationData loc2 = string2; + Assert.AreEqual(expected, loc1 >= loc2); + } + + [TestCase(false, "WESTUS2", "EASTUS2")] + [TestCase(false, "EASTUS2", "WESTUS2")] + [TestCase(true, "WESTUS2", "WESTUS2")] + public void EqualOperator(bool expected, string string1, string string2) + { + LocationData loc1 = string1; + LocationData loc2 = string2; + Assert.AreEqual(expected, loc1 == loc2); + } + + [TestCase(true, "WESTUS2", "EASTUS2")] + [TestCase(true, "EASTUS2", "WESTUS2")] + [TestCase(false, "WESTUS2", "WESTUS2")] + public void NotEqualOperator(bool expected, string string1, string string2) + { + LocationData loc1 = string1; + LocationData loc2 = string2; + Assert.AreEqual(expected, loc1 != loc2); + } + } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/PlanTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/PlanTests.cs index d8fd8e2273ba2..1403ed3481734 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/PlanTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/PlanTests.cs @@ -117,14 +117,8 @@ public void EqualsToName(bool expected, string name1, string name2) { Plan plan1 = new Plan(name1, null, null, null, null); Plan plan2 = new Plan(name2, null, null, null, null); - if (expected) - { - Assert.IsTrue(plan1.Equals(plan2)); - } - else - { - Assert.IsFalse(plan1.Equals(plan2)); - } + Assert.AreEqual(expected, plan1.Equals(plan2), "Plans did not match expected equality"); + Assert.AreEqual(expected, plan1.GetHashCode() == plan2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({plan1.GetHashCode()}, {plan2.GetHashCode()})"); } [TestCase(true, "product", "product")] @@ -138,14 +132,8 @@ public void EqualsToProduct(bool expected, string product1, string product2) { Plan plan1 = new Plan(null, null, product1, null, null); Plan plan2 = new Plan(null, null, product2, null, null); - if (expected) - { - Assert.IsTrue(plan1.Equals(plan2)); - } - else - { - Assert.IsFalse(plan1.Equals(plan2)); - } + Assert.AreEqual(expected, plan1.Equals(plan2), "Plans did not match expected equality"); + Assert.AreEqual(expected, plan1.GetHashCode() == plan2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({plan1.GetHashCode()}, {plan2.GetHashCode()})"); } [TestCase(true, "promotionCode", "promotionCode")] @@ -159,14 +147,8 @@ public void EqualsToPromotionCode(bool expected, string promotionCode1, string p { Plan plan1 = new Plan(null, null, null, promotionCode1, null); Plan plan2 = new Plan(null, null, null, promotionCode2, null); - if (expected) - { - Assert.IsTrue(plan1.Equals(plan2)); - } - else - { - Assert.IsFalse(plan1.Equals(plan2)); - } + Assert.AreEqual(expected, plan1.Equals(plan2), "Plans did not match expected equality"); + Assert.AreEqual(expected, plan1.GetHashCode() == plan2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({plan1.GetHashCode()}, {plan2.GetHashCode()})"); } [TestCase(true, "publisher", "publisher")] @@ -180,14 +162,8 @@ public void EqualsToPublisher(bool expected, string publisher1, string publisher { Plan plan1 = new Plan(null, publisher1, null, null, null); Plan plan2 = new Plan(null, publisher2, null, null, null); - if (expected) - { - Assert.IsTrue(plan1.Equals(plan2)); - } - else - { - Assert.IsFalse(plan1.Equals(plan2)); - } + Assert.AreEqual(expected, plan1.Equals(plan2), "Plans did not match expected equality"); + Assert.AreEqual(expected, plan1.GetHashCode() == plan2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({plan1.GetHashCode()}, {plan2.GetHashCode()})"); } [TestCase(true, "version", "version")] @@ -201,14 +177,8 @@ public void EqualsToVersion(bool expected, string version1, string version2) { Plan plan1 = new Plan(null, null, null, null, version1); Plan plan2 = new Plan(null, null, null, null, version2); - if (expected) - { - Assert.IsTrue(plan1.Equals(plan2)); - } - else - { - Assert.IsFalse(plan1.Equals(plan2)); - } + Assert.AreEqual(expected, plan1.Equals(plan2), "Plans did not match expected equality"); + Assert.AreEqual(expected, plan1.GetHashCode() == plan2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({plan1.GetHashCode()}, {plan2.GetHashCode()})"); } [Test] @@ -223,7 +193,16 @@ public void EqualsToNullPlan() public void EqualsToObject() { Plan plan1 = new Plan(null, null, null, null, null); - object plan2 = "random"; + object stringPlan = "random"; + Assert.IsFalse(plan1.Equals(stringPlan)); + + object nullObject = null; + Assert.IsFalse(plan1.Equals(nullObject)); + + object samePlan = plan1; + Assert.IsTrue(plan1.Equals(samePlan)); + + object plan2 = new Plan("Plan2", null, null, null, null); Assert.IsFalse(plan1.Equals(plan2)); } @@ -271,5 +250,121 @@ public void InvalidDeserializationTest() Assert.IsTrue(plan.Publisher == null); Assert.IsTrue(plan.PromotionCode == null); } + + [Test] + public void LessThanNull() + { + Plan plan = new Plan("PlanName", null, null, "PlanPromoCode", null); + Assert.IsTrue(null < plan); + Assert.IsFalse(plan < null); + } + + [Test] + public void LessThanOrEqualNull() + { + Plan plan = new Plan("PlanName", null, null, "PlanPromoCode", null); + Assert.IsTrue(null <= plan); + Assert.IsFalse(plan <= null); + } + + [Test] + public void GreaterThanNull() + { + Plan plan = new Plan("PlanName", null, null, "PlanPromoCode", null); + Assert.IsFalse(null > plan); + Assert.IsTrue(plan > null); + } + + [Test] + public void GreaterThanOrEqualNull() + { + Plan plan = new Plan("PlanName", null, null, "PlanPromoCode", null); + Assert.IsFalse(null >= plan); + Assert.IsTrue(plan >= null); + } + + [TestCase(false, "Nameb", "namea", "familya", "Familyb")] + [TestCase(false, "Nameb", "namea", "familya", "familya")] + [TestCase(false, "namea", "namea", "familya", "familya")] + [TestCase(true, "namea", "Nameb", "Familyb", "familya")] + public void LessThanOperator(bool expected, string name1, string name2, string promo1, string promo2) + { + Plan plan1 = new Plan(name1, null, null, promo1, null); + Plan plan2 = new Plan(name2, null, null, promo2, null); + Assert.AreEqual(expected, plan1 < plan2); + } + + [TestCase(false, "Nameb", "namea", "familya", "Familyb")] + [TestCase(false, "Nameb", "namea", "familya", "familya")] + [TestCase(true, "namea", "namea", "familya", "familya")] + [TestCase(true, "namea", "Nameb", "Familyb", "familya")] + public void LessThanOrEqualOperator(bool expected, string name1, string name2, string promo1, string promo2) + { + Plan plan1 = new Plan(name1, null, null, promo1, null); + Plan plan2 = new Plan(name2, null, null, promo2, null); + Assert.AreEqual(expected, plan1 <= plan2); + } + + [TestCase(true, "Nameb", "namea", "familya", "Familyb")] + [TestCase(true, "Nameb", "namea", "familya", "familya")] + [TestCase(false, "namea", "namea", "familya", "familya")] + [TestCase(false, "namea", "Nameb", "Familyb", "familya")] + public void GreaterThanOperator(bool expected, string name1, string name2, string promo1, string promo2) + { + Plan plan1 = new Plan(name1, null, null, promo1, null); + Plan plan2 = new Plan(name2, null, null, promo2, null); + Assert.AreEqual(expected, plan1 > plan2); + } + + [TestCase(true, "Nameb", "namea", "familya", "Familyb")] + [TestCase(true, "Nameb", "namea", "familya", "familya")] + [TestCase(true, "namea", "namea", "familya", "familya")] + [TestCase(false, "namea", "Nameb", "Familyb", "familya")] + public void GreaterThanOrEqualOperator(bool expected, string name1, string name2, string promo1, string promo2) + { + Plan plan1 = new Plan(name1, null, null, promo1, null); + Plan plan2 = new Plan(name2, null, null, promo2, null); + Assert.AreEqual(expected, plan1 >= plan2); + } + + [TestCase(true, "name", "name", "family", "family")] + [TestCase(true, "Name", "name", "Family", "family")] + [TestCase(false, "name", "name1", "family", "family")] + [TestCase(false, "Name", "name", "Family", "family1")] + [TestCase(true, null, null, null, null)] + [TestCase(false, "name", null, "family", null)] + [TestCase(false, null, "name", null, "family")] + [TestCase(true, "${?/>._`", "${?/>._`", "${?/>._`", "${?/>._`")] + [TestCase(false, "${?/>._`", "", "${?/>._`", "")] + public void EqualsToOperator(bool expected, string name1, string name2, string promo1, string promo2) + { + Plan plan1 = new Plan(name1, null, null, promo1, null); + Plan plan2 = new Plan(name2, null, null, promo2, null); + Assert.AreEqual(expected, plan1 == plan2); + } + + [TestCase(false, "name", "name", "family", "family")] + [TestCase(false, "Name", "name", "Family", "family")] + [TestCase(true, "name", "name1", "family", "family")] + [TestCase(true, "Name", "name", "Family", "family1")] + [TestCase(false, null, null, null, null)] + [TestCase(true, "name", null, "family", null)] + [TestCase(true, null, "name", null, "family")] + [TestCase(false, "${?/>._`", "${?/>._`", "${?/>._`", "${?/>._`")] + [TestCase(true, "${?/>._`", "", "${?/>._`", "")] + public void NotEqualsToOperator(bool expected, string name1, string name2, string promo1, string promo2) + { + Plan plan1 = new Plan(name1, null, null, promo1, null); + Plan plan2 = new Plan(name2, null, null, promo2, null); + Assert.AreEqual(expected, plan1 != plan2); + } + + [Test] + public void EqualOperatorNull() + { + Plan plan1 = new Plan("PlanName", null, null, "PlanPromo", null); + Assert.IsFalse(plan1 == null); + Assert.IsFalse(null == plan1); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs index 605a8cabb0fb2..d692e1d6d7cd8 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs @@ -731,5 +731,77 @@ public void NotEqualsOperator(string resourceProviderID1, string resourceProvide Assert.AreEqual(expected, a != resourceProviderID2); } } + + [TestCase(false, TrackedResourceId, TrackedResourceId)] + [TestCase(true, TrackedResourceId, ChildResourceId)] + [TestCase(false, ChildResourceId, TrackedResourceId)] + public void LessThanOperator(bool expected, string string1, string string2) + { + ResourceIdentifier id1 = string1; + ResourceIdentifier id2 = string2; + Assert.AreEqual(expected, id1 < id2); + } + + [TestCase(true, TrackedResourceId, TrackedResourceId)] + [TestCase(true, TrackedResourceId, ChildResourceId)] + [TestCase(false, ChildResourceId, TrackedResourceId)] + public void LessThanOrEqualOperator(bool expected, string string1, string string2) + { + ResourceIdentifier id1 = string1; + ResourceIdentifier id2 = string2; + Assert.AreEqual(expected, id1 <= id2); + } + + [TestCase(false, TrackedResourceId, TrackedResourceId)] + [TestCase(false, TrackedResourceId, ChildResourceId)] + [TestCase(true, ChildResourceId, TrackedResourceId)] + public void GreaterThanOperator(bool expected, string string1, string string2) + { + ResourceIdentifier id1 = string1; + ResourceIdentifier id2 = string2; + Assert.AreEqual(expected, id1 > id2); + } + + [TestCase(true, TrackedResourceId, TrackedResourceId)] + [TestCase(false, TrackedResourceId, ChildResourceId)] + [TestCase(true, ChildResourceId, TrackedResourceId)] + public void GreaterThanOrEqualOperator(bool expected, string string1, string string2) + { + ResourceIdentifier id1 = string1; + ResourceIdentifier id2 = string2; + Assert.AreEqual(expected, id1 >= id2); + } + + [Test] + public void LessThanNull() + { + ResourceIdentifier id = TrackedResourceId; + Assert.IsTrue(null < id); + Assert.IsFalse(id < null); + } + + [Test] + public void LessThanOrEqualNull() + { + ResourceIdentifier id = TrackedResourceId; + Assert.IsTrue(null <= id); + Assert.IsFalse(id <= null); + } + + [Test] + public void GreaterThanNull() + { + ResourceIdentifier id = TrackedResourceId; + Assert.IsFalse(null > id); + Assert.IsTrue(id > null); + } + + [Test] + public void GreaterThanOrEqualNull() + { + ResourceIdentifier id = TrackedResourceId; + Assert.IsFalse(null >= id); + Assert.IsTrue(id >= null); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTests.cs deleted file mode 100644 index 4bb596b7c7ede..0000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using NUnit.Framework; - -namespace Azure.ResourceManager.Core.Tests -{ - [Parallelizable] - public class ResourceTests - { - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] - [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - public void CompareToObject(int expected, string id1, string id2) - { - TestResource resource1 = new TestResource(id1); - TestResource resource2 = new TestResource(id2); - Assert.AreEqual(expected, resource1.CompareTo(resource2)); - } - - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] - [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - public void CompareToString(int expected, string id1, string id2) - { - TestResource resource1 = new TestResource(id1); - Assert.AreEqual(expected, resource1.CompareTo(id2)); - } - - [Test] - public void CompareToNull() - { - var resource1 = new TestResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); - TestResource resource2 = null; - Assert.AreEqual(1, resource1.CompareTo(resource2)); - Assert.AreEqual(1, resource1.CompareTo((string)null)); - } - - [Test] - public void CompareToSame() - { - var resource1 = new TestResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); - var resource2 = resource1; - Assert.AreEqual(0, resource1.CompareTo(resource2)); - } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs index b0b3bfe766086..1507a2750e54f 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs @@ -174,6 +174,7 @@ public void EqualsOpResourceTypeToResourceType(bool expected, string left, strin ResourceType leftResource = left; ResourceType rightResource = right; Assert.AreEqual(expected, leftResource == rightResource); + Assert.AreEqual(expected, leftResource?.GetHashCode() == rightResource?.GetHashCode()); } [TestCase(true, null, "Microsoft.Network1/VirtualNetworks2/subnets1")] @@ -229,6 +230,13 @@ public void EqualsWithObjectResourceType(bool expected, string left, string righ ResourceType rightRt = right; object rightObject = rightRt; Assert.AreEqual(expected, rt.Equals(rightObject)); + Assert.AreEqual(expected, rt?.GetHashCode() == rightRt?.GetHashCode()); + + object sameRt = rt; + Assert.IsTrue(rt.Equals(sameRt)); + + object intRt = 5; + Assert.IsFalse(rt.Equals(intRt)); } [TestCase(false, "Microsoft.Network1/VirtualNetworks2/subnets1", null)] @@ -277,5 +285,77 @@ public void ValidateIsParentOf(string childId, string parentId, bool expectedEqu ResourceType parentRt = parentId; Assert.AreEqual(expectedEquals, parentRt.IsParentOf(childRt)); } + + [TestCase(false, "Microsoft.Network/virtualNetworks/subnets2", "Microsoft.Network/virtualNetworks/subnets1")] + [TestCase(true, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets2")] + [TestCase(false, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets1")] + public void LessThanOperator(bool expected, string string1, string string2) + { + ResourceType rt1 = string1; + ResourceType rt2 = string2; + Assert.AreEqual(expected, rt1 < rt2); + } + + [TestCase(false, "Microsoft.Network/virtualNetworks/subnets2", "Microsoft.Network/virtualNetworks/subnets1")] + [TestCase(true, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets2")] + [TestCase(true, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets1")] + public void LessThanOrEqualOperator(bool expected, string string1, string string2) + { + ResourceType rt1 = string1; + ResourceType rt2 = string2; + Assert.AreEqual(expected, rt1 <= rt2); + } + + [TestCase(true, "Microsoft.Network/virtualNetworks/subnets2", "Microsoft.Network/virtualNetworks/subnets1")] + [TestCase(false, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets2")] + [TestCase(false, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets1")] + public void GreaterThanOperator(bool expected, string string1, string string2) + { + ResourceType rt1 = string1; + ResourceType rt2 = string2; + Assert.AreEqual(expected, rt1 > rt2); + } + + [TestCase(true, "Microsoft.Network/virtualNetworks/subnets2", "Microsoft.Network/virtualNetworks/subnets1")] + [TestCase(false, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets2")] + [TestCase(true, "Microsoft.Network/virtualNetworks/subnets1", "Microsoft.Network/virtualNetworks/subnets1")] + public void GreaterThanOrEqualOperator(bool expected, string string1, string string2) + { + ResourceType rt1 = string1; + ResourceType rt2 = string2; + Assert.AreEqual(expected, rt1 >= rt2); + } + + [Test] + public void LessThanNull() + { + ResourceType rt = "Microsoft.Network/virtualNetworks/subnets1"; + Assert.IsTrue(null < rt); + Assert.IsFalse(rt < null); + } + + [Test] + public void LessThanOrEqualNull() + { + ResourceType rt = "Microsoft.Network/virtualNetworks/subnets1"; + Assert.IsTrue(null <= rt); + Assert.IsFalse(rt <= null); + } + + [Test] + public void GreaterThanNull() + { + ResourceType rt = "Microsoft.Network/virtualNetworks/subnets1"; + Assert.IsFalse(null > rt); + Assert.IsTrue(rt > null); + } + + [Test] + public void GreaterThanOrEqualNull() + { + ResourceType rt = "Microsoft.Network/virtualNetworks/subnets1"; + Assert.IsFalse(null >= rt); + Assert.IsTrue(rt >= null); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SkuTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SkuTests.cs index b9a7c5423aee3..c0ec508248f88 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SkuTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SkuTests.cs @@ -118,6 +118,82 @@ public void CompareToMore(int expected, string name1, string name2, string famil Assert.AreEqual(expected, sku1.CompareTo(sku2)); } + [Test] + public void LessThanNull() + { + Sku sku = new Sku("SkuName", null, null, "SkuFamily", null); + Assert.IsTrue(null < sku); + Assert.IsFalse(sku < null); + } + + [Test] + public void LessThanOrEqualNull() + { + Sku sku = new Sku("SkuName", null, null, "SkuFamily", null); + Assert.IsTrue(null <= sku); + Assert.IsFalse(sku <= null); + } + + [Test] + public void GreaterThanNull() + { + Sku sku = new Sku("SkuName", null, null, "SkuFamily", null); + Assert.IsFalse(null > sku); + Assert.IsTrue(sku > null); + } + + [Test] + public void GreaterThanOrEqualNull() + { + Sku sku = new Sku("SkuName", null, null, "SkuFamily", null); + Assert.IsFalse(null >= sku); + Assert.IsTrue(sku >= null); + } + + [TestCase(false, "Nameb", "namea", "familya", "Familyb")] + [TestCase(false, "Nameb", "namea", "familya", "familya")] + [TestCase(false, "namea", "namea", "familya", "familya")] + [TestCase(true, "namea", "Nameb", "Familyb", "familya")] + public void LessThanOperator(bool expected, string name1, string name2, string family1, string family2) + { + Sku sku1 = new Sku(name1, null, null, family1, null); + Sku sku2 = new Sku(name2, null, null, family2, null); + Assert.AreEqual(expected, sku1 < sku2); + } + + [TestCase(false, "Nameb", "namea", "familya", "Familyb")] + [TestCase(false, "Nameb", "namea", "familya", "familya")] + [TestCase(true, "namea", "namea", "familya", "familya")] + [TestCase(true, "namea", "Nameb", "Familyb", "familya")] + public void LessThanOrEqualOperator(bool expected, string name1, string name2, string family1, string family2) + { + Sku sku1 = new Sku(name1, null, null, family1, null); + Sku sku2 = new Sku(name2, null, null, family2, null); + Assert.AreEqual(expected, sku1 <= sku2); + } + + [TestCase(true, "Nameb", "namea", "familya", "Familyb")] + [TestCase(true, "Nameb", "namea", "familya", "familya")] + [TestCase(false, "namea", "namea", "familya", "familya")] + [TestCase(false, "namea", "Nameb", "Familyb", "familya")] + public void GreaterThanOperator(bool expected, string name1, string name2, string family1, string family2) + { + Sku sku1 = new Sku(name1, null, null, family1, null); + Sku sku2 = new Sku(name2, null, null, family2, null); + Assert.AreEqual(expected, sku1 > sku2); + } + + [TestCase(true, "Nameb", "namea", "familya", "Familyb")] + [TestCase(true, "Nameb", "namea", "familya", "familya")] + [TestCase(true, "namea", "namea", "familya", "familya")] + [TestCase(false, "namea", "Nameb", "Familyb", "familya")] + public void GreaterThanOrEqualOperator(bool expected, string name1, string name2, string family1, string family2) + { + Sku sku1 = new Sku(name1, null, null, family1, null); + Sku sku2 = new Sku(name2, null, null, family2, null); + Assert.AreEqual(expected, sku1 >= sku2); + } + [TestCase(true, "name", "name")] [TestCase(true, "Name", "name")] [TestCase(true, null, null)] @@ -129,14 +205,40 @@ public void EqualsToName(bool expected, string name1, string name2) { Sku sku1 = new Sku(name1, null, null, null, null); Sku sku2 = new Sku(name2, null, null, null, null); - if (expected) - { - Assert.IsTrue(sku1.Equals(sku2)); - } - else - { - Assert.IsFalse(sku1.Equals(sku2)); - } + Assert.AreEqual(expected, sku1.Equals(sku2), "Skus did not match expected equals"); + Assert.AreEqual(expected, sku1.GetHashCode() == sku2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({sku1.GetHashCode()}, {sku2.GetHashCode()})"); + } + + [TestCase(true, "name", "name", "family", "family")] + [TestCase(true, "Name", "name", "Family", "family")] + [TestCase(false, "name", "name1", "family", "family")] + [TestCase(false, "Name", "name", "Family", "family1")] + [TestCase(true, null, null, null, null)] + [TestCase(false, "name", null, "family", null)] + [TestCase(false, null, "name", null, "family")] + [TestCase(true, "${?/>._`", "${?/>._`", "${?/>._`", "${?/>._`")] + [TestCase(false, "${?/>._`", "", "${?/>._`", "")] + public void EqualsToOperator(bool expected, string name1, string name2, string family1, string family2) + { + Sku sku1 = new Sku(name1, family1, null, null, null); + Sku sku2 = new Sku(name2, family2, null, null, null); + Assert.AreEqual(expected, sku1 == sku2); + } + + [TestCase(false, "name", "name", "family", "family")] + [TestCase(false, "Name", "name", "Family", "family")] + [TestCase(true, "name", "name1", "family", "family")] + [TestCase(true, "Name", "name", "Family", "family1")] + [TestCase(false, null, null, null, null)] + [TestCase(true, "name", null, "family", null)] + [TestCase(true, null, "name", null, "family")] + [TestCase(false, "${?/>._`", "${?/>._`", "${?/>._`", "${?/>._`")] + [TestCase(true, "${?/>._`", "", "${?/>._`", "")] + public void NotEqualsToOperator(bool expected, string name1, string name2, string family1, string family2) + { + Sku sku1 = new Sku(name1, family1, null, null, null); + Sku sku2 = new Sku(name2, family2, null, null, null); + Assert.AreEqual(expected, sku1 != sku2); } [TestCase(true, "family", "family")] @@ -150,14 +252,8 @@ public void EqualsToFamily(bool expected, string family1, string family2) { Sku sku1 = new Sku(null, null, null, family1, null); Sku sku2 = new Sku(null, null, null, family2, null); - if (expected) - { - Assert.IsTrue(sku1.Equals(sku2)); - } - else - { - Assert.IsFalse(sku1.Equals(sku2)); - } + Assert.AreEqual(expected, sku1.Equals(sku2), "Skus did not match expected equals"); + Assert.AreEqual(expected, sku1.GetHashCode() == sku2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({sku1.GetHashCode()}, {sku2.GetHashCode()})"); } [TestCase(true, "size", "size")] @@ -171,14 +267,8 @@ public void EqualsToSize(bool expected, string size1, string size2) { Sku sku1 = new Sku(null, null, size1, null, null); Sku sku2 = new Sku(null, null, size2, null, null); - if (expected) - { - Assert.IsTrue(sku1.Equals(sku2)); - } - else - { - Assert.IsFalse(sku1.Equals(sku2)); - } + Assert.AreEqual(expected, sku1.Equals(sku2), "Skus did not match expected equals"); + Assert.AreEqual(expected, sku1.GetHashCode() == sku2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({sku1.GetHashCode()}, {sku2.GetHashCode()})"); } [TestCase(true, "tier", "tier")] @@ -192,14 +282,8 @@ public void EqualsToTier(bool expected, string tier1, string tier2) { Sku sku1 = new Sku(null, tier1, null, null, null, null); Sku sku2 = new Sku(null, tier2, null, null, null, null); - if (expected) - { - Assert.IsTrue(sku1.Equals(sku2)); - } - else - { - Assert.IsFalse(sku1.Equals(sku2)); - } + Assert.AreEqual(expected, sku1.Equals(sku2), "Skus did not match expected equals"); + Assert.AreEqual(expected, sku1.GetHashCode() == sku2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({sku1.GetHashCode()}, {sku2.GetHashCode()})"); } [TestCase(true, "model", "model")] @@ -213,14 +297,8 @@ public void EqualsToModel(bool expected, string model1, string model2) { Sku sku1 = new Sku(null, null, null, null, model1, null); Sku sku2 = new Sku(null, null, null, null, model2, null); - if (expected) - { - Assert.IsTrue(sku1.Equals(sku2)); - } - else - { - Assert.IsFalse(sku1.Equals(sku2)); - } + Assert.AreEqual(expected, sku1.Equals(sku2), "Skus did not match expected equals"); + Assert.AreEqual(expected, sku1.GetHashCode() == sku2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({sku1.GetHashCode()}, {sku2.GetHashCode()})"); } [TestCase(true, 1, 1)] @@ -232,14 +310,8 @@ public void EqualsToCapacity(bool expected, long? capacity1, long? capacity2) { Sku sku1 = capacity1 == null ? new Sku(null, null, null, null, null) : new Sku(null, null, null, null, null, capacity1); Sku sku2 = capacity2 == null ? new Sku(null, null, null, null, null) : new Sku(null, null, null, null, null, capacity2); - if (expected) - { - Assert.IsTrue(sku1.Equals(sku2)); - } - else - { - Assert.IsFalse(sku1.Equals(sku2)); - } + Assert.AreEqual(expected, sku1.Equals(sku2), "Skus did not match expected equals"); + Assert.AreEqual(expected, sku1.GetHashCode() == sku2.GetHashCode(), $"Hashcodes comparison was expect {expected} but was {!expected}, ({sku1.GetHashCode()}, {sku2.GetHashCode()})"); } [Test] @@ -254,7 +326,16 @@ public void EqualsToNullSku() public void EqualsToObject() { Sku sku1 = new Sku(null, null, null, null, null); - object sku2 = "random"; + object sku2 = new Sku("SkuName", null, null, null, null); + object stringSku = "random"; + Assert.IsFalse(sku1.Equals(stringSku)); + + object nullSku = null; + Assert.IsFalse(sku1.Equals(nullSku)); + + object sameSku = sku1; + Assert.IsTrue(sku1.Equals(sameSku)); + Assert.IsFalse(sku1.Equals(sku2)); } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs index c82a98544162d..e7a28fa398146 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System.IO; -using System.Text; using System.Text.Json; -using Azure.Core; using Azure.ResourceManager.TestFramework; using NUnit.Framework; @@ -13,62 +10,6 @@ namespace Azure.ResourceManager.Core.Tests [Parallelizable] public class SubResourceTests { - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] - [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - public void CompareToObject(int expected, string id1, string id2) - { - SubResource resource1 = new SubResource(id1); - SubResource resource2 = new SubResource(id2); - Assert.AreEqual(expected, resource1.CompareTo(resource2)); - } - - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] - [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - public void CompareToString(int expected, string id1, string id2) - { - SubResource resource1 = new SubResource(id1); - Assert.AreEqual(expected, resource1.CompareTo(id2)); - } - - [Test] - public void CompareToNull() - { - var resource1 = new SubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); - SubResource resource2 = null; - var resource3 = new SubResource(); - Assert.AreEqual(1, resource1.CompareTo(resource2)); - Assert.AreEqual(1, resource1.CompareTo(resource3)); - Assert.AreEqual(1, resource1.CompareTo((string)null)); - } - - [Test] - public void CompareToSame() - { - var resource1 = new SubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); - var resource2 = resource1; - Assert.AreEqual(0, resource1.CompareTo(resource2)); - } - [Test] public void Deserialization() { @@ -77,7 +18,6 @@ public void Deserialization() var jsonString = JsonHelper.SerializeToString(resource1); var json = JsonDocument.Parse(jsonString).RootElement; var resource2 = SubResource.DeserializeSubResource(json); - Assert.AreEqual(0, resource1.CompareTo(resource2)); Assert.IsTrue(resource1.Equals(resource2)); Assert.IsTrue(resource1.Equals(id)); Assert.IsFalse(resource1.Equals(id + "1")); diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs deleted file mode 100644 index a5141148820fa..0000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using NUnit.Framework; - -namespace Azure.ResourceManager.Core.Tests -{ - [Parallelizable] - public class WritableSubResourceTests - { - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] - [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - public void CompareToObject(int expected, string id1, string id2) - { - WritableSubResource resource1 = new WritableSubResource(id1); - WritableSubResource resource2 = new WritableSubResource(id2); - Assert.AreEqual(expected, resource1.CompareTo(resource2)); - } - - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] - [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] - [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] - public void CompareToString(int expected, string id1, string id2) - { - WritableSubResource resource1 = new WritableSubResource(id1); - Assert.AreEqual(expected, resource1.CompareTo(id2)); - } - - [Test] - public void CompareToNull() - { - var resource1 = new WritableSubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); - WritableSubResource resource2 = null; - Assert.AreEqual(1, resource1.CompareTo(resource2)); - Assert.AreEqual(1, resource1.CompareTo((string)null)); - } - - [Test] - public void CompareToSame() - { - var resource1 = new WritableSubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); - var resource2 = resource1; - Assert.AreEqual(0, resource1.CompareTo(resource2)); - } - } -} From f473271abd25ca6563e0b9ae282d3921a20f5d81 Mon Sep 17 00:00:00 2001 From: m-nash Date: Tue, 29 Jun 2021 19:46:40 -0700 Subject: [PATCH 2/4] remove CA1067 --- .../src/Azure.ResourceManager.Core.csproj | 2 +- .../src/Resources/ResourceIdentity.cs | 17 ++++++++++++- .../src/Resources/ResourceNameFilter.cs | 18 +++++++++++++ .../src/Resources/ResourceTagFilter.cs | 16 ++++++++++++ .../src/Resources/ResourceTypeFilter.cs | 25 +++++++++++++++++-- .../src/Resources/SystemAssignedIdentity.cs | 17 ++++++++++++- .../src/Resources/UserAssignedIdentity.cs | 17 ++++++++++++- .../tests/Unit/SubResourceTests.cs | 6 ++--- 8 files changed, 109 insertions(+), 9 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj index 5f533803aea22..b21e3efaafe82 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj @@ -8,7 +8,7 @@ This is a beta preview vesion. This version uses a next-generation code generator that introduces important breaking changes, but also new features (such as intuitive authentication, custom HTTP pipeline, distributed tracing and much more). azure;management;resource - $(NoWarn);CA2214;CA1067;CA1065;SA1028 + $(NoWarn);CA2214;CA1065;SA1028 true diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentity.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentity.cs index 12599e56aad6a..80e42071c83e8 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentity.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentity.cs @@ -213,7 +213,7 @@ internal static void Serialize(Utf8JsonWriter writer, ResourceIdentity identity) /// True if they are equal, otherwise False. public bool Equals(ResourceIdentity other) { - if (other == null) + if (ReferenceEquals(other, null)) return false; if (UserAssignedIdentities.Count == other.UserAssignedIdentities.Count) @@ -237,5 +237,20 @@ public bool Equals(ResourceIdentity other) return SystemAssignedIdentity.Equals(SystemAssignedIdentity, other.SystemAssignedIdentity); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + return true; + + return Equals(obj as ResourceIdentity); + } + + /// + public override int GetHashCode() + { + return HashCodeBuilder.Combine(SystemAssignedIdentity, UserAssignedIdentities); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceNameFilter.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceNameFilter.cs index 86c77fe7c53e2..a73dad956d0d9 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceNameFilter.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceNameFilter.cs @@ -67,5 +67,23 @@ public override string GetFilterString() return string.Join(" and ", builder); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + return true; + + if (obj is string other) + return Equals(other); + + return Equals(obj as ResourceNameFilter); + } + + /// + public override int GetHashCode() + { + return Name.GetHashCode(); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTagFilter.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTagFilter.cs index 528a374a81761..bb78dab0caafb 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTagFilter.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTagFilter.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using Azure.Core; namespace Azure.ResourceManager.Core { @@ -61,5 +62,20 @@ public override string GetFilterString() { return $"tagName eq '{_tag.Item1}' and tagValue eq '{_tag.Item2}'"; } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + return true; + + return Equals(obj as ResourceTagFilter); + } + + /// + public override int GetHashCode() + { + return HashCodeBuilder.Combine(Key, Value); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTypeFilter.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTypeFilter.cs index a6406b32cf35c..49383d5419a24 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTypeFilter.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTypeFilter.cs @@ -31,13 +31,13 @@ public ResourceTypeFilter(ResourceType resourceType) /// public bool Equals(string other) { - throw new NotImplementedException(); + return ResourceType.Equals(other); } /// public bool Equals(ResourceTypeFilter other) { - throw new NotImplementedException(); + return ResourceType.Equals(other); } /// @@ -45,5 +45,26 @@ public override string GetFilterString() { return $"resourceType EQ '{ResourceType}'"; } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + return true; + + if (ReferenceEquals(null, obj)) + return false; + + if (obj is string other) + return Equals(other); + + return Equals(obj as ResourceTypeFilter); + } + + /// + public override int GetHashCode() + { + return ResourceType.GetHashCode(); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SystemAssignedIdentity.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SystemAssignedIdentity.cs index e2f7dcbc73219..3225c30347592 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SystemAssignedIdentity.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SystemAssignedIdentity.cs @@ -10,7 +10,7 @@ namespace Azure.ResourceManager.Core /// /// A class representing an Identity assigned by the system. /// - public sealed class SystemAssignedIdentity + public sealed class SystemAssignedIdentity : IEquatable { /// /// Initializes a new instance of the class with Null properties. @@ -158,5 +158,20 @@ public bool Equals(SystemAssignedIdentity other) return TenantId.Equals(other.TenantId) && PrincipalId.Equals(other.PrincipalId); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + return true; + + return Equals(obj as SystemAssignedIdentity); + } + + /// + public override int GetHashCode() + { + return HashCodeBuilder.Combine(TenantId, PrincipalId); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/UserAssignedIdentity.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/UserAssignedIdentity.cs index 88ed8932bddff..dffee4dae14ec 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/UserAssignedIdentity.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/UserAssignedIdentity.cs @@ -10,7 +10,7 @@ namespace Azure.ResourceManager.Core /// /// A class representing an Identity assigned by the user. /// - public sealed class UserAssignedIdentity + public sealed class UserAssignedIdentity : IEquatable { /// /// Initializes a new instance of the class. @@ -142,5 +142,20 @@ public bool Equals(UserAssignedIdentity other) return ClientId.Equals(other.ClientId) && PrincipalId.Equals(other.PrincipalId); } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) + return true; + + return Equals(obj as UserAssignedIdentity); + } + + /// + public override int GetHashCode() + { + return HashCodeBuilder.Combine(ClientId, PrincipalId); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs index e7a28fa398146..f250a5e2c4404 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs @@ -14,13 +14,13 @@ public class SubResourceTests public void Deserialization() { var id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"; + var expected = "{\"id\":\"" + id + "\"}"; var resource1 = new SubResource(id); var jsonString = JsonHelper.SerializeToString(resource1); var json = JsonDocument.Parse(jsonString).RootElement; var resource2 = SubResource.DeserializeSubResource(json); - Assert.IsTrue(resource1.Equals(resource2)); - Assert.IsTrue(resource1.Equals(id)); - Assert.IsFalse(resource1.Equals(id + "1")); + Assert.AreEqual(expected, jsonString); + Assert.AreEqual(jsonString, JsonHelper.SerializeToString(resource2)); } } } From b5735941ac17e5767190e66558c56609ca6658a2 Mon Sep 17 00:00:00 2001 From: m-nash Date: Tue, 29 Jun 2021 19:51:47 -0700 Subject: [PATCH 3/4] remove CA1065 --- .../src/Azure.ResourceManager.Core.csproj | 2 +- .../src/Resources/LocationResourceIdentifier.cs | 6 ++---- .../src/Resources/ResourceGroupResourceIdentifier.cs | 6 ++---- .../src/Resources/SubscriptionProviderIdentifier.cs | 6 ++---- .../src/Resources/SubscriptionResourceIdentifier.cs | 6 ++---- .../src/Resources/TenantProviderIdentifier.cs | 6 ++---- .../src/Resources/TenantResourceIdentifier.cs | 6 ++---- 7 files changed, 13 insertions(+), 25 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj index b21e3efaafe82..bc28ff148fcc4 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj @@ -8,7 +8,7 @@ This is a beta preview vesion. This version uses a next-generation code generator that introduces important breaking changes, but also new features (such as intuitive authentication, custom HTTP pipeline, distributed tracing and much more). azure;management;resource - $(NoWarn);CA2214;CA1065;SA1028 + $(NoWarn);CA2214;SA1028 true diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs index 900b34fe01639..b9c59ed4629ec 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs @@ -92,10 +92,8 @@ public static implicit operator LocationResourceIdentifier(string other) { if (other is null) return null; - LocationResourceIdentifier id = ResourceIdentifier.Create(other) as LocationResourceIdentifier; - if (id is null) - throw new ArgumentException("Not a valid location level resource", nameof(other)); - return id; + + return ResourceIdentifier.Create(other) as LocationResourceIdentifier; } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs index 88a1cae7b4953..2c6e5c1ef2115 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs @@ -88,10 +88,8 @@ public static implicit operator ResourceGroupResourceIdentifier(string other) { if (other is null) return null; - ResourceGroupResourceIdentifier id = ResourceIdentifier.Create(other) as ResourceGroupResourceIdentifier; - if (id is null) - throw new ArgumentException("Not a valid resource group level resource", nameof(other)); - return id; + + return ResourceIdentifier.Create(other) as ResourceGroupResourceIdentifier; } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs index 573b82080402c..c01c46f28a273 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs @@ -58,10 +58,8 @@ public static implicit operator SubscriptionProviderIdentifier(string other) { if (other is null) return null; - SubscriptionProviderIdentifier id = ResourceIdentifier.Create(other) as SubscriptionProviderIdentifier; - if (other is null) - throw new ArgumentException("Not a valid tenant provider resource", nameof(other)); - return id; + + return ResourceIdentifier.Create(other) as SubscriptionProviderIdentifier; } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs index 1603bd8bfec24..70d277608cd1d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs @@ -123,10 +123,8 @@ public static implicit operator SubscriptionResourceIdentifier(string other) { if (other is null) return null; - SubscriptionResourceIdentifier id = ResourceIdentifier.Create(other) as SubscriptionResourceIdentifier; - if (id is null) - throw new ArgumentException("Not a valid subscription level resource", nameof(other)); - return id; + + return ResourceIdentifier.Create(other) as SubscriptionResourceIdentifier; } internal override string ToResourceString() diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs index e1169ec1b2f04..f3906cb7e975e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs @@ -55,10 +55,8 @@ public static implicit operator TenantProviderIdentifier(string other) { if (other is null) return null; - TenantProviderIdentifier id = ResourceIdentifier.Create(other) as TenantProviderIdentifier; - if (other is null) - throw new ArgumentException("Not a valid tenant provider resource", nameof(other)); - return id; + + return ResourceIdentifier.Create(other) as TenantProviderIdentifier; } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs index 7c94ee87752ed..9450336f04450 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs @@ -90,10 +90,8 @@ public static implicit operator TenantResourceIdentifier(string other) { if (other is null) return null; - TenantResourceIdentifier id = ResourceIdentifier.Create(other) as TenantResourceIdentifier; - if (id is null) - throw new ArgumentException("Not a valid tenant level resource", nameof(other)); - return id; + + return ResourceIdentifier.Create(other) as TenantResourceIdentifier; } /// From ae2d644d8a0ae8740ccab3e68776b93c2d6a15ae Mon Sep 17 00:00:00 2001 From: m-nash Date: Tue, 29 Jun 2021 20:12:34 -0700 Subject: [PATCH 4/4] remove SA1028 --- .../src/ApiVersionsBase.cs | 32 +++++------ .../src/ArmClient.cs | 2 +- .../src/Azure.ResourceManager.Core.csproj | 2 +- .../src/Generated/Models/Plan.cs | 50 ++++++++--------- .../src/Generated/Models/Sku.cs | 4 +- .../src/Generated/Models/SubscriptionData.cs | 4 +- .../src/Generated/Models/SubscriptionState.cs | 4 +- .../src/Resources/LocationData.cs | 48 ++++++++--------- .../Resources/LocationResourceIdentifier.cs | 4 +- .../ResourceGroupResourceIdentifier.cs | 6 +-- .../src/Resources/ResourceIdentifier.cs | 54 +++++++++---------- .../Resources/ResourceIdentifierExtensions.cs | 16 +++--- .../src/Resources/ResourceType.cs | 32 +++++------ .../src/Resources/SubResource.cs | 6 +-- .../SubscriptionProviderIdentifier.cs | 2 +- .../SubscriptionResourceIdentifier.cs | 8 +-- .../src/Resources/TenantProviderIdentifier.cs | 2 +- .../src/Resources/TenantResourceIdentifier.cs | 14 ++--- .../src/Resources/WritableSubResource.cs | 6 +-- .../tests/Unit/ResourceIdentifierTests.cs | 12 ++--- 20 files changed, 154 insertions(+), 154 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs index fa1eae6820712..3a62493bbe794 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs @@ -23,22 +23,22 @@ protected ApiVersionsBase(string value) } /// - /// + /// 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 <(ApiVersionsBase left, ApiVersionsBase 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 greater than the right. public static bool operator >(ApiVersionsBase left, ApiVersionsBase right) { return !ReferenceEquals(left, null) && left.CompareTo(right) > 0; @@ -191,22 +191,22 @@ public override int GetHashCode() } /// - /// + /// 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 <=(ApiVersionsBase left, ApiVersionsBase 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 >=(ApiVersionsBase left, ApiVersionsBase right) { return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index 40cc0ac394d75..6320090bd4fc7 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -51,7 +51,7 @@ public ArmClient(TokenCredential credential, ArmClientOptions options = default) /// The id of the default Azure subscription. /// A credential used to authenticate to an Azure Service. /// The client parameters to use in these operations. - /// If is null. + /// If is null. public ArmClient( string defaultSubscriptionId, TokenCredential credential, diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj index bc28ff148fcc4..2741c4b9be3ed 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj @@ -8,7 +8,7 @@ This is a beta preview vesion. This version uses a next-generation code generator that introduces important breaking changes, but also new features (such as intuitive authentication, custom HTTP pipeline, distributed tracing and much more). azure;management;resource - $(NoWarn);CA2214;SA1028 + $(NoWarn);CA2214 true diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs index 284086ffac619..6fac41b894908 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Plan.cs @@ -16,7 +16,7 @@ public sealed partial class Plan : IEquatable, IComparable public Plan() { } - + /// /// Initializes a new instance of the class. /// @@ -136,11 +136,11 @@ public override int GetHashCode() } /// - /// + /// Compares this instance with another object and determines if they are equals. /// - /// - /// - /// + /// The object on the left side of the operator. + /// The object on the right side of the operator. + /// True if they are equal, otherwise false. public static bool operator ==(Plan left, Plan right) { if (ReferenceEquals(left, null)) @@ -152,55 +152,55 @@ public override int GetHashCode() } /// - /// + /// Compares this instance with another object and determines if they are equals. /// - /// - /// - /// + /// The object on the left side of the operator. + /// The object on the right side of the operator. + /// True if they are not equal, otherwise false. public static bool operator !=(Plan left, Plan 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 <(Plan left, Plan 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 <=(Plan left, Plan 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 >(Plan left, Plan 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 >=(Plan left, Plan right) { return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs index dee4274b0475a..d906fb0492868 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/Sku.cs @@ -151,7 +151,7 @@ public override int GetHashCode() /// /// The sku on the left side of the operator. /// The sku on the right side of the operator. - /// True if they are equals, otherwise false. + /// True if they are equal, otherwise false. public static bool operator ==(Sku left, Sku right) { if (ReferenceEquals(left, null)) @@ -167,7 +167,7 @@ public override int GetHashCode() /// /// The sku on the left side of the operator. /// The sku on the right side of the operator. - /// True if they are not equals, otherwise false. + /// True if they are not equal, otherwise false. public static bool operator !=(Sku left, Sku right) { return !(left == right); diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionData.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionData.cs index 450d62da4f27a..3198a2f4fcdc9 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionData.cs @@ -74,8 +74,8 @@ internal SubscriptionData(string id, /// public string DisplayName { get; } - /// - /// The subscription tenant ID. + /// + /// The subscription tenant ID. /// public string TenantId { get; } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionState.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionState.cs index 2590f4eac1742..b63a1596bbb8f 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionState.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionState.cs @@ -3,8 +3,8 @@ namespace Azure.ResourceManager.Core { - /// - /// The subscription state. Possible values are Enabled, Warned, PastDue, Disabled, and Deleted. + /// + /// The subscription state. Possible values are Enabled, Warned, PastDue, Disabled, and Deleted. /// public enum SubscriptionState { diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs index 4e68a7b5ab260..24f4702b152d0 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationData.cs @@ -486,11 +486,11 @@ public override int GetHashCode() } /// - /// + /// Compares this instance with another object and determines if they are equals. /// - /// - /// - /// + /// The object on the left side of the operator. + /// The object on the right side of the operator. + /// True if they are equal, otherwise false. public static bool operator ==(LocationData left, LocationData right) { if (ReferenceEquals(left, null)) @@ -502,55 +502,55 @@ public override int GetHashCode() } /// - /// + /// Compares this instance with another object and determines if they are equals. /// - /// - /// - /// + /// The object on the left side of the operator. + /// The object on the right side of the operator. + /// True if they are not equal, otherwise false. public static bool operator !=(LocationData left, LocationData 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 <(LocationData left, LocationData 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 <=(LocationData left, LocationData 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 >(LocationData left, LocationData 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 >=(LocationData left, LocationData right) { return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs index b9c59ed4629ec..6e81fb07ecf00 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationResourceIdentifier.cs @@ -6,7 +6,7 @@ namespace Azure.ResourceManager.Core { /// - /// The identifier for a resource that is contained in a location. + /// The identifier for a resource that is contained in a location. /// public sealed class LocationResourceIdentifier : SubscriptionResourceIdentifier { @@ -39,7 +39,7 @@ public LocationResourceIdentifier(string resourceId) } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// Used to initialize resources in the same namespace as the parent resource. /// /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs index 2c6e5c1ef2115..ae993e62270d0 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs @@ -25,7 +25,7 @@ internal ResourceGroupResourceIdentifier(SubscriptionResourceIdentifier parent, } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for a resource in a different namespace than its parent. /// /// he of the target of this extension resource. @@ -39,7 +39,7 @@ internal ResourceGroupResourceIdentifier(ResourceGroupResourceIdentifier target, } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for a resource in the same namespace as its parent. /// /// he of the target of this extension resource. @@ -52,7 +52,7 @@ internal ResourceGroupResourceIdentifier(ResourceGroupResourceIdentifier target, } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// /// The string representation of a resource id. public ResourceGroupResourceIdentifier(string resourceId) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs index 478a095b1be70..de4dc54a4d0ea 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs @@ -16,7 +16,7 @@ public abstract class ResourceIdentifier : IEquatable, IComp internal const string ProvidersKey = "providers", SubscriptionsKey = "subscriptions", ResourceGroupsKey = "resourceGroups", LocationsKey = "locations"; - internal const string ResourceGroupsLowerKey = "resourcegroups"; + internal const string ResourceGroupsLowerKey = "resourcegroups"; internal const string BuiltInResourceNamespace = "Microsoft.Resources"; @@ -98,7 +98,7 @@ public static ResourceIdentifier Create(string resourceId) } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are contained in a subscription. /// /// The GUID string representing the resource. @@ -161,7 +161,7 @@ internal static ResourceIdentifier CreateBaseSubscriptionIdentifier(string subsc } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are contained in a location. /// /// The resource id of the subscription for this resource. @@ -189,7 +189,7 @@ internal static ResourceIdentifier CreateBaseLocationIdentifier(SubscriptionReso } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are contained in a resource group. /// /// The resource id of the subscription for this resource. @@ -217,7 +217,7 @@ internal static ResourceIdentifier CreateBaseResourceGroupIdentifier(Subscriptio } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are based in the tenant. /// /// The resource id of the parent resource. @@ -237,7 +237,7 @@ internal static ResourceIdentifier CreateTenantIdentifier(TenantResourceIdentifi } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are based in a subscription. /// /// The resource id of the parent resource. @@ -257,7 +257,7 @@ internal static ResourceIdentifier CreateSubscriptionIdentifier(SubscriptionReso } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are contained in a location. /// /// The resource id of the parent resource. @@ -277,7 +277,7 @@ internal static ResourceIdentifier CreateLocationIdentifier(LocationResourceIden } /// - /// Create a new instance of the class for resource identifiers + /// Create a new instance of the class for resource identifiers /// that are contained in a resource group. /// /// The resource id of the parent resource. @@ -465,8 +465,8 @@ public bool Equals(ResourceIdentifier other) /// Compre this resource identifier to the given resource identifier. /// /// The resource identifier to compare to. - /// 0 if the resource identifiers are equivalent, -1 if this resource identifier - /// should be ordered before the given resource identifier, 1 if this resource identifier + /// 0 if the resource identifiers are equivalent, -1 if this resource identifier + /// should be ordered before the given resource identifier, 1 if this resource identifier /// should be ordered after the given resource identifier. public int CompareTo(ResourceIdentifier other) { @@ -500,7 +500,7 @@ public override int GetHashCode() 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(); @@ -528,44 +528,44 @@ public override int GetHashCode() } /// - /// + /// 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 <(ResourceIdentifier left, ResourceIdentifier 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 <=(ResourceIdentifier left, ResourceIdentifier 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 >(ResourceIdentifier left, ResourceIdentifier 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 >=(ResourceIdentifier left, ResourceIdentifier right) { return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifierExtensions.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifierExtensions.cs index ef5af2d1a6a7f..8e1b5e9927f5a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifierExtensions.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifierExtensions.cs @@ -17,7 +17,7 @@ public static class ResourceIdentifierExtensions /// /// The id to append to. /// The provider namespace of the added resource. - /// The simple type of the added resource, without slashes (/), + /// The simple type of the added resource, without slashes (/), /// for example, 'virtualMachines'. /// The name of the resource. /// The combined resource id. @@ -33,7 +33,7 @@ public static TenantResourceIdentifier AppendProviderResource(this TenantResourc /// /// The id to append to. /// The provider namespace of the added resource. - /// The simple type of the added resource, without slashes (/), + /// The simple type of the added resource, without slashes (/), /// for example, 'virtualMachines'. /// The name of the resource. /// The combined resource id. @@ -49,7 +49,7 @@ public static SubscriptionResourceIdentifier AppendProviderResource(this Subscri /// /// The id to append to. /// The provider namespace of the added resource. - /// The simple type of the added resource, without slashes (/), + /// The simple type of the added resource, without slashes (/), /// for example, 'virtualMachines'. /// The name of the resource. /// The combined resource id. @@ -65,7 +65,7 @@ public static ResourceGroupResourceIdentifier AppendProviderResource(this Resour /// /// The id to append to. /// The provider namespace of the added resource. - /// The simple type of the added resource, without slashes (/), + /// The simple type of the added resource, without slashes (/), /// for example, 'virtualMachines'. /// The name of the resource. /// The combined resource id. @@ -80,7 +80,7 @@ public static LocationResourceIdentifier AppendProviderResource(this LocationRes /// Add a provider resource to an existing resource id. /// /// The id to append to. - /// The simple type of the child resource, without slashes (/), + /// The simple type of the child resource, without slashes (/), /// for example, 'subnets'. /// The name of the resource. /// The combined resource id. @@ -95,7 +95,7 @@ public static TenantResourceIdentifier AppendChildResource(this TenantResourceId /// Add a provider resource to an existing resource id. /// /// The id to append to. - /// The simple type of the child resource, without slashes (/), + /// The simple type of the child resource, without slashes (/), /// for example, 'subnets'. /// The name of the resource. /// The combined resource id. @@ -110,7 +110,7 @@ public static SubscriptionResourceIdentifier AppendChildResource(this Subscripti /// Add a provider resource to an existing resource id. /// /// The id to append to. - /// The simple type of the child resource, without slashes (/), + /// The simple type of the child resource, without slashes (/), /// for example, 'subnets'. /// The name of the resource. /// The combined resource id. @@ -125,7 +125,7 @@ public static ResourceGroupResourceIdentifier AppendChildResource(this ResourceG /// Add a provider resource to an existing resource id. /// /// The id to append to. - /// The simple type of the child resource, without slashes (/), + /// The simple type of the child resource, without slashes (/), /// for example, 'subnets'. /// The name of the resource. /// The combined resource id. diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs index 75000f75c5316..660389434aa4c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs @@ -246,44 +246,44 @@ private void Parse(string resourceIdOrType) } /// - /// + /// 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 <(ResourceType left, ResourceType 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 <=(ResourceType left, ResourceType 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 >(ResourceType left, ResourceType 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 >=(ResourceType left, ResourceType right) { return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs index f876b63ab7844..71a0b7feda866 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -15,7 +15,7 @@ public class SubResource : SubResource /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - public SubResource() + public SubResource() { } @@ -37,7 +37,7 @@ public partial class SubResource /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - public SubResource() + public SubResource() { } @@ -46,7 +46,7 @@ public SubResource() [SerializationConstructor] protected internal SubResource(string id) { - Id = (TIdentifier)id; + Id = (TIdentifier)id; } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs index c01c46f28a273..e6480212b2bf9 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs @@ -29,7 +29,7 @@ internal SubscriptionProviderIdentifier(SubscriptionProviderIdentifier parent, s } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in the sanem namespace as their parent resource. /// /// The resource id of the parent resource. diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs index 70d277608cd1d..c2ff342891724 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionResourceIdentifier.cs @@ -31,7 +31,7 @@ internal SubscriptionResourceIdentifier(Guid id) } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in the sanem namespace as their parent resource. /// /// The resource id of the parent resource. @@ -45,7 +45,7 @@ internal SubscriptionResourceIdentifier(SubscriptionResourceIdentifier parent, R } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in the sanem namespace as their parent resource. /// /// The resource id of the parent resource. @@ -59,7 +59,7 @@ internal SubscriptionResourceIdentifier(SubscriptionResourceIdentifier parent, s } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in a different namespace than their parent resource. /// /// The resource id of the parent resource. @@ -76,7 +76,7 @@ internal SubscriptionResourceIdentifier(SubscriptionResourceIdentifier parent, s /// /// Initializes a new instance of the class. /// - /// The string representation of the subscription id. This can be in the form of a GUID, + /// The string representation of the subscription id. This can be in the form of a GUID, /// or a full resource id like '/subscriptions/xxxxx-yyyy-zzzz-wwwwww'. public SubscriptionResourceIdentifier(string resourceIdOrSubscriptionId) { diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs index f3906cb7e975e..9a4b446144be1 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs @@ -27,7 +27,7 @@ internal TenantProviderIdentifier(TenantProviderIdentifier parent, string provid } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in the sanem namespace as their parent resource. /// /// The resource id of the parent resource. diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs index 9450336f04450..3cd8ff3766c9c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantResourceIdentifier.cs @@ -16,7 +16,7 @@ internal TenantResourceIdentifier() } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// /// The resource type (including namespace and type). /// The name of the resource. @@ -26,7 +26,7 @@ internal TenantResourceIdentifier(ResourceType resourceType, string name) : base } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in the same namespace as their parent. /// /// The parent resource id. @@ -39,7 +39,7 @@ internal TenantResourceIdentifier(TenantResourceIdentifier parent, ResourceType } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in the same namespace as their parent. /// /// The parent resource id. @@ -53,7 +53,7 @@ internal TenantResourceIdentifier(TenantResourceIdentifier parent, string typeNa } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// for resources in a different namespace than their parent. /// /// The parent resource id. @@ -95,10 +95,10 @@ public static implicit operator TenantResourceIdentifier(string other) } /// - /// + /// Tries to get the provider from the resource Id. /// - /// - /// + /// The id to parse for a provider. + /// True if a provider exists. public virtual bool TryGetProvider(out string providerId) { providerId = default(string); diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs index 6c5506660b7bf..a9cadddf216ba 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs @@ -16,7 +16,7 @@ public class WritableSubResource : WritableSubResource /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - public WritableSubResource() + public WritableSubResource() { } @@ -38,8 +38,8 @@ public partial class WritableSubResource /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - public WritableSubResource() - { + public WritableSubResource() + { } /// Initializes a new instance of . diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs index d692e1d6d7cd8..feaf6948a8008 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceIdentifierTests.cs @@ -433,16 +433,16 @@ public void ThrowOnMistypedResource() 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"); - SubscriptionResourceIdentifier subscription; - Assert.Throws(() => subscription = "/providers/Contoso.Widgets/widgets/myWidget"); + SubscriptionResourceIdentifier subscription = "/providers/Contoso.Widgets/widgets/myWidget"; + Assert.IsNull(subscription); Assert.Throws(() => subscription = new SubscriptionResourceIdentifier("/subscriptions/6b085460-5f21-477e-ba44-1035046e9101/locations/westus2")); Assert.Throws(() => subscription = new SubscriptionResourceIdentifier("/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"); - ResourceGroupResourceIdentifier group; - Assert.Throws(() => group = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"); - LocationResourceIdentifier location; - Assert.Throws(() => location = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"); + ResourceGroupResourceIdentifier group = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"; + Assert.IsNull(group); + LocationResourceIdentifier location = "/subscriptions/6b085460-5f21-477e-ba44-1035046e9101"; + Assert.IsNull(location); } [TestCase(TrackedResourceId, TrackedResourceId, 0)]