public void RegisterConventionPack_RegisterEqualConventionPacksTwoTimes_OneConventionPackRegistered()
        {
            // Arrange
            var mongoDatabaseBuilder = new MongoDatabaseBuilder(_mongoOptions);

            mongoDatabaseBuilder.RegisterConventionPack(
                "duplicateTestConventionPack", new ConventionPack
            {
                new DuplicateTestConvention1(),
                new DuplicateTestConvention2()
            }, t => true);

            mongoDatabaseBuilder.RegisterConventionPack(
                "duplicateTestConventionPack", new ConventionPack
            {
                new DuplicateTestConvention2(),
                new DuplicateTestConvention1()
            }, t => true);

            // Act
            MongoDbContextData result = mongoDatabaseBuilder.Build();

            // Assert
            IEnumerable <IConvention> conventions = ConventionRegistry
                                                    .Lookup(typeof(string)).Conventions;
            int duplicateTestConventionCount1 = conventions
                                                .Count(convention => convention.Name == nameof(DuplicateTestConvention1));
            int duplicateTestConventionCount2 = conventions
                                                .Count(convention => convention.Name == nameof(DuplicateTestConvention2));

            Assert.Equal(1, duplicateTestConventionCount1);
            Assert.Equal(1, duplicateTestConventionCount2);
        }
        public void RegisterConventionPack_RegisterUnequalConventionPacksTwoTimes_ThrowsException()
        {
            // Arrange
            var mongoDatabaseBuilder = new MongoDatabaseBuilder(_mongoOptions);

            mongoDatabaseBuilder.RegisterConventionPack(
                "unequalTestConventionPack", new ConventionPack
            {
                new DifferingTestConvention1(),
                new DifferingTestConvention2()
            }, t => true);

            mongoDatabaseBuilder.RegisterConventionPack(
                "unequalTestConventionPack", new ConventionPack
            {
                new DifferingTestConvention1(),
                new DifferingTestConvention2(),
                new DifferingTestConvention3()
            }, t => true);

            // Act
            Action differingRegistration = () => mongoDatabaseBuilder.Build();

            // Assert
            Assert.Throws <Exception>(differingRegistration);
        }
        public void RegisterConventionPack_NullConventionPackRegistered_ThrowsException()
        {
            // Arrange
            var mongoDatabaseBuilder = new MongoDatabaseBuilder(_mongoOptions);

            mongoDatabaseBuilder.RegisterConventionPack("nullConventionPack", null, t => true);

            // Act
            Action registrationAction = () => mongoDatabaseBuilder.Build();

            // Assert
            Assert.Throws <ArgumentNullException>(registrationAction);
        }
        public void RegisterConventionPack_RegisterOneSpecificConventionPackWithoutName_ThrowsException()
        {
            // Arrange
            var mongoDatabaseBuilder = new MongoDatabaseBuilder(_mongoOptions);

            mongoDatabaseBuilder.RegisterConventionPack(
                null, new ConventionPack
            {
                new EnumRepresentationConvention(BsonType.String),
                new CamelCaseElementNameConvention()
            }, t => true);

            // Act
            Action registrationAction = () => mongoDatabaseBuilder.Build();

            // Assert
            Assert.Throws <ArgumentNullException>(registrationAction);
        }
        public void RegisterConventionPack_RegisterOneSpecificConventionPack_RegisteredSuccessfully()
        {
            // Arrange
            var mongoDatabaseBuilder = new MongoDatabaseBuilder(_mongoOptions);

            mongoDatabaseBuilder.RegisterConventionPack(
                "camelCase", new ConventionPack
            {
                new EnumRepresentationConvention(BsonType.String),
                new CamelCaseElementNameConvention()
            }, t => true);

            // Act
            MongoDbContextData result = mongoDatabaseBuilder.Build();

            // Assert
            IEnumerable <IConvention> conventions = ConventionRegistry.Lookup(typeof(string)).Conventions;

            Assert.NotNull(conventions.OfType <EnumRepresentationConvention>().FirstOrDefault(c => c.Representation == BsonType.String));
            Assert.NotNull(conventions.OfType <CamelCaseElementNameConvention>().FirstOrDefault());
        }