public void Test_Class_with_Built_in_Types() { var obj1 = new { Property1 = "value1", Property2 = "2" }; var obj2 = new AllBuiltInTypes { ByteType = byte.MaxValue, SByteType = sbyte.MaxValue, Int32Type = int.MaxValue, UInt32Type = uint.MaxValue, Int16Type = short.MaxValue, UInt16Type = ushort.MaxValue, Int64Type = long.MaxValue, UInt64Type = ulong.MaxValue, SingleType = float.MaxValue, DoubleType = double.MaxValue, DecimalType = 300.5m, BooleanType = false, CharType = '\x0058', ObjectType = new { Test = 1 }, StringType = "foo", DateTimeType = DateTime.Now, EnumType = TestEnum.Val1 }; var result1 = Merger.Merge(obj1, obj2); Assert.AreEqual(19, result1.GetType().GetProperties().Length); Assert.AreEqual(obj1.Property1, result1.GetType().GetProperty("Property1").GetValue(result1)); Assert.AreEqual(obj1.Property2, result1.GetType().GetProperty("Property2").GetValue(result1)); Assert.AreEqual(obj2.ByteType, result1.GetType().GetProperty("ByteType").GetValue(result1)); Assert.AreEqual(obj2.SByteType, result1.GetType().GetProperty("SByteType").GetValue(result1)); Assert.AreEqual(obj2.Int32Type, result1.GetType().GetProperty("Int32Type").GetValue(result1)); Assert.AreEqual(obj2.UInt32Type, result1.GetType().GetProperty("UInt32Type").GetValue(result1)); Assert.AreEqual(obj2.Int16Type, result1.GetType().GetProperty("Int16Type").GetValue(result1)); Assert.AreEqual(obj2.UInt16Type, result1.GetType().GetProperty("UInt16Type").GetValue(result1)); Assert.AreEqual(obj2.Int64Type, result1.GetType().GetProperty("Int64Type").GetValue(result1)); Assert.AreEqual(obj2.UInt64Type, result1.GetType().GetProperty("UInt64Type").GetValue(result1)); Assert.AreEqual(obj2.SingleType, result1.GetType().GetProperty("SingleType").GetValue(result1)); Assert.AreEqual(obj2.DoubleType, result1.GetType().GetProperty("DoubleType").GetValue(result1)); Assert.AreEqual(obj2.DecimalType, result1.GetType().GetProperty("DecimalType").GetValue(result1)); Assert.AreEqual(obj2.BooleanType, result1.GetType().GetProperty("BooleanType").GetValue(result1)); Assert.AreEqual(obj2.CharType, result1.GetType().GetProperty("CharType").GetValue(result1)); Assert.AreEqual(obj2.ObjectType, result1.GetType().GetProperty("ObjectType").GetValue(result1)); Assert.AreEqual(obj2.SingleType, result1.GetType().GetProperty("SingleType").GetValue(result1)); Assert.AreEqual(obj2.DateTimeType, result1.GetType().GetProperty("DateTimeType").GetValue(result1)); Assert.AreEqual(TestEnum.Val1, result1.GetType().GetProperty("EnumType").GetValue(result1)); }
public void Test_Class_with_Built_in_Types() { var obj1 = new { Property1 = "value1", Property2 = "2" }; var obj2 = new AllBuiltInTypes { ByteType = Byte.MaxValue, SByteType = SByte.MaxValue, Int32Type = Int32.MaxValue, UInt32Type = UInt32.MaxValue, Int16Type = Int16.MaxValue, UInt16Type = UInt16.MaxValue, Int64Type = Int64.MaxValue, UInt64Type = UInt64.MaxValue, SingleType = Single.MaxValue, DoubleType = Double.MaxValue, DecimalType = 300.5m, BooleanType = false, CharType = '\x0058', ObjectType = new { Test = 1 }, StringType = "foo", DateTimeType = DateTime.Now, EnumType = TestEnum.Val1 }; var result1 = TypeMerger.Merge(obj1, obj2); result1.GetType().GetProperties().Length.Should().Be(19); result1.GetType().GetProperty("Property1").GetValue(result1).Should().Be(obj1.Property1); result1.GetType().GetProperty("Property2").GetValue(result1).Should().Be(obj1.Property2); result1.GetType().GetProperty("ByteType").GetValue(result1).Should().Be(obj2.ByteType); result1.GetType().GetProperty("SByteType").GetValue(result1).Should().Be(obj2.SByteType); result1.GetType().GetProperty("Int32Type").GetValue(result1).Should().Be(obj2.Int32Type); result1.GetType().GetProperty("UInt32Type").GetValue(result1).Should().Be(obj2.UInt32Type); result1.GetType().GetProperty("Int16Type").GetValue(result1).Should().Be(obj2.Int16Type); result1.GetType().GetProperty("UInt16Type").GetValue(result1).Should().Be(obj2.UInt16Type); result1.GetType().GetProperty("Int64Type").GetValue(result1).Should().Be(obj2.Int64Type); result1.GetType().GetProperty("UInt64Type").GetValue(result1).Should().Be(obj2.UInt64Type); result1.GetType().GetProperty("SingleType").GetValue(result1).Should().Be(obj2.SingleType); result1.GetType().GetProperty("DoubleType").GetValue(result1).Should().Be(obj2.DoubleType); result1.GetType().GetProperty("DecimalType").GetValue(result1).Should().Be(obj2.DecimalType); result1.GetType().GetProperty("BooleanType").GetValue(result1).Should().Be(obj2.BooleanType); result1.GetType().GetProperty("CharType").GetValue(result1).Should().Be(obj2.CharType); result1.GetType().GetProperty("ObjectType").GetValue(result1).Should().Be(obj2.ObjectType); result1.GetType().GetProperty("SingleType").GetValue(result1).Should().Be(obj2.SingleType); result1.GetType().GetProperty("DateTimeType").GetValue(result1).Should().Be(obj2.DateTimeType); result1.GetType().GetProperty("EnumType").GetValue(result1).Should().Be(TestEnum.Val1); }