public void TestDateTimeSetter() { var obj = new SimpleClass(); var fieldMap = new PropertySetterBase.FieldMapData(typeof (SimpleClass).GetProperty("DateTimeProperty"), "dd/MMM/yyyy:HH:mm:ss"); var setter = new DateTimeSetter(fieldMap); setter.Set(obj, "20/Dez/2010:00:02:38"); Assert.AreEqual(DateTime.Parse("2010-12-20T00:02:38"), obj.DateTimeProperty); setter.Set(obj, "20/Dec/2010:00:02:38"); Assert.AreEqual(DateTime.Parse("2010-12-20T00:02:38"), obj.DateTimeProperty); setter.Set(obj, "2010-12-20 00:02:38"); Assert.AreEqual(DateTime.Parse("2010-12-20T00:02:38"), obj.DateTimeProperty); setter.Set(obj, "1313029269"); Assert.AreEqual(DateTime.Parse("2011-08-11T02:21:09"), obj.DateTimeProperty); setter.Set(obj, "26/04/2013 17:16:26"); Assert.AreEqual(DateTime.Parse("2013-04-26T17:16:26"), obj.DateTimeProperty); }
public void TestHexToLongDWordSetter() { var obj = new SimpleClass(); var fieldMap = new PropertySetterBase.FieldMapData(typeof (SimpleClass).GetProperty("LongProperty")); var setter = new HexToLongDWordSetter(fieldMap); setter.Set(obj, "21C5431"); Assert.AreEqual(35410993, obj.LongProperty); setter.Set(obj, "2F15DB8A4C"); Assert.AreEqual(202230172236, obj.LongProperty); obj.LongProperty = -933489160; var parsedValue = setter.Get(obj); Assert.AreEqual("C85C15F8", parsedValue); }
public void TestVarCharSetter() { const string stringBig = "Esta string tem mais de 20 caracteres e precisa ser cortada aqui senão vai gerar uma exception."; var obj = new SimpleClass(); var fieldMap = new PropertySetterBase.FieldMapData(typeof(SimpleClass).GetProperty("StringProperty")) {MaxLength = 20 }; var setter = new VarCharSetter(fieldMap); setter.Set(obj, stringBig); Assert.AreEqual(stringBig.Substring(0, 20), obj.StringProperty); }
public void TestEnumSetter() { var fieldMap = new PropertySetterBase.FieldMapData(typeof(SimpleClass).GetProperty("EnumProperty")); var setter = new EnumSetter<SimpleEnum>(fieldMap); var obj = new SimpleClass(); setter.Set(obj, "1"); Assert.AreEqual(SimpleEnum.Number1, obj.EnumProperty); obj = new SimpleClass(); setter.Set(obj, "3"); Assert.AreEqual(SimpleEnum.Number1 | SimpleEnum.Number2, obj.EnumProperty); obj = new SimpleClass(); setter.Set(obj, "9999"); Assert.AreEqual((SimpleEnum)9999, obj.EnumProperty); obj = new SimpleClass(); setter.Set(obj, "asfdsdafadf"); Assert.AreEqual(SimpleEnum.None, obj.EnumProperty); }
public void TestHexToLongQWordSetter() { var obj = new SimpleClass(); var fieldMap = new PropertySetterBase.FieldMapData (typeof(SimpleClass).GetProperty("LongProperty")); var setter = new HexToLongQWordSetter(fieldMap); setter.Set(obj, "21C5431"); Assert.AreEqual(35410993, obj.LongProperty); }