Beispiel #1
0
        private async Task VerifyPartitionKeyDeleteOperation(
            Cosmos.PartitionKey partitionKey,
            string partitionKeySerialized,
            RequestOptions requestOptions = null)
        {
            ResponseMessage response            = null;
            HttpStatusCode  httpStatusCode      = HttpStatusCode.OK;
            int             testHandlerHitCount = 0;
            TestHandler     testHandler         = new TestHandler((request, cancellationToken) =>
            {
                Assert.IsTrue(request.RequestUri.OriginalString.StartsWith(@"dbs/testdb/colls/testcontainer"));
                Assert.AreEqual(requestOptions, request.RequestOptions);
                Assert.AreEqual(ResourceType.PartitionKey, request.ResourceType);
                Assert.IsNotNull(request.Headers.PartitionKey);
                Assert.AreEqual(partitionKeySerialized, request.Headers.PartitionKey);
                testHandlerHitCount++;
                response = new ResponseMessage(httpStatusCode, request, errorMessage: null)
                {
                    Content = request.Content
                };
                return(Task.FromResult(response));
            });

            CosmosClient client = MockCosmosUtil.CreateMockCosmosClient(
                (builder) => builder.AddCustomHandlers(testHandler));

            Container container = client.GetDatabase("testdb")
                                  .GetContainer("testcontainer");

            ContainerInternal containerInternal = (ContainerInternal)container;
            ResponseMessage   responseMessage   = await containerInternal.DeleteAllItemsByPartitionKeyStreamAsync(
                partitionKey : partitionKey,
                requestOptions : requestOptions);

            Assert.IsNotNull(responseMessage);
            Assert.AreEqual(httpStatusCode, responseMessage.StatusCode);
            Assert.AreEqual(1, testHandlerHitCount, "The operation did not make it to the handler");
        }