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

RequestOption.Properties: Fixes RequestOption.Properties for CreateContainerIfNotExistsAsync #1961

Merged
merged 1 commit into from
Oct 26, 2020
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 @@ -219,7 +219,7 @@ public Task<ResponseMessage> DeleteContainerStreamAsync(

public Task<ResponseMessage> ReadContainerStreamAsync(
CosmosDiagnosticsContext diagnosticsContext,
ContainerRequestOptions requestOptions = null,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
{
return this.ProcessStreamAsync(
Expand Down Expand Up @@ -489,8 +489,8 @@ private Task<ResponseMessage> ProcessStreamAsync(
CosmosDiagnosticsContext diagnosticsContext,
Stream streamPayload,
OperationType operationType,
ContainerRequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
RequestOptions requestOptions,
CancellationToken cancellationToken)
{
return this.ProcessResourceOperationStreamAsync(
diagnosticsContext: diagnosticsContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public async Task<ContainerResponse> 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)
Expand Down Expand Up @@ -227,6 +228,7 @@ public async Task<ContainerResponse> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> properties = new Dictionary<string, object>()
{
{ 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()
{
Expand Down