From c41921f24d07e49127ab7c3ace00f940ffcc9920 Mon Sep 17 00:00:00 2001 From: Shaleen Kalsi Date: Mon, 14 Dec 2020 20:50:35 +0530 Subject: [PATCH] modified PartitionkeyDeleteTest + comment fixes --- .../src/Resource/Container/Container.cs | 2 +- .../Resource/Container/ContainerCore.Items.cs | 2 +- .../Resource/Container/ContainerInlineCore.cs | 2 +- .../CosmosItemTests.cs | 42 ++++++++++++++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs index 99939c3c5b..a602280027 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs @@ -1182,7 +1182,7 @@ public abstract ChangeFeedEstimator GetChangeFeedEstimator( /// (Optional) The options for the Partition Key Delete request. /// (Optional) representing request cancellation. /// - /// A containing a which wraps a . + /// A containing a . /// public abstract Task DeleteAllItemsByPartitionKeyStreamAsync( Cosmos.PartitionKey partitionKey, diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs index 2dee463d64..9585ae2ff5 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs @@ -912,6 +912,7 @@ public override async Task GetPartitionKeyValueFromStreamAsync( public Task DeleteAllItemsByPartitionKeyStreamAsync( Cosmos.PartitionKey partitionKey, + CosmosDiagnosticsContext diagnosticsContext, ITrace trace, ItemRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) @@ -927,7 +928,6 @@ public Task DeleteAllItemsByPartitionKeyStreamAsync( } ContainerCore.ValidatePartitionKey(resultingPartitionKey, requestOptions); - CosmosDiagnosticsContext diagnosticsContext = CosmosDiagnosticsContext.Create(requestOptions); return this.ClientContext.ProcessResourceOperationStreamAsync( resourceUri: this.LinkUri, diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs index 684832020d..2cf5b0b373 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs @@ -463,7 +463,7 @@ public override Task 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)); } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index de64d05731..63927b7835 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -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 itemResponse = await this.Container.CreateItemAsync(testItem1); + ItemResponse itemResponse2 = await this.Container.CreateItemAsync(testItem2); + ItemResponse itemResponse3 = await this.Container.CreateItemAsync(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]