public TestMongoDatabase()
            : base(new MongoConnectionSettings {
            Database = "test"
        })
        {
            RemoveAll = Commands.RemoveAllAsync(this);

            ModelQueries         = GetQueriesInterface <TestModel>();
            StorageModelQueries  = GetQueriesInterface <TestModel, TestMetadata>();
            ModelCommands        = GetCommandsInterface <Guid, TestModel>();
            StorageModelCommands = GetCommandsInterface <Guid, TestModel, TestMetadata>();
        }
Exemple #2
0
        /// <summary>
        /// Creates a remove all command against the specified database.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="database">The database.</param>
        /// <returns>A new remove all command.</returns>
        public static RemoveAllCommandAsync <TModel> RemoveAllAsync <TModel>(MongoDatabase database)
        {
            var removeAllCommandAsync = RemoveAllAsync(database);

            RemoveAllCommandAsync <TModel> commandAsync =
                async(collectionName, cancellationToken) =>
            {
                var modelTypeName = string.IsNullOrWhiteSpace(collectionName) ? typeof(TModel).Name : collectionName;

                await removeAllCommandAsync(modelTypeName, cancellationToken);
            };

            return(commandAsync);
        }
Exemple #3
0
        /// <summary>
        /// Creates a remove all command against the specified database.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <returns>A new remove all command.</returns>
        public static RemoveAllCommandAsync RemoveAllAsync(MongoDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            RemoveAllCommandAsync commandAsync = async(collectionName, cancellationToken) =>
            {
                if (string.IsNullOrWhiteSpace(collectionName))
                {
                    throw new ArgumentNullException(nameof(collectionName));
                }

                var client = database.CreateClient();
                await client.DropCollectionAsync(collectionName, cancellationToken);
            };

            return(commandAsync);
        }