Exemple #1
0
        public void MissingSourceProperties()
        {
            var obj1 = new DataObject3
            {
                Hello  = "Hello",
                Value1 = TestContext.CurrentContext.Random.GetString(50),
            };

            var obj2 = new DataObject2();

            ReflectionUtilities.CopyProperties(obj1, obj2);

            Assert.AreEqual(obj1.Hello, obj2.Hello);
            Assert.AreEqual(obj1.Value1, obj2.Value1);
            Assert.AreEqual(default(string), obj2.Value2);
        }
Exemple #2
0
        public void SameProperties()
        {
            var obj1 = new DataObject1
            {
                Hello  = "Hello",
                Value1 = TestContext.CurrentContext.Random.GetString(50),
                Value2 = TestContext.CurrentContext.Random.GetString(50)
            };

            var obj2 = new DataObject2();

            ReflectionUtilities.CopyProperties(obj1, obj2);

            Assert.AreEqual(obj1.Hello, obj2.Hello);
            Assert.AreEqual(obj1.Value1, obj2.Value1);
            Assert.AreEqual(obj1.Value2, obj2.Value2);
        }
Exemple #3
0
        public void PropertyMapping()
        {
            var obj1 = new DataObject1
            {
                Hello  = "Hello",
                Value1 = TestContext.CurrentContext.Random.GetString(50),
                Value2 = TestContext.CurrentContext.Random.GetString(50)
            };

            var obj2     = new DataObject2();
            var settings = new CopySettings();

            settings.PropertyMapping.Add(nameof(DataObject1.Value1), nameof(DataObject2.Value2));
            settings.PropertyMapping.Add(nameof(DataObject1.Value2), nameof(DataObject2.Value1));

            ReflectionUtilities.CopyProperties(obj1, obj2, settings);

            Assert.AreEqual(obj1.Hello, obj2.Hello);
            Assert.AreEqual(obj1.Value2, obj2.Value1);
            Assert.AreEqual(obj1.Value1, obj2.Value2);
        }
Exemple #4
0
 public DataObject(int id, string value, DataObject2 o)
 {
     Id     = id;
     Value  = value;
     Object = o;
 }