From e9eaf0534ba02a213d8e28c9140c5a0b3396545c Mon Sep 17 00:00:00 2001 From: Adam Holliday Date: Tue, 11 Oct 2022 12:20:16 -0400 Subject: [PATCH 1/4] Added toString handling for None in addition to existing null --- Microsoft.Azure.Cosmos/src/PartitionKey.cs | 5 +++++ .../Microsoft.Azure.Cosmos.Tests/PartitionKeyTests.cs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/Microsoft.Azure.Cosmos/src/PartitionKey.cs b/Microsoft.Azure.Cosmos/src/PartitionKey.cs index 86e0bbae58..44c17a21cb 100644 --- a/Microsoft.Azure.Cosmos/src/PartitionKey.cs +++ b/Microsoft.Azure.Cosmos/src/PartitionKey.cs @@ -173,6 +173,11 @@ public bool Equals(PartitionKey other) /// The string representation of the partition key value public override string ToString() { + if (this.IsNone) + { + return "None"; + } + if (this.InternalKey == null) { return PartitionKey.NullPartitionKeyInternal.ToJsonString(); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyTests.cs index c5c2be4ea7..cac1d9ab72 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyTests.cs @@ -88,6 +88,15 @@ public void TestPartitionKeyDefinitionAreEquivalent() Assert.IsTrue(PartitionKeyDefinition.AreEquivalent(definition1, definition2)); } + [TestMethod] + public void NoneToStringNotNullRef() + { + const string noneString = "None"; + Cosmos.PartitionKey noneKey = Cosmos.PartitionKey.None; + + Assert.AreEqual(noneString, noneKey.ToString()); + } + [TestMethod] public void RoundTripTests() { From 27fe2e60fc9810bc60eef6757e3244d00132beba Mon Sep 17 00:00:00 2001 From: Adam Holliday Date: Tue, 11 Oct 2022 14:22:38 -0400 Subject: [PATCH 2/4] Added const string representation of None --- Microsoft.Azure.Cosmos/src/PartitionKey.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/PartitionKey.cs b/Microsoft.Azure.Cosmos/src/PartitionKey.cs index 44c17a21cb..16d6515656 100644 --- a/Microsoft.Azure.Cosmos/src/PartitionKey.cs +++ b/Microsoft.Azure.Cosmos/src/PartitionKey.cs @@ -4,6 +4,7 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Runtime.CompilerServices; using Microsoft.Azure.Documents.Routing; /// @@ -48,6 +49,11 @@ namespace Microsoft.Azure.Cosmos /// internal bool IsNone { get; } + /// + /// String representation of None for use when representing Partition Key as none. + /// + private const string NoneString = "None"; + /// /// Creates a new partition key value. /// @@ -175,7 +181,7 @@ public override string ToString() { if (this.IsNone) { - return "None"; + return NoneString; } if (this.InternalKey == null) From 5176a7e1699511b07a4acec44fe9dc6c93079cf5 Mon Sep 17 00:00:00 2001 From: Adam Holliday Date: Tue, 11 Oct 2022 14:24:31 -0400 Subject: [PATCH 3/4] Unnecessary using added - removed --- Microsoft.Azure.Cosmos/src/PartitionKey.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/PartitionKey.cs b/Microsoft.Azure.Cosmos/src/PartitionKey.cs index 16d6515656..308015646f 100644 --- a/Microsoft.Azure.Cosmos/src/PartitionKey.cs +++ b/Microsoft.Azure.Cosmos/src/PartitionKey.cs @@ -4,7 +4,6 @@ namespace Microsoft.Azure.Cosmos { using System; - using System.Runtime.CompilerServices; using Microsoft.Azure.Documents.Routing; /// From 3a0b7d0315bb46084e618fc14e1bde4f7075123e Mon Sep 17 00:00:00 2001 From: Adam Holliday Date: Tue, 11 Oct 2022 15:11:43 -0400 Subject: [PATCH 4/4] Consistent handling of None for both references to PartitionKey.None.ToString() --- .../src/FeedRange/FeedRanges/FeedRangePartitionKey.cs | 2 +- Microsoft.Azure.Cosmos/src/PartitionKey.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/FeedRange/FeedRanges/FeedRangePartitionKey.cs b/Microsoft.Azure.Cosmos/src/FeedRange/FeedRanges/FeedRangePartitionKey.cs index 0b73a1a349..47f84fd280 100644 --- a/Microsoft.Azure.Cosmos/src/FeedRange/FeedRanges/FeedRangePartitionKey.cs +++ b/Microsoft.Azure.Cosmos/src/FeedRange/FeedRanges/FeedRangePartitionKey.cs @@ -79,7 +79,7 @@ public override string ToString() { if (this.PartitionKey.IsNone) { - return "None"; + return PartitionKey.NoneString; } return this.PartitionKey.InternalKey.ToJsonString(); diff --git a/Microsoft.Azure.Cosmos/src/PartitionKey.cs b/Microsoft.Azure.Cosmos/src/PartitionKey.cs index 308015646f..959175d2ae 100644 --- a/Microsoft.Azure.Cosmos/src/PartitionKey.cs +++ b/Microsoft.Azure.Cosmos/src/PartitionKey.cs @@ -51,7 +51,7 @@ namespace Microsoft.Azure.Cosmos /// /// String representation of None for use when representing Partition Key as none. /// - private const string NoneString = "None"; + internal const string NoneString = "None"; /// /// Creates a new partition key value.