예제 #1
0
        public void Mapping_object_with_non_null_collection_to_object_with_null_collection_creates_list()
        {
            var source = new SourceClassWithCollection();
            source.Children = new[] { new SourceChild1 { ChildId = 1 }, new SourceChild1 { ChildId = 2 } };

            var target = new TargetClassWithCollection();
            target.Children = null;

            _mapper.Map(source, target);

            Assert.AreEqual("string value 1", target.StringProperty1);
            Assert.AreEqual(2, target.Children.Count);
            Assert.AreEqual(1, target.Children[0].ChildId);
            Assert.AreEqual(2, target.Children[1].ChildId);
        }
예제 #2
0
        public void Items_in_matching_collection_are_mapped_to_new_instances_and_added_to_the_target_collection()
        {
            var source = new SourceClassWithCollection();
            source.Children = new[] { new SourceChild1 { ChildId = 1 }, new SourceChild1 { ChildId = 2 } };

            var target = _mapper.Map<TargetClassWithCollection>(source);

            Assert.AreEqual("string value 1", target.StringProperty1);
            Assert.AreEqual(2, target.Children.Count);
            Assert.AreEqual(1, target.Children[0].ChildId);
            Assert.AreEqual(2, target.Children[1].ChildId);
        }