Beispiel #1
0
        public Mongo(MongoConfiguration configuration)
        {
            string connectionString = BuildConnectionString(configuration);

            var client = new MongoClient(connectionString);

            _database = client.GetDatabase(configuration.Database);

            if (!IsCollectionExistsInDatabase(ArticlesCollection))
            {
                _database.CreateCollection(ArticlesCollection);
            }

            _articlesCollection = _database.GetCollection <StoredArticle>(ArticlesCollection);

            var imagesOptions = new GridFSBucketOptions {
                BucketName = ImagesCollections
            };
            var videosOptions = new GridFSBucketOptions {
                BucketName = VideosCollection
            };

            _images = new GridFSBucket(_database, imagesOptions);
            _videos = new GridFSBucket(_database, videosOptions);
        }
Beispiel #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>();
        }
Beispiel #3
0
        public void CreateDropCollectionOperation_should_return_expected_result(
            [Values(1, 2)]
            int databaseW,
            [Values(null, 1, 2)]
            int?bucketW)
        {
            var bucketWriteConcern = bucketW.HasValue ? new WriteConcern(bucketW.Value) : null;
            var options            = new GridFSBucketOptions {
                WriteConcern = bucketWriteConcern
            };
            var subject = CreateSubject(options);
            var databaseWriteConcern = new WriteConcern(databaseW);
            var mockDatabase         = Mock.Get(subject.Database);
            var databaseSettings     = new MongoDatabaseSettings {
                WriteConcern = databaseWriteConcern
            };

            mockDatabase.SetupGet(d => d.Settings).Returns(databaseSettings);
            var collectionNamespace    = new CollectionNamespace(subject.Database.DatabaseNamespace, "collection");
            var messageEncoderSettings = new MessageEncoderSettings();

            var result = subject.CreateDropCollectionOperation(collectionNamespace, messageEncoderSettings);

            result.CollectionNamespace.Should().BeSameAs(collectionNamespace);
            result.MessageEncoderSettings.Should().BeSameAs(messageEncoderSettings);
            result.WriteConcern.Should().BeSameAs(bucketWriteConcern ?? databaseWriteConcern);
        }
Beispiel #4
0
        public void CreateCreateChunksCollectionIndexesOperation_should_return_expected_result(
            [Values(1, 2)]
            int databaseW,
            [Values(null, 1, 2)]
            int?bucketW)
        {
            var bucketWriteConcern = bucketW.HasValue ? new WriteConcern(bucketW.Value) : null;
            var options            = new GridFSBucketOptions {
                WriteConcern = bucketWriteConcern
            };
            var subject = CreateSubject(options);
            var databaseWriteConcern = new WriteConcern(databaseW);
            var mockDatabase         = Mock.Get(subject.Database);
            var databaseSettings     = new MongoDatabaseSettings {
                WriteConcern = databaseWriteConcern
            };

            mockDatabase.SetupGet(d => d.Settings).Returns(databaseSettings);

            var result = subject.CreateCreateChunksCollectionIndexesOperation();

            result.CollectionNamespace.CollectionName.Should().Be("fs.chunks");
            result.MessageEncoderSettings.Should().NotBeNull();
            result.Requests.Should().NotBeNull();
            result.WriteConcern.Should().BeSameAs(bucketWriteConcern ?? databaseWriteConcern);
        }
Beispiel #5
0
        public async Task <byte[]> GetDataAsync(string id)
        {
            var coll = GetCollection <MemoryItemModel>(MemoryVaultCollections.Memories);

            var filter = Builders <MemoryItemModel> .Filter.Eq(p => p.Id, ObjectId.Parse(id));

            var project = Builders <MemoryItemModel> .Projection.Expression(e => e.ItemId);

            var proj = new FindOptions <MemoryItemModel, ObjectId>
            {
                Projection = project
            };

            var found = await coll.FindAsync(filter, proj);

            var fileId = await found.FirstOrDefaultAsync();

            if (fileId != null)
            {
                GridFSBucketOptions opts = new GridFSBucketOptions();
                opts.BucketName = MemoryVaultCollections.MemoryFiles;

                var bucket = new GridFSBucket(GetDatabase(), opts);

                return(await bucket.DownloadAsBytesAsync(fileId));
            }

            return(null);
        }
        public async Task DownloadFileMongo()
        {
            var client = new MongoClient("mongodb://localhost:27017");

            var database = client.GetDatabase("BookstoreDb");

            var gridFsBucketOptions = new GridFSBucketOptions()
            {
                BucketName     = "images",
                ChunkSizeBytes = 1048576, // 1МБ
            };

            var bucket = new GridFSBucket(database, gridFsBucketOptions);

            var filter = Builders <GridFSFileInfo <ObjectId> >

                         .Filter.Eq(x => x.Filename, "123.png");

            var searchResult = await bucket.FindAsync(filter);

            var fileEntry = searchResult.FirstOrDefault();

            byte[] content = await bucket.DownloadAsBytesAsync(fileEntry.Id);

            File.WriteAllBytes("123.png", content);
        }
