Beispiel #1
0
        public void ObjectMapper_FillObject_1_Items()
        {
            var dataTable = new DataTable("ObjectTable");

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Columns.Add("StringProp", typeof(string));
            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp", typeof(Array));
            dataTable.Columns.Add("BitProp", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp", typeof(decimal));
            dataTable.Columns.Add("GuidProp", typeof(Guid));
            dataTable.Columns.Add("EnumProp", typeof(int));

            var bytearray = Encoding.ASCII.GetBytes("Hello This is test");
            var guid      = new Guid("e3b16c58-5737-410f-9548-227b9b34cf68");
            var enumValue = (int)TestObject.TestEnum.Two;

            dataTable.Rows.Add(
                10,
                "string",
                DateTime.Today,
                bytearray,
                bytearray,
                true,
                12.99m,
                guid,
                enumValue
                );


            TestObject result = null;

            Measure("FillObject Single Item", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.AreEqual(10, result.IntProp);
            Assert.AreEqual("string", result.StringProp);
            Assert.AreEqual(DateTime.Today, result.DateTimeProp);
            Assert.AreEqual(bytearray, result.ByteArrayProp);
            Assert.AreEqual(bytearray, result.ArrayProp);
            Assert.AreEqual(true, result.BitProp);
            Assert.AreEqual(12.99m, result.DecimalProp);
            Assert.AreEqual(new Guid("e3b16c58-5737-410f-9548-227b9b34cf68"), result.GuidProp);
        }
Beispiel #2
0
        public void ObjectMapper_FillObject_binary_to_Array()
        {
            var dataTable = new DataTable("ObjectTable");
            var colValue  = Encoding.ASCII.GetBytes("Hello This is test");

            dataTable.Columns.Add("ArrayProp", typeof(byte[]));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject Binary to Array", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(colValue, result.ArrayProp);
        }
Beispiel #3
0
        public void ObjectMapper_FillObject_datetime()
        {
            var dataTable = new DataTable("ObjectTable");
            var colValue  = new DateTime(2010, 12, 11, 10, 9, 8);

            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject DateTime", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(colValue, result.DateTimeProp);
        }
Beispiel #4
0
        public void ObjectMapper_FillObject_string()
        {
            var dataTable = new DataTable("ObjectTable");
            var colValue  = Guid.NewGuid().ToString();

            dataTable.Columns.Add("StringProp", typeof(String));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject String", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(colValue, result.StringProp);
        }
Beispiel #5
0
        public void ObjectMapper_FillObject_enum()
        {
            var dataTable = new DataTable("ObjectTable");
            int colValue  = (int)TestObject.TestEnum.Two;

            dataTable.Columns.Add("EnumProp", typeof(int));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject Enum", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(TestObject.TestEnum.Two, result.EnumProp);
        }
Beispiel #6
0
        public void ObjectMapper_FillObject_guid()
        {
            var  dataTable = new DataTable("ObjectTable");
            Guid colValue  = new Guid("e3b16c58-5737-410f-9548-227b9b34cf68");

            dataTable.Columns.Add("GuidProp", typeof(Guid));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject Guid", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(colValue, result.GuidProp);
        }
Beispiel #7
0
        public void ObjectMapper_FillObject_int_to_boolean_false()
        {
            var     dataTable = new DataTable("ObjectTable");
            decimal colValue  = 0;

            dataTable.Columns.Add("BitProp", typeof(int));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject Into to Bool True", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(false, result.BitProp);
        }
Beispiel #8
0
        public void ObjectMapper_FillObject_int()
        {
            var dataTable = new DataTable("ObjectTable");
            var colValue  = 12;

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject Int", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(colValue, result.IntProp);
        }
Beispiel #9
0
        public void ObjectMapper_FillObject_decimal()
        {
            var     dataTable = new DataTable("ObjectTable");
            decimal colValue  = 12.99m;

            dataTable.Columns.Add("DecimalProp", typeof(decimal));
            dataTable.Rows.Add(colValue);

            TestObject result = null;

            Measure("FillObject Decimal", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable);
            });

            Assert.IsNotNull(result);
            Assert.AreEqual(colValue, result.DecimalProp);
        }
