예제 #1
0
        private async Task ContainerOperations(CosmosDatabase database, bool dbNotExist)
        {
            // Create should fail if the database does not exist
            if (dbNotExist)
            {
                CosmosContainerSettings newcontainerSettings = new CosmosContainerSettings(id: DoesNotExist, partitionKeyPath: "/pk");
                this.VerifyNotFoundResponse(await database.Containers.CreateContainerAsStreamAsync(newcontainerSettings, throughput: 500));
            }

            CosmosContainer doesNotExistContainer = database.Containers[DoesNotExist];

            this.VerifyNotFoundResponse(await doesNotExistContainer.ReadAsStreamAsync());

            CosmosContainerSettings containerSettings = new CosmosContainerSettings(id: DoesNotExist, partitionKeyPath: "/pk");

            this.VerifyNotFoundResponse(await doesNotExistContainer.ReplaceAsStreamAsync(containerSettings));
            this.VerifyNotFoundResponse(await doesNotExistContainer.DeleteAsStreamAsync());

            // Validate Child resources
            await this.ItemOperations(doesNotExistContainer, true);

            // The database exists create a container and validate it's children
            if (!dbNotExist)
            {
                CosmosContainer containerExists = await database.Containers.CreateContainerAsync(
                    id : "NotFoundTest" + Guid.NewGuid().ToString(),
                    partitionKeyPath : "/pk");

                await this.ItemOperations(containerExists, false);
            }
        }