Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CreateContainerIfNotExistsAsync validation to limit to partitionKeyPath only #629

Merged
merged 5 commits into from
Aug 7, 2019
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 @@ -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))
simplynaveen20 marked this conversation as resolved.
Show resolved Hide resolved
{
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