Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override string ToString()
{
if (this.PartitionKey.IsNone)
{
return "None";
return PartitionKey.NoneString;
}

return this.PartitionKey.InternalKey.ToJsonString();
Expand Down
10 changes: 10 additions & 0 deletions Microsoft.Azure.Cosmos/src/PartitionKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
internal bool IsNone { get; }

/// <summary>
/// String representation of None for use when representing Partition Key as none.
/// </summary>
internal const string NoneString = "None";

/// <summary>
/// Creates a new partition key value.
/// </summary>
Expand Down Expand Up @@ -173,6 +178,11 @@ public bool Equals(PartitionKey other)
/// <returns>The string representation of the partition key value</returns>
public override string ToString()
{
if (this.IsNone)
{
return NoneString;
}

if (this.InternalKey == null)
{
return PartitionKey.NullPartitionKeyInternal.ToJsonString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down