Example #1
0
            public object Map(object from, object to, TContext context)
            {
                if (to == null)
                {
                    to = _constructor();
                }

                var toList = (IList)to;

                toList.Clear();

                MapperUtils.CopyToList((IEnumerable)from, toList, _typeMapper, context);

                return(to);
            }
Example #2
0
        public void CopyToList_CallsMapperWithContext_NullEntries()
        {
            var context = new object();
            var mapper  = new Mock <IMap <object> >();

            mapper.Setup(
                c => c.MapObject(It.IsAny <object>(), It.IsAny <object>(), It.IsAny <object>()))
            .Returns <object, object, object>((from, to, ctx) => from == null ? null : from.ToString());
            var destinationList = new List <string>();

            MapperUtils.CopyToList(new int?[] { 1, null, 3 }, destinationList, mapper.Object, context);

            mapper.Verify(c => c.MapObject(1, It.IsAny <object>(), context));
            mapper.Verify(c => c.MapObject(null, It.IsAny <object>(), context), Times.Never());
            mapper.Verify(c => c.MapObject(3, It.IsAny <object>(), context));
            Assert.AreEqual(new [] { "1", null, "3" }, destinationList.ToArray());
        }