Beispiel #7
0
 // constructors
 protected JsonDrivenGridFSTest(IMongoDatabase database, string bucketName, Dictionary <string, object> objectMap)
     : base(objectMap)
 {
     _database      = database;
     _bucketOptions = new GridFSBucketOptions {
         BucketName = bucketName
     };
 }
Beispiel #8
0
        public void constructor_should_throw_when_database_is_null()
        {
            var options = new GridFSBucketOptions();

            Action action = () => new GridFSBucket(null, options);

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("database");
        }
Beispiel #9
0
        /// <summary>获得文件桶</summary>
        private GridFSBucket CreateBucket(IMongoDatabase database)
        {
            var options = new GridFSBucketOptions();

            options.BucketName     = ImmutableGridFSBucketOptions.Defaults.BucketName;
            options.ChunkSizeBytes = 1024 * 1024 * 1;
            return(new GridFSBucket(database, options));
        }
        public void constructor_should_throw_when_database_is_null()
        {
            var options = new GridFSBucketOptions();

            Action action = () => new GridFSBucket(null, options);

            action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("database");
        }
Beispiel #11
0
        public void BucketName_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.BucketName = "bucket";

            subject.BucketName.Should().Be("bucket");
        }
Beispiel #12
0
        public void ReadConcern_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.ReadConcern = ReadConcern.Majority;

            subject.ReadConcern.Should().Be(ReadConcern.Majority);
        }
        public void ChunkSizeBytes_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.ChunkSizeBytes = 123;

            subject.ChunkSizeBytes.Should().Be(123);
        }
        public void BucketName_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions { BucketName = "bucket" };

            var result = subject.BucketName;

            result.Should().Be("bucket");
        }
        public void ChunkSizeBytes_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions { ChunkSizeBytes = 123 };

            var result = subject.ChunkSizeBytes;

            result.Should().Be(123);
        }
        public void BucketName_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.BucketName = "bucket";

            subject.BucketName.Should().Be("bucket");
        }
        public void BucketName_set_should_throw_when_name_is_null()
        {
            var subject = new GridFSBucketOptions();

            Action action = () => subject.BucketName = null;

            action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("value");
        }
Beispiel #18
0
        public void BucketName_set_should_throw_when_name_is_null()
        {
            var subject = new GridFSBucketOptions();

            Action action = () => subject.BucketName = null;

            action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("value");
        }
Beispiel #19
0
        public void WriteConcern_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.WriteConcern = WriteConcern.WMajority;

            subject.WriteConcern.Should().Be(WriteConcern.WMajority);
        }
Beispiel #20
0
        public void ChunkSizeBytes_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.ChunkSizeBytes = 123;

            subject.ChunkSizeBytes.Should().Be(123);
        }
Beispiel #21
0
        public void SuppressEnsureIndexes_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.SuppressEnsureIndexes = true;

            subject.SuppressEnsureIndexes.Should().BeTrue();
        }
Beispiel #22
0
        public void ReadPreference_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.ReadPreference = ReadPreference.Secondary;

            subject.ReadPreference.Should().Be(ReadPreference.Secondary);
        }
Beispiel #23
0
        public IMonGridFSBucket GetBucket(GridFSBucketOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(new MonGridFSBucket(this, new GridFSBucket(this.MongoDatabase, options)));
        }
Beispiel #24
0
        public void constructor_with_no_arguments_should_initialize_instance_with_default_values()
        {
            var result = new GridFSBucketOptions();

            result.BucketName.Should().Be("fs");
            result.ChunkSizeBytes.Should().Be(255 * 1024);
            result.ReadPreference.Should().BeNull();
            result.WriteConcern.Should().BeNull();
        }
Beispiel #25
0
        /// <summary>
        /// 获得文件字节数组
        /// </summary>
        /// <param name="bucketName"></param>
        /// <param name="fileId"></param>
        /// <returns></returns>
        public static Byte[] GetFileBytes(string bucketName, string fileId)
        {
            GridFSBucketOptions options = new GridFSBucketOptions();

            options.BucketName = bucketName;
            var bucket = new GridFSBucket(mongoContext, options);

            return(bucket.DownloadAsBytes(new ObjectId(fileId)));
        }
