diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs
index f66ed787f113..3a62493bbe79 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs
@@ -23,31 +23,25 @@ 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)
{
- if (ReferenceEquals(null, left))
- return !ReferenceEquals(null, right);
-
- return left.CompareTo(right) == -1;
+ 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)
{
- 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();
}
+
+ ///
+ /// 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 40cc0ac394d7..6320090bd4fc 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 152ad5c686c1..2741c4b9be3e 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
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 00eac4c30ac1..6fac41b89490 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
{
@@ -14,7 +16,7 @@ public sealed partial class Plan : IEquatable, IComparable
public Plan()
{
}
-
+
///
/// Initializes a new instance of the class.
///
@@ -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));
+ }
+
+ ///
+ /// 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))
+ {
+ return ReferenceEquals(right, null);
+ }
+
+ return left.Equals(right);
+ }
+
+ ///
+ /// 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 dd62f6ccac73..d906fb049286 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 equal, 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 equal, 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/Generated/Models/SubscriptionData.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/Models/SubscriptionData.cs
index 450d62da4f27..3198a2f4fcdc 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 2590f4eac174..b63a1596bbb8 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 a9770d8b24bd..24f4702b152d 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();
+ }
+
+ ///
+ /// 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))
+ {
+ return ReferenceEquals(right, null);
+ }
+
+ return left.Equals(right);
+ }
+
+ ///
+ /// 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 900b34fe0163..6e81fb07ecf0 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.
///
///
@@ -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/Resource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs
index befebf7f9a56..8c6085ce34c5 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/ResourceGroupResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceGroupResourceIdentifier.cs
index 88a1cae7b495..ae993e62270d 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)
@@ -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/ResourceIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentifier.cs
index 7961bfa2bf1a..de4dc54a4d0e 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();
@@ -526,5 +526,49 @@ public override int GetHashCode()
{
return !ResourceIdentifier.Equals(id1,id2);
}
+
+ ///
+ /// 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 ef5af2d1a6a7..8e1b5e9927f5 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/ResourceIdentity.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceIdentity.cs
index 12599e56aad6..80e42071c83e 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 86c77fe7c53e..a73dad956d0d 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 528a374a8176..bb78dab0caaf 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/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs
index 41b837798b81..660389434aa4 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;
}
}
+
+ ///
+ /// 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/ResourceTypeFilter.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceTypeFilter.cs
index a6406b32cf35..49383d5419a2 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/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs
index ca0e7e62b93c..71a0b7feda86 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()
{
}
@@ -30,15 +30,14 @@ 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
{
///
/// Initializes an empty instance of for mocking.
///
[InitializationConstructor]
- public SubResource()
+ public SubResource()
{
}
@@ -47,7 +46,7 @@ public SubResource()
[SerializationConstructor]
protected internal SubResource(string id)
{
- Id = (TIdentifier)id;
+ Id = (TIdentifier)id;
}
///
@@ -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/SubscriptionProviderIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubscriptionProviderIdentifier.cs
index 573b82080402..e6480212b2bf 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.
@@ -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 1603bd8bfec2..c2ff34289172 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)
{
@@ -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/SystemAssignedIdentity.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SystemAssignedIdentity.cs
index e2f7dcbc7321..3225c3034759 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/TenantProviderIdentifier.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TenantProviderIdentifier.cs
index e1169ec1b2f0..9a4b446144be 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.
@@ -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 7c94ee87752e..3cd8ff3766c9 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.
@@ -90,17 +90,15 @@ 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;
}
///
- ///
+ /// 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/UserAssignedIdentity.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/UserAssignedIdentity.cs
index 88ed8932bddf..dffee4dae14e 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/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs
index 6427d5473905..a9cadddf216b 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
{
@@ -15,7 +16,7 @@ public class WritableSubResource : WritableSubResource
/// Initializes an empty instance of for mocking.
///
[InitializationConstructor]
- public WritableSubResource()
+ public WritableSubResource()
{
}
@@ -30,16 +31,15 @@ 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
{
///
/// Initializes an empty instance of for mocking.
///
[InitializationConstructor]
- public WritableSubResource()
- {
+ public WritableSubResource()
+ {
}
/// Initializes a new instance of .
@@ -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 5c8e8b8f6ac5..f5ed047125f4 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 db1d3d214c68..584a90de1c7c 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 d8fd8e2273ba..1403ed348173 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 605a8cabb0fb..feaf6948a800 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)]
@@ -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 4bb596b7c7ed..000000000000
--- 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 b0b3bfe76608..1507a2750e54 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 b9a7c5423aee..c0ec508248f8 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 c82a98544162..f250a5e2c440 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,74 +10,17 @@ 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()
{
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.AreEqual(0, resource1.CompareTo(resource2));
- 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));
}
}
}
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 a5141148820f..000000000000
--- 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));
- }
- }
-}