public void TestMapObjWithConstructor()
        {
            Mapper <Student, PersonWithConstructor> m = AutoMapper.AutoMapper.Build <Student, PersonWithConstructor>().CreateMapper();
            Student s = new Student {
                Nr = 39393, Name = "Edgar Demétrio", Origin = true
            };
            PersonWithConstructor expected = new PersonWithConstructor(null)
            {
                Nr = 39393, Name = "Edgar Demétrio", Origin = true
            };
            PersonWithConstructor actual = m.Map(s);

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void ProtoBufTestWithPersonConstructor()
        {
            var newPerson = new PersonWithConstructor();

            newPerson.Name    = "Harry";
            newPerson.Age     = 99;
            newPerson.Hobbies = new List <string>();

            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, newPerson);

                ms.Flush();
                ms.Position = 0;

                var deserializePerson = Serializer.Deserialize <PersonWithConstructor>(ms);

                Assert.IsTrue(deserializePerson.Name == "Harry");
                Assert.IsNotNull(deserializePerson.Hobbies); // Is not null because we initialized the list on our constructor
            }
        }