Beispiel #26
0
        public void ChunkSizeBytes_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions {
                ChunkSizeBytes = 123
            };

            var result = subject.ChunkSizeBytes;

            result.Should().Be(123);
        }
Beispiel #27
0
        /// <summary>
        /// 上传文件(流)
        /// </summary>
        /// <param name="bucketName">相当于文件夹名</param>
        /// <param name="fileName">文件名</param>
        /// <param name="fs">文件流</param>
        /// <returns></returns>
        public static ObjectId UploadFile(string bucketName, string fileName, Stream fs)
        {
            GridFSBucketOptions options = new GridFSBucketOptions();

            options.BucketName = bucketName;
            var bucket = new GridFSBucket(mongoContext, options);
            var oid    = bucket.UploadFromStream(fileName, fs);

            return(oid);
        }
Beispiel #28
0
        public void BucketName_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions {
                BucketName = "bucket"
            };

            var result = subject.BucketName;

            result.Should().Be("bucket");
        }
Beispiel #29
0
        public void ChunkSizeBytes_set_should_throw_when_value_is_invalid(
            [Values(-1, 0)]
            int value)
        {
            var subject = new GridFSBucketOptions();

            Action action = () => subject.ChunkSizeBytes = value;

            action.ShouldThrow <ArgumentException>().And.ParamName.Should().Be("value");
        }
Beispiel #30
0
        public void WriteConcern_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions {
                WriteConcern = WriteConcern.WMajority
            };

            var result = subject.WriteConcern;

            result.Should().Be(WriteConcern.WMajority);
        }
        public MongoImageStore(IMongoDatabase database)
        {
            var db      = database ?? throw new System.ArgumentNullException(nameof(database));
            var options = new GridFSBucketOptions
            {
                BucketName = "productImages"
            };

            _bucket = new GridFSBucket(db, options);
        }
Beispiel #32
0
        public void SuppressEnsureIndexes_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions {
                SuppressEnsureIndexes = true
            };

            var result = subject.SuppressEnsureIndexes;

            result.Should().BeTrue();
        }
Beispiel #33
0
        public void ReadConcern_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions {
                ReadConcern = ReadConcern.Majority
            };

            var result = subject.ReadConcern;

            result.Should().Be(ReadConcern.Majority);
        }
Beispiel #34
0
        public void ReadPreference_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions {
                ReadPreference = ReadPreference.Secondary
            };

            var result = subject.ReadPreference;

            result.Should().Be(ReadPreference.Secondary);
        }
Beispiel #35
0
        // private methods
        private IGridFSBucket CreateBucket(int chunkSize)
        {
            var client            = DriverTestConfiguration.Client;
            var databaseNamespace = DriverTestConfiguration.DatabaseNamespace;
            var database          = client.GetDatabase(databaseNamespace.DatabaseName);
            var bucketOptions     = new GridFSBucketOptions {
                ChunkSizeBytes = chunkSize
            };

            return(new GridFSBucket(database, bucketOptions));
        }
