public void TestStruct() { DataObjectModel obj = new DataObjectModel(); obj.StructTest.MyEnum = Day.A2; obj.StructTest.MyInt32 = 123; obj.StructTest.MyString = "temp"; MyStruct m; m.MyEnum = Day.A5; m.MyInt32 = 999; m.MyString = "testStruct"; EntityTools <DataObjectModel> .SetValue(obj, "StructTest", false, m); Assert.AreEqual(m.MyEnum, obj.StructTest.MyEnum); Assert.AreEqual(m.MyInt32, obj.StructTest.MyInt32); Assert.AreEqual(m.MyString, obj.StructTest.MyString); MyStruct d = (MyStruct)EntityTools <DataObjectModel> .GetValue(obj, "STRUCTTEST", true); Assert.AreEqual(m.MyEnum, d.MyEnum); Assert.AreEqual(m.MyInt32, d.MyInt32); Assert.AreEqual(m.MyString, d.MyString); }
public void GetValueIgnoreCase() { DataObjectModel obj = new DataObjectModel(); string s = "test1234"; obj.Name = s; string v = EntityTools <DataObjectModel> .GetValue(obj, "naMe", true) as string; Assert.AreEqual(s, v); }
public void TestEnum() { DataObjectModel obj = new DataObjectModel(); obj.MyDay = Day.A1; EntityTools <DataObjectModel> .SetValue(obj, "MyDay", false, "A2"); Assert.AreEqual(Day.A2, obj.MyDay); Day d = (Day)EntityTools <DataObjectModel> .GetValue(obj, "myDay", true); Assert.AreEqual(d, obj.MyDay); }
public void TestDateTime() { DataObjectModel obj = new DataObjectModel(); obj.CreateTime = DateTime.Parse("2010-09-18"); DateTime i = DateTime.Parse("2012-2-1"); EntityTools <DataObjectModel> .SetValue(obj, "CreateTime", false, "2012-2-1"); Assert.AreEqual(i, obj.CreateTime); DateTime d = (DateTime)EntityTools <DataObjectModel> .GetValue(obj, "CreateTime", true); Assert.AreEqual(d, obj.CreateTime); }
public void TestInt32() { DataObjectModel obj = new DataObjectModel(); obj.BookCount = 112; int i = 234234; EntityTools <DataObjectModel> .SetValue(obj, "BookCount", false, i); Assert.AreEqual(i, obj.BookCount); int d = (int)EntityTools <DataObjectModel> .GetValue(obj, "BookCount", true); Assert.AreEqual(d, obj.BookCount); }
private void GetSet(bool ignoreCase) { var obj = new DataObjectModel(); IDataObject objIDataObject = obj as IDataObject; object glocalInstance = obj; string propertyName = "Name"; var func = (Func <DataObjectModel, string>)Delegate.CreateDelegate(typeof(Func <DataObjectModel, string>), typeof(DataObjectModel).GetMethod("get_Name")); TestCase tester = new TestCase(); tester.Watcher = (i, name, sw) => { Trace.WriteLine(string.Format("{0}:{1}", name, sw.Elapsed)); }; tester.Build("直接调用时", () => { obj.NameField = obj.Name; }); tester.Build("委托调用时", () => { var value = func(obj); }); tester.Build("接口调用时", () => { objIDataObject.SetValue(propertyName, ignoreCase, objIDataObject.GetValue(propertyName, ignoreCase)); }); tester.Build("工具调用时", () => { EntityTools <DataObjectModel> .SetValue(obj, propertyName, ignoreCase, EntityTools <DataObjectModel> .GetValue(obj, propertyName, ignoreCase)); }); tester.Build("字符串工具", () => { EntityTools <DataObjectModel> .SetValueString(obj, propertyName, ignoreCase, EntityTools <DataObjectModel> .GetValueString(obj, propertyName, ignoreCase)); }); tester.Build("虚接口调用", () => { obj.SetEntityValue(propertyName, ignoreCase, obj.GetEntityValue(propertyName, ignoreCase)); }); tester.StepWatcher = i => { Trace.WriteLine(string.Format("执行{0:###,###,###}次的结果: ", i)); }; int times = 10000; tester.Execute(1000 * times); }