diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs index 4e299c48d8..78459239f6 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.cs @@ -219,7 +219,7 @@ public Task DeleteContainerStreamAsync( public Task ReadContainerStreamAsync( CosmosDiagnosticsContext diagnosticsContext, - ContainerRequestOptions requestOptions = null, + RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return this.ProcessStreamAsync( @@ -489,8 +489,8 @@ private Task ProcessStreamAsync( CosmosDiagnosticsContext diagnosticsContext, Stream streamPayload, OperationType operationType, - ContainerRequestOptions requestOptions = null, - CancellationToken cancellationToken = default) + RequestOptions requestOptions, + CancellationToken cancellationToken) { return this.ProcessResourceOperationStreamAsync( diagnosticsContext: diagnosticsContext, diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs index 8a827b4543..7fc9ffe2d8 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs @@ -187,6 +187,7 @@ public async Task CreateContainerIfNotExistsAsync( ContainerCore container = (ContainerCore)this.GetContainer(containerProperties.Id); using (ResponseMessage readResponse = await container.ReadContainerStreamAsync( diagnosticsContext: diagnosticsContext, + requestOptions: requestOptions, cancellationToken: cancellationToken)) { if (readResponse.StatusCode != HttpStatusCode.NotFound) @@ -227,6 +228,7 @@ public async Task CreateContainerIfNotExistsAsync( // so for the remaining ones we should do a Read instead of throwing Conflict exception using (ResponseMessage readResponseAfterCreate = await container.ReadContainerStreamAsync( diagnosticsContext: diagnosticsContext, + requestOptions: requestOptions, cancellationToken: cancellationToken)) { return this.ClientContext.ResponseFactory.CreateContainerResponse(container, readResponseAfterCreate); 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 e22bfb33d9..01c8a849e5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs @@ -505,6 +505,50 @@ public async Task PartitionedCreateWithPathDelete() Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); } + [TestMethod] + public async Task CreateContainerIfNotExistsPropertiesTestAsync() + { + string key = Guid.NewGuid().ToString(); + Dictionary properties = new Dictionary() + { + { key, Guid.NewGuid() } + }; + + // Count is used to validate the handler actually got called. + int count = 0; + RequestHandlerHelper requestHandlerHelper = new RequestHandlerHelper + { + UpdateRequestMessage = requestMessage => + { + if (requestMessage.ResourceType == ResourceType.Collection) + { + count++; + Assert.IsNotNull(requestMessage.Properties); + Assert.IsTrue(object.ReferenceEquals(properties[key], requestMessage.Properties[key])); + } + } + }; + + CosmosClient client = TestCommon.CreateCosmosClient(x => x.AddCustomHandlers(requestHandlerHelper)); + string containerName = Guid.NewGuid().ToString(); + string partitionKeyPath1 = "/users"; + + RequestOptions requestOptions = new RequestOptions() + { + Properties = properties + }; + + ContainerProperties settings = new ContainerProperties(containerName, partitionKeyPath1); + + Cosmos.Database database = client.GetDatabase(this.cosmosDatabase.Id); + ContainerResponse containerResponse = await database.CreateContainerIfNotExistsAsync(settings, requestOptions: requestOptions); + Assert.IsTrue(count > 0); + + count = 0; + await database.CreateContainerIfNotExistsAsync(settings, requestOptions: requestOptions); + Assert.IsTrue(count > 0); + } + [TestMethod] public async Task CreateContainerIfNotExistsAsyncTest() {