Esempio n. 1
1
        public void Drop_should_drop_the_files_and_chunks_collections(
            [Values(false, true)] bool async)
        {
            var client = DriverTestConfiguration.Client;
            var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            var subject = new GridFSBucket(database);
            subject.UploadFromBytes("test", new byte[] { 0 }); // causes the collections to be created

            if (async)
            {
                subject.DropAsync().GetAwaiter().GetResult();
            }
            else
            {
                subject.Drop();
            }

            var collections = database.ListCollections().ToList();
            var collectionNames = collections.Select(c => c["name"].AsString);
            collectionNames.Should().NotContain("fs.files");
            collectionNames.Should().NotContain("fs.chunks");
        }
Esempio n. 2
0
        public void Drop_should_throw_when_a_write_concern_error_occurss(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet);
            var client   = DriverTestConfiguration.Client;
            var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);

            EnsureBucketExists(new GridFSBucket(database)); // with default WriteConcern
            var options = new GridFSBucketOptions {
                WriteConcern = new WriteConcern(9)
            };
            var subject = new GridFSBucket(database, options);

            var exception = Record.Exception(() =>
            {
                if (async)
                {
                    subject.DropAsync().GetAwaiter().GetResult();
                }
                else
                {
                    subject.Drop();
                }
            });

            exception.Should().BeOfType <MongoWriteConcernException>();
        }
        public void Drop_should_drop_the_files_and_chunks_collections(
            [Values(false, true)] bool async)
        {
            RequireServer.Check();
            var client   = DriverTestConfiguration.Client;
            var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            var subject  = new GridFSBucket(database);

            EnsureBucketExists(subject);

            if (async)
            {
                subject.DropAsync().GetAwaiter().GetResult();
            }
            else
            {
                subject.Drop();
            }

            var collections     = database.ListCollections().ToList();
            var collectionNames = collections.Select(c => c["name"].AsString);

            collectionNames.Should().NotContain("fs.files");
            collectionNames.Should().NotContain("fs.chunks");
        }
    private static void ClearGridFS()
    {
        var bucket = new GridFSBucket(mongoDb, new GridFSBucketOptions {
            BucketName = "pictures"
        });

        bucket.Drop();
    }
Esempio n. 5
0
        public void DropEntireBucket()
        {
            MongoClient client = GetClient(m_connectionStr);
            var         db     = client.GetDatabase(DatabaseName);
            var         bucket = new GridFSBucket(db, BucksOptions);

            bucket.Drop();
        }
Esempio n. 6
0
        public virtual void Setup()
        {
            var credential     = MongoCredential.CreateCredential("admin", "egAdmin", "gremlinz");
            var serverUrl      = ConfigurationManager.AppSettings["mongoQueueUrl"];
            var clientSettings = new MongoClientSettings()
            {
                Server     = new MongoServerAddress(serverUrl),
                Credential = credential
            };

            var client = new MongoClient(serverUrl);
            var db     = client.GetDatabase(ConfigurationManager.AppSettings["mongoQueueDb"]);

            collection = client.GetDatabase(ConfigurationManager.AppSettings["mongoQueueDb"])
                         .GetCollection <BsonDocument>(ConfigurationManager.AppSettings["mongoQueueCollection"]);

            db.DropCollection(ConfigurationManager.AppSettings["mongoQueueCollection"]);

            this.gridfs = new GridFSBucket(this.collection.Database);
            gridfs.Drop();

            queue = new Queue();
        }
        public void Drop_should_drop_the_files_and_chunks_collections(
            [Values(false, true)] bool async)
        {
            var client   = DriverTestConfiguration.Client;
            var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            var subject  = new GridFSBucket(database);

            subject.UploadFromBytes("test", new byte[] { 0 }); // causes the collections to be created

            if (async)
            {
                subject.DropAsync().GetAwaiter().GetResult();
            }
            else
            {
                subject.Drop();
            }

            var collections     = database.ListCollections().ToList();
            var collectionNames = collections.Select(c => c["name"].AsString);

            collectionNames.Should().NotContain("fs.files");
            collectionNames.Should().NotContain("fs.chunks");
        }
Esempio n. 8
0
 /// <summary>
 /// 删除所有
 /// </summary>
 public void DroppGridFSBucket()
 {
     bucket.Drop();
 }
        public void Drop_should_throw_when_a_write_concern_error_occurss(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet);
            var client = DriverTestConfiguration.Client;
            var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            EnsureBucketExists(new GridFSBucket(database)); // with default WriteConcern
            var options = new GridFSBucketOptions { WriteConcern = new WriteConcern(9) };
            var subject = new GridFSBucket(database, options);

            var exception = Record.Exception(() =>
            {
                if (async)
                {
                    subject.DropAsync().GetAwaiter().GetResult();
                }
                else
                {
                    subject.Drop();
                }
            });

            exception.Should().BeOfType<MongoWriteConcernException>();
        }
        public void Drop_should_drop_the_files_and_chunks_collections(
            [Values(false, true)] bool async)
        {
            RequireServer.Check();
            var client = DriverTestConfiguration.Client;
            var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            var subject = new GridFSBucket(database);
            EnsureBucketExists(subject);

            if (async)
            {
                subject.DropAsync().GetAwaiter().GetResult();
            }
            else
            {
                subject.Drop();
            }

            var collections = database.ListCollections().ToList();
            var collectionNames = collections.Select(c => c["name"].AsString);
            collectionNames.Should().NotContain("fs.files");
            collectionNames.Should().NotContain("fs.chunks");
        }