Beispiel #36
0
        private IGridFSBucket getBucket(IMongoClient client)
        {
            var database = client.GetDatabase("file_storage");
            var options  = new GridFSBucketOptions
            {
                BucketName     = bucket_name,
                ChunkSizeBytes = 1048576,
            };

            return(new GridFSBucket(database, options));
        }
        public void constructor_should_initialize_instance()
        {
            var database = (new Mock<IMongoDatabase> { DefaultValue = DefaultValue.Mock }).Object;
            var options = new GridFSBucketOptions();

            var result = new GridFSBucket(database, options);

            result.Database.Should().BeSameAs(database);
            result.Options.BucketName.Should().Be(options.BucketName);
            result.Options.ChunkSizeBytes.Should().Be(options.ChunkSizeBytes);
            result.Options.ReadPreference.Should().Be(options.ReadPreference);
            result.Options.WriteConcern.Should().Be(options.WriteConcern);
        }
        public void constructor_should_initialize_instance()
        {
            var database = Substitute.For<IMongoDatabase>();
            var options = new GridFSBucketOptions();

            var result = new GridFSBucket(database, options);

            result.Database.Should().BeSameAs(database);
            result.Options.BucketName.Should().Be(options.BucketName);
            result.Options.ChunkSizeBytes.Should().Be(options.ChunkSizeBytes);
            result.Options.ReadPreference.Should().Be(options.ReadPreference);
            result.Options.WriteConcern.Should().Be(options.WriteConcern);
        }
        public void CreateCreateChunksCollectionIndexesOperation_should_return_expected_result(
            [Values(1, 2)]
            int databaseW,
            [Values(null, 1, 2)]
            int? bucketW)
        {
            var bucketWriteConcern = bucketW.HasValue ? new WriteConcern(bucketW.Value) : null;
            var options = new GridFSBucketOptions { WriteConcern = bucketWriteConcern };
            var subject = CreateSubject(options);
            var databaseWriteConcern = new WriteConcern(databaseW);
            var mockDatabase = Mock.Get(subject.Database);
            var databaseSettings = new MongoDatabaseSettings { WriteConcern = databaseWriteConcern };
            mockDatabase.SetupGet(d => d.Settings).Returns(databaseSettings);

            var result = subject.CreateCreateChunksCollectionIndexesOperation();

            result.CollectionNamespace.CollectionName.Should().Be("fs.chunks");
            result.MessageEncoderSettings.Should().NotBeNull();
            result.Requests.Should().NotBeNull();
            result.WriteConcern.Should().BeSameAs(bucketWriteConcern ?? databaseWriteConcern);
        }
        public void ToMutable_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions { BucketName = "bucket", ChunkSizeBytes = 123, ReadPreference = ReadPreference.Secondary, WriteConcern = WriteConcern.WMajority }.ToImmutable();

            var result = subject.ToMutable();

            result.BucketName.Should().Be(subject.BucketName);
            result.ChunkSizeBytes.Should().Be(subject.ChunkSizeBytes);
            result.ReadPreference.Should().Be(subject.ReadPreference);
            result.WriteConcern.Should().Be(subject.WriteConcern);
        }
 // private methods
 private IGridFSBucket CreateBucket(int chunkSize)
 {
     var client = DriverTestConfiguration.Client;
     var databaseNamespace = DriverTestConfiguration.DatabaseNamespace;
     var database = client.GetDatabase(databaseNamespace.DatabaseName);
     var bucketOptions = new GridFSBucketOptions { ChunkSizeBytes = chunkSize };
     return new GridFSBucket(database, bucketOptions);
 }
        public void constructor_with_mutable_other_should_initialize_instance()
        {
            var other = new GridFSBucketOptions { BucketName = "bucket", ChunkSizeBytes = 123, ReadConcern = ReadConcern.Majority, ReadPreference = ReadPreference.Secondary, WriteConcern = WriteConcern.WMajority };

            var result = new GridFSBucketOptions(other);

            result.BucketName.Should().Be(other.BucketName);
            result.ChunkSizeBytes.Should().Be(other.ChunkSizeBytes);
            result.ReadConcern.Should().Be(other.ReadConcern);
            result.ReadPreference.Should().Be(other.ReadPreference);
            result.WriteConcern.Should().Be(other.WriteConcern);
        }
        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>();
        }
        // private methods
        private GridFSBucket CreateSubject(GridFSBucketOptions options = null)
        {
            var cluster = new Mock<ICluster>().Object;

            var mockClient = new Mock<IMongoClient>();
            mockClient.SetupGet(c => c.Cluster).Returns(cluster);

            var mockDatabase = new Mock<IMongoDatabase>();
            mockDatabase.SetupGet(d => d.Client).Returns(mockClient.Object);
            mockDatabase.SetupGet(d => d.DatabaseNamespace).Returns(new DatabaseNamespace("database"));

            return new GridFSBucket(mockDatabase.Object, options);
        }
        // private methods
        private GridFSBucket CreateSubject(GridFSBucketOptions options = null)
        {
            var cluster = Substitute.For<ICluster>();

            var client = Substitute.For<IMongoClient>();
            client.Cluster.Returns(cluster);

            var database = Substitute.For<IMongoDatabase>();
            database.Client.Returns(client);

            return new GridFSBucket(database, options);
        }
        public void ReadConcern_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.ReadConcern = ReadConcern.Majority;

            subject.ReadConcern.Should().Be(ReadConcern.Majority);
        }
        public void ReadPreference_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.ReadPreference = ReadPreference.Secondary;

            subject.ReadPreference.Should().Be(ReadPreference.Secondary);
        }
        public void WriteConcern_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions { WriteConcern = WriteConcern.WMajority };

            var result = subject.WriteConcern;

            result.Should().Be(WriteConcern.WMajority);
        }
        public void WriteConcern_set_should_have_expected_result()
        {
            var subject = new GridFSBucketOptions();

            subject.WriteConcern = WriteConcern.WMajority;

            subject.WriteConcern.Should().Be(WriteConcern.WMajority);
        }
        public void constructor_with_arguments_should_initialize_instance()
        {
            var mutable = new GridFSBucketOptions { BucketName = "bucket", ChunkSizeBytes = 123, ReadConcern = ReadConcern.Majority, ReadPreference = ReadPreference.Secondary, WriteConcern = WriteConcern.WMajority };

            var result = new ImmutableGridFSBucketOptions(mutable);

            result.BucketName.Should().Be("bucket");
            result.ChunkSizeBytes.Should().Be(123);
            result.ReadConcern.Should().Be(ReadConcern.Majority);
            result.ReadPreference.Should().Be(ReadPreference.Secondary);
            result.WriteConcern.Should().Be(WriteConcern.WMajority);
        }
        public void constructor_with_no_arguments_should_initialize_instance_with_default_values()
        {
            var result = new GridFSBucketOptions();

            result.BucketName.Should().Be("fs");
            result.ChunkSizeBytes.Should().Be(255 * 1024);
            result.ReadConcern.Should().BeNull();
            result.ReadPreference.Should().BeNull();
            result.WriteConcern.Should().BeNull();
        }
        public void implicit_conversion_from_mutable_should_return_expected_result()
        {
            var mutable = new GridFSBucketOptions { BucketName = "bucket", ChunkSizeBytes = 123, ReadPreference = ReadPreference.Secondary, WriteConcern = WriteConcern.WMajority };

            var result = (ImmutableGridFSBucketOptions)mutable;

            result.BucketName.Should().Be(mutable.BucketName);
            result.ChunkSizeBytes.Should().Be(mutable.ChunkSizeBytes);
            result.ReadPreference.Should().Be(mutable.ReadPreference);
            result.WriteConcern.Should().Be(mutable.WriteConcern);
        }
        public void Options_get_should_return_the_expected_result()
        {
            var database = Substitute.For<IMongoDatabase>();
            var options = new GridFSBucketOptions();
            var subject = new GridFSBucket(database, options);

            var result = subject.Options;

            result.BucketName.Should().Be(options.BucketName);
            result.ChunkSizeBytes.Should().Be(options.ChunkSizeBytes);
            result.ReadPreference.Should().Be(options.ReadPreference);
            result.WriteConcern.Should().Be(options.WriteConcern);
        }
        public void CreateDropCollectionOperation_should_return_expected_result(
            [Values(1, 2)]
            int databaseW,
            [Values(null, 1, 2)]
            int? bucketW)
        {
            var bucketWriteConcern = bucketW.HasValue ? new WriteConcern(bucketW.Value) : null;
            var options = new GridFSBucketOptions { WriteConcern = bucketWriteConcern };
            var subject = CreateSubject(options);
            var databaseWriteConcern = new WriteConcern(databaseW);
            var mockDatabase = Mock.Get(subject.Database);
            var databaseSettings = new MongoDatabaseSettings { WriteConcern = databaseWriteConcern };
            mockDatabase.SetupGet(d => d.Settings).Returns(databaseSettings);
            var collectionNamespace = new CollectionNamespace(subject.Database.DatabaseNamespace, "collection");
            var messageEncoderSettings = new MessageEncoderSettings();

            var result = subject.CreateDropCollectionOperation(collectionNamespace, messageEncoderSettings);

            result.CollectionNamespace.Should().BeSameAs(collectionNamespace);
            result.MessageEncoderSettings.Should().BeSameAs(messageEncoderSettings);
            result.WriteConcern.Should().BeSameAs(bucketWriteConcern ?? databaseWriteConcern);
        }
        public void ReadConcern_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions { ReadConcern = ReadConcern.Majority };

            var result = subject.ReadConcern;

            result.Should().Be(ReadConcern.Majority);
        }
        public void ReadPreference_get_should_return_expected_result()
        {
            var subject = new GridFSBucketOptions { ReadPreference = ReadPreference.Secondary };

            var result = subject.ReadPreference;

            result.Should().Be(ReadPreference.Secondary);
        }
        public void ChunkSizeBytes_set_should_throw_when_value_is_invalid(
            [Values(-1, 0)]
            int value)
        {
            var subject = new GridFSBucketOptions();

            Action action = () => subject.ChunkSizeBytes = value;

            action.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("value");
        }
        public void Options_get_should_return_the_expected_result()
        {
            var database = (new Mock<IMongoDatabase> { DefaultValue = DefaultValue.Mock }).Object;
            var options = new GridFSBucketOptions();
            var subject = new GridFSBucket(database, options);

            var result = subject.Options;

            result.BucketName.Should().Be(options.BucketName);
            result.ChunkSizeBytes.Should().Be(options.ChunkSizeBytes);
            result.ReadConcern.Should().Be(options.ReadConcern);
            result.ReadPreference.Should().Be(options.ReadPreference);
            result.WriteConcern.Should().Be(options.WriteConcern);
        }