예제 #1
0
        public void Should_not_serialize_empty_enumerables()
        {
            var           bsonClassMap  = new BsonClassMap <ComplexSubDocument>();
            BsonMemberMap bsonMemberMap = bsonClassMap.MapMember(cr => cr.ComplexValueList);
            var           ignoreEmptyEnumerableConvention = new IgnoreEmptyEnumerablesConvention();

            ignoreEmptyEnumerableConvention.Apply(bsonMemberMap);
            var complexSubDocument = new ComplexSubDocument();

            complexSubDocument.ComplexValueList.Clear();
            Assert.False(bsonMemberMap.ShouldSerialize(complexSubDocument, complexSubDocument.ComplexValueList));
        }
예제 #2
0
        public void Should_serialize_non_empty_enumerables()
        {
            var           bsonClassMap  = new BsonClassMap <ComplexSubDocument>();
            BsonMemberMap bsonMemberMap = bsonClassMap.MapMember(cr => cr.ComplexValueList);
            var           ignoreEmptyEnumerableConvention = new IgnoreEmptyEnumerablesConvention();

            ignoreEmptyEnumerableConvention.Apply(bsonMemberMap);
            var complexSubDocument = new ComplexSubDocument
            {
                ComplexValueList =
                {
                    new ComplexType(),
                    new ComplexType(),
                    new ComplexType()
                }
            };

            Assert.True(bsonMemberMap.ShouldSerialize(complexSubDocument, complexSubDocument.ComplexValueList));
        }