コード例 #1
0
        public void CoreTestFillMapPolymorph()
        {
            var source = PolymorphicSubClass.Create(5);
            var manual = new DTO.PolymorphicSubClass(source);

            var dto = new DTO.PolymorphicSubClass();

            Mapper.Fill(source, dto);
            Assert.Equal(dto, manual);

            dto = new DTO.PolymorphicSubClass();
            Mapper.Fill <PolymorphicBaseClass, DTO.PolymorphicBaseClass>(source, dto);
            Assert.Equal(dto, manual);

            dto = new DTO.PolymorphicSubClass();
            Mapper.Fill <PolymorphicBaseClass, object>(source, dto);
            Assert.Equal(dto, manual);

            var dto2 = new DTO.PolymorphicBaseClass();

            Mapper.Fill <PolymorphicBaseClass, object>(source, dto2);
            var manual2 = new DTO.PolymorphicBaseClass
            {
                Id = source.Id,
                // AString is still filled according to the subclass mapping
                AString = source.AString.ToUpper()
            };

            Assert.Equal(dto2, manual2);

            var dto3 = new DTO.PolymorphicSubSubClass();

            Mapper.Fill(source, dto3);
            dto = new DTO.PolymorphicSubClass()
            {
                Id = dto3.Id, AString = dto3.AString, Name = dto3.Name
            };
            Assert.Equal(dto, manual);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Init.InitHMapper();
            Init.InitAutomapper();
            Init.InitExpressMapper();

            var test = AutoMapper.Mapper.Map <PolymorphicSubClass, DTO.PolymorphicSubClass>(PolymorphicSubClass.Create(5));

            Run("Very simple class", VerySimpleClass.CreateMany(300000), x => new DTO.VerySimpleClass(x));
            Run("Simple class", SimpleClass.CreateMany(40000), x => new DTO.SimpleClass(x));
            Run("Simple set", SimpleSet.CreateMany(10000, 100), x => new DTO.SimpleSet(x));
            Run("Multiple set", MultipleSets.CreateMany(1000, 100), x => new DTO.MultipleSets(x));
            Run("Dictionary", DictionarySet.CreateMany(300, 100), x => new DTO.DictionarySet(x));

            Run("Simple generic class of int", SimpleGeneric <int> .CreateMany(Enumerable.Range(1, 300000).Select(i => i).ToArray()), x => new DTO.SimpleGeneric <int>(x));
            Run("Mapped object generic class", MappedObjectGeneric <VerySimpleClass> .CreateMany(VerySimpleClass.CreateMany(200000)), x => new DTO.MappedObjectGeneric <DTO.VerySimpleClass>(x));
            Run("Multiple generic class", MultipleGenerics <int, string> .CreateMany(Enumerable.Range(1, 200000).Select(i => Tuple.Create(i, Guid.NewGuid().ToString())).ToArray()), x => new DTO.MultipleGenerics <string, int>(x));
            Run("Polymorphic class", PolymorphicSubSubClass.CreateMany(300000), x => new DTO.PolymorphicSubClass(x));
            Run("Set of polymorphic class", SetOfPolymorphic.CreateMany(150000), x => new DTO.SetOfPolymorphic(x));
            Run("Generic of polymorphic class", MappedObjectGeneric <PolymorphicBaseClass> .CreateMany(PolymorphicBaseClass.CreateMany(200000)), x => new DTO.MappedObjectGeneric <DTO.PolymorphicBaseClass>(x));
            Run("Set of generic polymorphic classes", SetOfGenericPolymorph.CreateMany(50000), x => new DTO.SetOfGenericPolymorph(x));
        }