From e64d14e261104152933e8838091a334e4fcc9707 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Mon, 1 Jun 2026 21:56:54 -0700 Subject: [PATCH 1/4] Code changes to remove unnecessary APIs from pub contract. --- .../src/Diagnostics/RequestedRegion.cs | 36 ------------------- .../Diagnostics/RequestedRegionTests.cs | 24 ------------- 2 files changed, 60 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs index 90b4a175d6..dc510b353c 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs @@ -54,26 +54,6 @@ public bool Equals(RequestedRegion other) && this.Reason == other.Reason; } - /// - public override bool Equals(object obj) - { - return obj is RequestedRegion other && this.Equals(other); - } - - /// - public override int GetHashCode() - { - int regionHash = this.RegionName == null - ? 0 - : StringComparer.OrdinalIgnoreCase.GetHashCode(this.RegionName); - // Combine without depending on System.HashCode (net6+) to keep this constant - // across TFMs. - unchecked - { - return (regionHash * 397) ^ (byte)this.Reason; - } - } - /// /// Returns a human-readable representation of this in the /// form "{regionName}:{reason}". @@ -83,21 +63,5 @@ public override string ToString() { return $"{this.RegionName}:{this.Reason}"; } - - /// - /// Equality operator. - /// - /// The left operand. - /// The right operand. - /// true if the two values are equal; otherwise false. - public static bool operator ==(RequestedRegion left, RequestedRegion right) => left.Equals(right); - - /// - /// Inequality operator. - /// - /// The left operand. - /// The right operand. - /// true if the two values are not equal; otherwise false. - public static bool operator !=(RequestedRegion left, RequestedRegion right) => !left.Equals(right); } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs index 7ae9b7274b..da0c30477b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs @@ -25,30 +25,6 @@ public void Constructor_NullRegionName_Throws() () => new RequestedRegion(null, RequestedRegionReason.Initial)); } - [TestMethod] - public void Equality_RegionNameIsCaseInsensitive() - { - RequestedRegion a = new RequestedRegion("East US", RequestedRegionReason.Initial); - RequestedRegion b = new RequestedRegion("east us", RequestedRegionReason.Initial); - - Assert.IsTrue(a.Equals(b)); - Assert.IsTrue(a == b); - Assert.IsFalse(a != b); - Assert.IsTrue(a.Equals((object)b)); - Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); - } - - [TestMethod] - public void Equality_DifferentReason_NotEqual() - { - RequestedRegion a = new RequestedRegion("East US", RequestedRegionReason.Initial); - RequestedRegion b = new RequestedRegion("East US", RequestedRegionReason.Hedging); - - Assert.IsFalse(a.Equals(b)); - Assert.IsTrue(a != b); - Assert.IsFalse(a == b); - } - [TestMethod] public void Equals_NonRequestedRegionObject_ReturnsFalse() { From 3530460af4f97a91411a0125165e5ed87e50ff8c Mon Sep 17 00:00:00 2001 From: Meghana-Palaparthi Date: Tue, 2 Jun 2026 11:46:21 -0500 Subject: [PATCH 2/4] Update DotNetSDKAPI.net6.json --- .../Contracts/DotNetSDKAPI.net6.json | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json index fddac1ce7a..263c744047 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json @@ -8753,16 +8753,6 @@ "Attributes": [], "MethodInfo": "Boolean Equals(Microsoft.Azure.Cosmos.RequestedRegion);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:True;" }, - "Boolean Equals(System.Object)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Boolean Equals(System.Object);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "Int32 GetHashCode()": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "Int32 GetHashCode();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "Microsoft.Azure.Cosmos.RequestedRegionReason get_Reason()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -8775,16 +8765,6 @@ "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.RequestedRegionReason Reason;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.RequestedRegionReason get_Reason();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "System.Boolean Microsoft.Azure.Cosmos.RequestedRegion.op_Equality(Microsoft.Azure.Cosmos.RequestedRegion, Microsoft.Azure.Cosmos.RequestedRegion)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.Boolean Microsoft.Azure.Cosmos.RequestedRegion.op_Equality(Microsoft.Azure.Cosmos.RequestedRegion, Microsoft.Azure.Cosmos.RequestedRegion);IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, - "System.Boolean Microsoft.Azure.Cosmos.RequestedRegion.op_Inequality(Microsoft.Azure.Cosmos.RequestedRegion, Microsoft.Azure.Cosmos.RequestedRegion)": { - "Type": "Method", - "Attributes": [], - "MethodInfo": "System.Boolean Microsoft.Azure.Cosmos.RequestedRegion.op_Inequality(Microsoft.Azure.Cosmos.RequestedRegion, Microsoft.Azure.Cosmos.RequestedRegion);IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" - }, "System.String get_RegionName()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ From 32e562c2b085d693fbd15a112fb3792b2267f24b Mon Sep 17 00:00:00 2001 From: Meghana-Palaparthi Date: Tue, 2 Jun 2026 12:26:01 -0500 Subject: [PATCH 3/4] Add HashCode and Equals implementation back and update contracts --- .../src/Diagnostics/RequestedRegion.cs | 20 +++++++++++++++++++ .../Contracts/DotNetSDKAPI.net6.json | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs b/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs index dc510b353c..4050e6fee4 100644 --- a/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs +++ b/Microsoft.Azure.Cosmos/src/Diagnostics/RequestedRegion.cs @@ -54,6 +54,26 @@ public bool Equals(RequestedRegion other) && this.Reason == other.Reason; } + /// + public override bool Equals(object obj) + { + return obj is RequestedRegion other && this.Equals(other); + } + + /// + public override int GetHashCode() + { + int regionHash = this.RegionName == null + ? 0 + : StringComparer.OrdinalIgnoreCase.GetHashCode(this.RegionName); + // Combine without depending on System.HashCode (net6+) to keep this constant + // across TFMs. + unchecked + { + return (regionHash * 397) ^ (byte)this.Reason; + } + } + /// /// Returns a human-readable representation of this in the /// form "{regionName}:{reason}". diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json index 263c744047..d0623b657d 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetSDKAPI.net6.json @@ -8753,6 +8753,16 @@ "Attributes": [], "MethodInfo": "Boolean Equals(Microsoft.Azure.Cosmos.RequestedRegion);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:True;" }, + "Boolean Equals(System.Object)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Boolean Equals(System.Object);IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Int32 GetHashCode()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Int32 GetHashCode();IsAbstract:False;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, "Microsoft.Azure.Cosmos.RequestedRegionReason get_Reason()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ From 831499bd516044760e88c535d34a04bcb657d226 Mon Sep 17 00:00:00 2001 From: Meghana-Palaparthi Date: Tue, 2 Jun 2026 12:34:40 -0500 Subject: [PATCH 4/4] Update RequestedRegionTests.cs --- .../Diagnostics/RequestedRegionTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs index da0c30477b..4bf33f0240 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Diagnostics/RequestedRegionTests.cs @@ -25,6 +25,26 @@ public void Constructor_NullRegionName_Throws() () => new RequestedRegion(null, RequestedRegionReason.Initial)); } + [TestMethod] + public void Equality_RegionNameIsCaseInsensitive() + { + RequestedRegion a = new RequestedRegion("East US", RequestedRegionReason.Initial); + RequestedRegion b = new RequestedRegion("east us", RequestedRegionReason.Initial); + + Assert.IsTrue(a.Equals(b)); + Assert.IsTrue(a.Equals((object)b)); + Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); + } + + [TestMethod] + public void Equality_DifferentReason_NotEqual() + { + RequestedRegion a = new RequestedRegion("East US", RequestedRegionReason.Initial); + RequestedRegion b = new RequestedRegion("East US", RequestedRegionReason.Hedging); + + Assert.IsFalse(a.Equals(b)); + } + [TestMethod] public void Equals_NonRequestedRegionObject_ReturnsFalse() {