Skip to content

Commit

Permalink
modified PartitionkeyDeleteTest + comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaleen Kalsi committed Dec 14, 2020
1 parent 2da3eca commit c41921f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ public abstract ChangeFeedEstimator GetChangeFeedEstimator(
/// <param name="requestOptions">(Optional) The options for the Partition Key Delete request.</param>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>
/// A <see cref="Task"/> containing a <see cref="ResponseMessage"/> which wraps a <see cref="Stream"/>.
/// A <see cref="Task"/> containing a <see cref="ResponseMessage"/>.
/// </returns>
public abstract Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
Cosmos.PartitionKey partitionKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ public override async Task<PartitionKey> GetPartitionKeyValueFromStreamAsync(

public Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
Cosmos.PartitionKey partitionKey,
CosmosDiagnosticsContext diagnosticsContext,
ITrace trace,
ItemRequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -927,7 +928,6 @@ public Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
}

ContainerCore.ValidatePartitionKey(resultingPartitionKey, requestOptions);
CosmosDiagnosticsContext diagnosticsContext = CosmosDiagnosticsContext.Create(requestOptions);

return this.ClientContext.ProcessResourceOperationStreamAsync(
resourceUri: this.LinkUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public override Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
return this.ClientContext.OperationHelperAsync(
nameof(DeleteAllItemsByPartitionKeyStreamAsync),
requestOptions,
(diagnostics, trace) => base.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey, trace, requestOptions, cancellationToken));
(diagnostics, trace) => base.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey, diagnostics, trace, requestOptions, cancellationToken));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -568,21 +568,53 @@ await feedIterator.ReadNextAsync(this.cancellationToken))
public async Task PartitionKeyDeleteTest()
{
string pKString = "PK1";
string pKString2 = "PK2";
dynamic testItem1 = new
{
id = "item1",
status = pKString
};

dynamic testItem2 = new
{
id = "item2",
status = pKString
};

dynamic testItem3 = new
{
id = "item3",
status = pKString2
};

ContainerInternal containerInternal = (ContainerInternal)this.Container;
ItemResponse<dynamic> itemResponse = await this.Container.CreateItemAsync<dynamic>(testItem1);
ItemResponse<dynamic> itemResponse2 = await this.Container.CreateItemAsync<dynamic>(testItem2);
ItemResponse<dynamic> itemResponse3 = await this.Container.CreateItemAsync<dynamic>(testItem3);
Cosmos.PartitionKey partitionKey1 = new Cosmos.PartitionKey(pKString);
ResponseMessage pKDeleteResponse = await containerInternal.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey1);
Assert.AreEqual(pKDeleteResponse.StatusCode, HttpStatusCode.OK);
Cosmos.PartitionKey partitionKey2 = new Cosmos.PartitionKey(pKString2);
using (ResponseMessage pKDeleteResponse = await containerInternal.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey1))
{
Assert.AreEqual(pKDeleteResponse.StatusCode, HttpStatusCode.OK);
}

ResponseMessage readResponse = await this.Container.ReadItemStreamAsync("item1", partitionKey1);
Assert.AreEqual(readResponse.StatusCode, HttpStatusCode.NotFound);
Assert.AreEqual(readResponse.Headers.SubStatusCode, SubStatusCodes.Unknown);
using (ResponseMessage readResponse = await this.Container.ReadItemStreamAsync("item1", partitionKey1))
{
Assert.AreEqual(readResponse.StatusCode, HttpStatusCode.NotFound);
Assert.AreEqual(readResponse.Headers.SubStatusCode, SubStatusCodes.Unknown);
}

using (ResponseMessage readResponse = await this.Container.ReadItemStreamAsync("item2", partitionKey1))
{
Assert.AreEqual(readResponse.StatusCode, HttpStatusCode.NotFound);
Assert.AreEqual(readResponse.Headers.SubStatusCode, SubStatusCodes.Unknown);
}

//verify item with the other Partition Key is not deleted
using (ResponseMessage readResponse = await this.Container.ReadItemStreamAsync("item3", partitionKey2))
{
Assert.AreEqual(readResponse.StatusCode, HttpStatusCode.OK);
}
}

[TestMethod]
Expand Down

0 comments on commit c41921f

Please sign in to comment.