public void GetCollection_GetNotExistingCollection_ReturnsNewCollection()
        {
            // Arrange
            IMongoCollection <Foo> mongoCollectionFoo =
                _mongoDatabase.GetCollection <Foo>(nameof(Foo));
            IMongoCollection <Bar> mongoCollectionBar =
                _mongoDatabase.GetCollection <Bar>(nameof(Bar));

            IMongoCollections mongoCollections = new MongoCollections();

            mongoCollections.Add(mongoCollectionFoo);

            MongoDbContextData mongoDbContextData = new MongoDbContextData(
                _mongoDatabase.Client,
                _mongoDatabase,
                mongoCollections);

            // Act
            IMongoCollection <Bar> collection = mongoDbContextData.GetCollection <Bar>();

            // Assert
            Assert.NotNull(collection);
            Assert.NotSame(mongoCollectionBar, collection);
            Assert.Equal("Bar", collection.CollectionNamespace.CollectionName);
        }
        public void ConfigureCollection_SetDifferentSettingsToCollection_CollectionConfiguredSuccessfully()
        {
            // Arrange
            var mongoDatabaseBuilder = new MongoDatabaseBuilder(_mongoOptions);

            // Act
            mongoDatabaseBuilder.ConfigureCollection(new FooCollectionConfiguration());
            MongoDbContextData result = mongoDatabaseBuilder.Build();

            // Assert
            IMongoCollection <Foo> collection = result.GetCollection <Foo>();

            IEnumerable <BsonClassMap> classMaps = BsonClassMap.GetRegisteredClassMaps();

            Snapshot.Match(new
            {
                CollectionName = collection.CollectionNamespace.CollectionName,
                Settings       = collection.Settings,
                Indexes        = collection.Indexes.List().ToList(),
                ClassMaps      = classMaps.Select(map => new {
                    Name        = map.Discriminator,
                    IdMemberMap = new {
                        map.IdMemberMap?.ElementName,
                        map.IdMemberMap?.MemberName
                    },
                    AllMemberMaps = map.AllMemberMaps.Select(amm =>
                                                             new { amm.ElementName, amm.MemberName }),
                    IgnoreExtraElements = map.IgnoreExtraElements
                })
            });
        }
        public void GetCollection_GetNotExistingCollectionTwice_ReturnsSameCollection()
        {
            // Arrange
            IMongoCollections mongoCollections = new MongoCollections();

            MongoDbContextData mongoDbContextData = new MongoDbContextData(
                _mongoDatabase.Client,
                _mongoDatabase,
                mongoCollections);

            // Act
            IMongoCollection <Bar> collection1 = mongoDbContextData.GetCollection <Bar>();
            IMongoCollection <Bar> collection2 = mongoDbContextData.GetCollection <Bar>();

            // Assert
            Assert.NotNull(collection1);
            Assert.Same(collection1, collection2);
        }
        public void GetCollection_GetBarCollection_ReturnsRightCollection()
        {
            // Arrange
            IMongoCollection <Foo> mongoCollectionFoo =
                _mongoDatabase.GetCollection <Foo>(nameof(Foo));
            IMongoCollection <Bar> mongoCollectionBar =
                _mongoDatabase.GetCollection <Bar>(nameof(Bar));

            IMongoCollections mongoCollections = new MongoCollections();

            mongoCollections.Add(mongoCollectionFoo);
            mongoCollections.Add(mongoCollectionBar);

            MongoDbContextData mongoDbContextData = new MongoDbContextData(
                _mongoDatabase.Client,
                _mongoDatabase,
                mongoCollections);

            // Act
            IMongoCollection <Bar> collection = mongoDbContextData.GetCollection <Bar>();

            // Assert
            Assert.Same(mongoCollectionBar, collection);
        }