Skip to content

Commit

Permalink
Fixed CreateContainerIfNotExistsAsync validation to limit to partitio…
Browse files Browse the repository at this point in the history
…nKeyPath only (#629)

* inital commmit

* removing space

* updating  change log

* Updated changelog
  • Loading branch information
simplynaveen20 authored and kirankumarkolli committed Aug 7, 2019
1 parent 7698311 commit 64a0cad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ public override async Task<ContainerResponse> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,41 @@ 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]
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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<T> 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) 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

Expand Down

0 comments on commit 64a0cad

Please sign in to comment.