コード例 #1
0
        public void ListTypeConverter_FromSource_Convert_ReturnsList()
        {
            var source = new[] { new User {
                                     Id = 1, Name = "Homer"
                                 }, new User {
                                     Id = 2, Name = "Marge"
                                 } };
            var mapper = new Mock <IMapper <User, UserView> >();

            mapper.Setup(m => m.Map(source[0])).Returns(new UserView {
                Id = 1, Name = "Homer"
            });
            mapper.Setup(m => m.Map(source[1])).Returns(new UserView {
                Id = 2, Name = "Marge"
            });
            var mappingFactory = new Mock <IMappingFactory>();

            mappingFactory.Setup(f => f.Create <User, UserView>()).Returns(mapper.Object);
            var converter = new ListTypeConverter <User, UserView> {
                MappingFactory = mappingFactory.Object
            };

            var target = converter.Convert(source.ToList()).ToList();

            target[0].Id.ShouldBe(1);
            target[0].Name.ShouldBe("Homer");
            target[1].Id.ShouldBe(2);
            target[1].Name.ShouldBe("Marge");
        }
コード例 #2
0
        public void ListTypeConverter_EmptySource_Convert_ReturnsNull()
        {
            var converter = new ListTypeConverter <User, UserView>();

            var target = converter.Convert(new List <User>(0));

            target.ShouldBeNull();
        }
コード例 #3
0
        public void ListTypeConverter_UnknownTarget_Convert_ReturnsNull()
        {
            var mappingFactory = new Mock <IMappingFactory>();

            mappingFactory.Setup(f => f.Create <User, UserView>()).Returns((IMapper <User, UserView>)null);
            var converter = new ListTypeConverter <User, UserView> {
                MappingFactory = mappingFactory.Object
            };

            var target = converter.Convert(new[] { new User() }.ToList());

            target.ShouldBeNull();
        }