From 9366646e51795822503e3b5f9878d742c14a8ee2 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Singh Date: Fri, 2 Aug 2019 15:12:06 -0400 Subject: [PATCH 1/4] inital commmit --- .../src/Resource/Database/DatabaseCore.cs | 4 +-- .../CosmosContainerTests.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs index 7b34e18405..f787b49dac 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs @@ -186,9 +186,7 @@ public override async Task CreateContainerIfNotExistsAsync( if (response.StatusCode != HttpStatusCode.NotFound) { ContainerResponse retrivedContainerResponse = await this.ClientContext.ResponseFactory.CreateContainerResponseAsync(container, Task.FromResult(response)); - if (!PartitionKeyDefinition.AreEquivalent( - retrivedContainerResponse.Resource.PartitionKey, - containerProperties.PartitionKey)) + if (!retrivedContainerResponse.Resource.PartitionKeyPath.Equals(containerProperties.PartitionKeyPath)) { throw new ArgumentException( string.Format( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs index a6269169a8..80eb9d70b4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs @@ -184,6 +184,42 @@ public async Task CreateContainerIfNotExistsAsyncTest() containerResponse = await containerResponse.Container.DeleteContainerAsync(); Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); + + + //Creating existing container with partition key having value for SystemKey + //https://github.com/Azure/azure-cosmos-dotnet-v3/issues/623 + string v2ContainerName = "V2Container"; + PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); + partitionKeyDefinition.Paths.Add("/test"); + partitionKeyDefinition.IsSystemKey = false; + ContainerProperties containerPropertiesWithSystemKey = new ContainerProperties() + { + Id = v2ContainerName, + PartitionKey = partitionKeyDefinition, + }; + await this.cosmosDatabase.CreateContainerAsync(containerPropertiesWithSystemKey); + + ContainerProperties containerProperties = new ContainerProperties(v2ContainerName, "/test"); + containerResponse = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(containerProperties); + Assert.AreEqual(HttpStatusCode.OK, containerResponse.StatusCode); + Assert.AreEqual(v2ContainerName, containerResponse.Resource.Id); + Assert.AreEqual("/test", containerResponse.Resource.PartitionKey.Paths.First()); + + containerResponse = await containerResponse.Container.DeleteContainerAsync(); + Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); + + containerPropertiesWithSystemKey.PartitionKey.IsSystemKey = true; + await this.cosmosDatabase.CreateContainerAsync(containerPropertiesWithSystemKey); + + containerProperties = new ContainerProperties(v2ContainerName, "/test"); + containerResponse = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(containerProperties); + Assert.AreEqual(HttpStatusCode.OK, containerResponse.StatusCode); + Assert.AreEqual(v2ContainerName, containerResponse.Resource.Id); + Assert.AreEqual("/test", containerResponse.Resource.PartitionKey.Paths.First()); + + containerResponse = await containerResponse.Container.DeleteContainerAsync(); + Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); + } [TestMethod] From 09c92d91b56634d2f81fb8a1c151403167e6e287 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Singh Date: Fri, 2 Aug 2019 15:17:51 -0400 Subject: [PATCH 2/4] removing space --- .../Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs index 80eb9d70b4..3098694fff 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs @@ -219,7 +219,6 @@ public async Task CreateContainerIfNotExistsAsyncTest() containerResponse = await containerResponse.Container.DeleteContainerAsync(); Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); - } [TestMethod] From 0668520a27f0b4b98a320bf78777ff9b75724635 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Singh Date: Mon, 5 Aug 2019 18:36:24 -0400 Subject: [PATCH 3/4] updating change log --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index c6451dd26a..dc7b824ade 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#612](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/612) Bug fix for ReadFeed with partition-key - [#614](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/614) Fixed SpatialPath serialization and compatibility with older index versions +- [#629](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/629) Bug fix for CreateContainerIfNotExistsAsync api ## [3.1.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.1.0) - 2019-07-26 From 189357194193c6c0a0311c0dc1145671be33babc Mon Sep 17 00:00:00 2001 From: kirankumarkolli Date: Wed, 7 Aug 2019 07:50:57 +0530 Subject: [PATCH 4/4] Updated changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index b91f2cf6a9..685df06a6f 100644 --- a/changelog.md +++ b/changelog.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#612](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/612) Bug fix for ReadFeed with partition-key - [#614](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/614) Fixed SpatialPath serialization and compatibility with older index versions - [#626](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/626) FeedResponse status code now return OK for success instead of the invalid status code 0 or Accepted -- [#629](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/629) Bug fix for CreateContainerIfNotExistsAsync api +- [#629](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/629) Fixed CreateContainerIfNotExistsAsync validation to limited to partitionKeyPath only ## [3.1.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.1.0) - 2019-07-26