Beispiel #10
0
        public void ObjectMapper_FillObject_CallbackTest()
        {
            var dataTable = new DataTable("ObjectTable");

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Columns.Add("StringProp", typeof(string));
            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp", typeof(Array));
            dataTable.Columns.Add("BitProp", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp", typeof(decimal));

            var bytearray = Encoding.ASCII.GetBytes("Hello This is test");

            dataTable.Rows.Add(
                10,
                "string",
                DateTime.Today,
                bytearray,
                bytearray,
                true,
                12.99m
                );

            TestObject result = null;

            Measure("FillObject Single Item with Callback", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable, (T) =>
                {
                    T.StringProp = "blah";
                });
            });

            Assert.AreEqual(10, result.IntProp);
            Assert.AreEqual("blah", result.StringProp);
            Assert.AreEqual(DateTime.Today, result.DateTimeProp);
            Assert.AreEqual(bytearray, result.ByteArrayProp);
            Assert.AreEqual(bytearray, result.ArrayProp);
            Assert.AreEqual(true, result.BitProp);
            Assert.AreEqual(12.99m, result.DecimalProp);
        }
Beispiel #11
0
        public void ObjectMapper_FillObject_1_Existing_Items_With_Overwrite()
        {
            var dataTable = new DataTable("ObjectTable");

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Columns.Add("StringProp", typeof(string));
            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp", typeof(Array));
            dataTable.Columns.Add("BitProp", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp", typeof(decimal));

            var bytearray = Encoding.ASCII.GetBytes("Hello This is test");

            dataTable.Rows.Add(
                10,
                "string",
                DateTime.Today,
                bytearray,
                bytearray,
                true,
                12.99m
                );

            TestObject result = null;

            Measure("FillObject Single Existing Item with Overwrite", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable, new TestObject {
                    IntProp = 1, StringProp = "Overwrite Me!", DateTimeProp = DateTime.Today.AddDays(-1)
                }, true);
            });

            Assert.AreEqual(10, result.IntProp);
            Assert.AreEqual("string", result.StringProp);
            Assert.AreEqual(DateTime.Today, result.DateTimeProp);
            Assert.AreEqual(bytearray, result.ByteArrayProp);
            Assert.AreEqual(bytearray, result.ArrayProp);
            Assert.AreEqual(true, result.BitProp);
            Assert.AreEqual(12.99m, result.DecimalProp);
        }
Beispiel #12
0
        public void ObjectMapper_FillObject_1_Existing_Items_With_Callback()
        {
            var dataTable = new DataTable("ObjectTable");

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Columns.Add("StringProp", typeof(string));
            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp", typeof(Array));
            dataTable.Columns.Add("BitProp", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp", typeof(decimal));

            var bytearray         = Encoding.ASCII.GetBytes("Hello This is test");
            var modifiedByteArray = Encoding.ASCII.GetBytes("Modified byte array");

            dataTable.Rows.Add(
                10,
                "string",
                DateTime.Today,
                bytearray,
                bytearray,
                true,
                12.99m
                );

            TestObject result = null;

            Measure("FillObject Single Existing Item with Callback", 500, () =>
            {
                result = ObjectMapper.FillObject <TestObject>(dataTable, new TestObject(), false, (T) => { T.ModifyItems(); });
            });

            Assert.AreEqual(1, result.IntProp);
            Assert.AreEqual("blah", result.StringProp);
            Assert.AreEqual(new DateTime(2015, 1, 1), result.DateTimeProp);
            Assert.AreEqual(modifiedByteArray, result.ByteArrayProp);
            Assert.AreEqual(modifiedByteArray, result.ArrayProp);
            Assert.AreEqual(false, result.BitProp);
            Assert.AreEqual(9.99m, result.DecimalProp);
        }