Example #1
0
        public void Mapper_Map_ObjectsNoActions_ShouldMapCorrectly()
        {
            var fieldAndPropertyMapper = new FieldAndPropertyMapper();

            fieldAndPropertyMapper.Clear();
            fieldAndPropertyMapper.AddMap <Parent, Child>();
            var parent = new Parent
            {
                Id      = 100,
                Name    = "name",
                Surname = "surname"
            };
            var child = new Child
            {
                Name = "child",
                Id   = "1"
            };

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            fieldAndPropertyMapper.Map(parent, child);
            //---------------Test Result -----------------------
            Assert.AreEqual(100, parent.Id);
            Assert.AreNotEqual(parent.Id.ToString(), child.Id);
            Assert.AreEqual(parent.Name, child.Name);
            Assert.AreEqual(parent.Surname, child.Surname);
        }
Example #2
0
        public void Mapper_Map_GivenObjects_ShouldMapCorrectly()
        {
            var fieldAndPropertyMapper = new FieldAndPropertyMapper();

            fieldAndPropertyMapper.Clear();
            fieldAndPropertyMapper.AddMap <Parent, Child>((parent1, child1) =>
            {
                child1.ParentId = parent1.Id;
            });
            var parent = new Parent
            {
                Id      = 100,
                Name    = "name",
                Surname = "surname"
            };
            var child = new Child
            {
                Name = "child",
                Id   = "1"
            };

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            fieldAndPropertyMapper.Map(parent, child);
            //---------------Test Result -----------------------
            Assert.AreEqual(100, parent.Id);
            Assert.AreEqual(100, child.ParentId);
        }
Example #3
0
        public void Mapper_Map_TMapTo_IsNotNull_ExpectNoArgumentNullException()
        {
            var fieldAndPropertyMapper = new FieldAndPropertyMapper();

            //---------------Set up test pack-------------------
            fieldAndPropertyMapper.Clear();
            fieldAndPropertyMapper.AddMap <Parent, Child>();
            var parent = new Parent
            {
                Id      = 100,
                Name    = "name",
                Surname = "surname"
            };
            var child = new Child
            {
                Name = "child",
                Id   = "1"
            };

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            fieldAndPropertyMapper.Map <Parent, Child>(parent, child);
            //---------------Test Result -----------------------
            Assert.AreEqual(100, parent.Id);
            Assert.AreNotEqual(parent.Id.ToString(), child.Id);
            Assert.AreEqual(parent.Name, child.Name);
            Assert.AreEqual(parent.Surname, child.Surname);
        }
Example #4
0
        public void Mapper_Map_TMapTo_IsNotNull_ExpectArgumentNullException()
        {
            var fieldAndPropertyMapper = new FieldAndPropertyMapper();

            fieldAndPropertyMapper.Clear();
            fieldAndPropertyMapper.AddMap <Parent, Child>();
            var child = new Child
            {
                Name = "child",
                Id   = "1"
            };

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            //---------------Test Result -----------------------
            Assert.ThrowsException <ArgumentNullException>(() => fieldAndPropertyMapper.Map(default(Parent), child));
        }
Example #5
0
        public void Mapper_Map_TMapTo_IsNull_ExpectNoArgumentNullException()
        {
            var fieldAndPropertyMapper = new FieldAndPropertyMapper();

            //---------------Set up test pack-------------------
            fieldAndPropertyMapper.Clear();
            fieldAndPropertyMapper.AddMap <Parent, Child>();
            var parent = new Parent
            {
                Id      = 100,
                Name    = "name",
                Surname = "surname"
            };

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            fieldAndPropertyMapper.Map <Parent, Child>(parent, null);
            //---------------Test Result -----------------------
            Assert.AreEqual(100, parent.Id);
        }