public void TestConvention(BsonType value)
        {
            var convention           = new EnumRepresentationConvention(value);
            var classMap             = new BsonClassMap <TestClass>();
            var nonEnumMemberMap     = classMap.MapMember(x => x.NonEnum);
            var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum);
            var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum);

            convention.Apply(nonEnumMemberMap);
            convention.Apply(changedEnumMemberMap);
            Assert.AreEqual(value, ((IRepresentationConfigurable)(changedEnumMemberMap.GetSerializer())).Representation);
        }
        public void TestConvention(BsonType value)
        {
            var convention           = new EnumRepresentationConvention(value);
            var classMap             = new BsonClassMap <TestClass>();
            var nonEnumMemberMap     = classMap.MapMember(x => x.NonEnum);
            var defaultEnumMemberMap = classMap.MapMember(x => x.DefaultEnum);
            var changedEnumMemberMap = classMap.MapMember(x => x.ChangedRepresentationEnum);

            convention.Apply(nonEnumMemberMap);
            convention.Apply(changedEnumMemberMap);
            Assert.IsNull(nonEnumMemberMap.SerializationOptions);
            Assert.IsNull(defaultEnumMemberMap.SerializationOptions);
            Assert.AreEqual(value, ((RepresentationSerializationOptions)changedEnumMemberMap.SerializationOptions).Representation);
        }
        public void Apply_should_do_nothing_when_member_is_not_an_enum()
        {
            var subject    = new EnumRepresentationConvention(BsonType.String);
            var memberMap  = CreateMemberMap(c => c.I);
            var serializer = memberMap.GetSerializer();

            subject.Apply(memberMap);

            memberMap.GetSerializer().Should().BeSameAs(serializer);
        }
        public void TestConventionOverride()
        {
            var int64Convention = new EnumRepresentationConvention(BsonType.Int64);
            var strConvention   = new EnumRepresentationConvention(BsonType.String);
            var classMap        = new BsonClassMap <TestClass>();
            var memberMap       = classMap.MapMember(x => x.ChangedRepresentationEnum);

            int64Convention.Apply(memberMap);
            strConvention.Apply(memberMap);
            Assert.AreEqual(BsonType.String, ((RepresentationSerializationOptions)memberMap.SerializationOptions).Representation);
        }
        public void Apply_should_configure_serializer_when_member_is_an_enum(BsonType representation)
        {
            var subject   = new EnumRepresentationConvention(representation);
            var memberMap = CreateMemberMap(c => c.E);

            subject.Apply(memberMap);

            var serializer = (EnumSerializer <E>)memberMap.GetSerializer();

            serializer.Representation.Should().Be(representation);
        }
        public void TestConventionOverride()
        {
            var int64Convention = new EnumRepresentationConvention(BsonType.Int64);
            var strConvention   = new EnumRepresentationConvention(BsonType.String);
            var classMap        = new BsonClassMap <TestClass>();
            var memberMap       = classMap.MapMember(x => x.ChangedRepresentationEnum);

            int64Convention.Apply(memberMap);
            strConvention.Apply(memberMap);
            Assert.Equal(BsonType.String, ((IRepresentationConfigurable)(memberMap.GetSerializer())).Representation);
        }