Example #1
0
        /// <summary>
        /// Creates a new test collection from file.
        /// </summary>
        /// <typeparam name="T">The document type.</typeparam>
        /// <returns>
        /// Returns the newly created collection.
        /// </returns>
        public async Task <IMongoCollection <T> > CreateCollectionFromFileAsync <T>()
        {
            var            options  = new CreateCollectionFromFileOptions();
            IMongoDatabase database = CreateDatabase();

            return(await CreateCollectionFromFileAsync <T>(
                       database, options));
        }
Example #2
0
        /// <summary>
        /// Creates a new test collection from file with specified <paramref name="options"/>.
        /// inside of the given <paramref name="database"/>
        /// </summary>
        /// <typeparam name="T">The document type.</typeparam>
        /// <param name="database">The target database</param>
        /// <param name="options">The collection creation options.</param>
        /// <returns>
        /// Returns the newly created collection.
        /// </returns>
        public async Task <IMongoCollection <T> > CreateCollectionFromFileAsync <T>(
            IMongoDatabase database,
            CreateCollectionFromFileOptions options)
        {
            options  = options ?? new CreateCollectionFromFileOptions();
            database = database ?? CreateDatabase(options.CollectionOptions.DatabaseOptions);

            return(await CreateCollectionFromFileInternalAsync <T>(database, options));
        }
Example #3
0
        /// <summary>
        /// Creates a new test collection from file with specified <paramref name="options"/>.
        /// inside of the generated database.
        /// </summary>
        /// <typeparam name="T">The document type.</typeparam>
        /// <param name="options">The collection creation options.</param>
        /// <returns>
        /// Returns the newly created collection.
        /// </returns>
        public async Task <IMongoCollection <T> > CreateCollectionFromFileAsync <T>(
            CreateCollectionFromFileOptions options)
        {
            IMongoDatabase database = CreateDatabase(
                options.CollectionOptions.DatabaseOptions);

            return(await CreateCollectionFromFileInternalAsync <T>(
                       database, options));
        }
Example #4
0
        private async Task <IMongoCollection <T> > CreateCollectionFromFileInternalAsync <T>(
            IMongoDatabase database,
            CreateCollectionFromFileOptions options)
        {
            await MongoUtils.DeployAndImport(
                options, Settings);

            return(database
                   .GetCollection <T>(options.CollectionOptions.CollectionName));
        }
Example #5
0
        internal static async Task DeployAndImport(
            CreateCollectionFromFileOptions options,
            IImageSettings settings)
        {
            var copyContext = new CopyContext(
                options.File.FullName,
                Path.Combine(options.Destination, options.File.Name));

            await Container.CopyTo(copyContext, settings);

            await Container.InvokeCommand(
                new MongoImportCommand(
                    copyContext.Destination,
                    options.CollectionOptions.DatabaseOptions.DatabaseName,
                    options.CollectionOptions.CollectionName,
                    options.CustomImportArgs),
                settings);
        }