internal MockContainerProvider(string databaseName, string containerName, MockCosmosState cosmosState, MockLogger logger)
 {
     this.DatabaseName  = databaseName;
     this.ContainerName = containerName;
     this.CosmosState   = cosmosState;
     this.Logger        = logger;
 }
Example #2
0
        public async Task <IContainerProvider> CreateContainerAsync(string id, string partitionKeyPath)
        {
            // Used to model asynchrony in the request.
            await Task.Yield();

            this.Logger.LogInformation("Creating container '{0}' in database '{1}'.", id, this.DatabaseName);

            this.CosmosState.EnsureDatabaseExists(this.DatabaseName);

            var database = this.CosmosState.Databases[this.DatabaseName];

            if (string.IsNullOrEmpty(id))
            {
                throw MockCosmosState.CreateCosmosClientException(
                          $"The container name cannot be empty",
                          HttpStatusCode.BadRequest);
            }

            this.CosmosState.EnsureContainerDoesNotExistInDatabase(database, id);
            database[id] = new ConcurrentDictionary <PartitionKey, ConcurrentDictionary <string, object> >();
            return(new MockContainerProvider(this.DatabaseName, id, this.CosmosState, this.Logger));
        }
 internal MockClientProvider(MockCosmosState cosmosState, MockLogger logger)
 {
     this.CosmosState = cosmosState;
     this.Logger      = logger;
 }