public void TestCacheablePocoSubtractAssign() { var tPoco = new PocoEvent(); bool tTest = false; var tEvent = new EventHandler <EventArgs>((@object, args) => { tTest = true; }); var tCachedInvoke = new CacheableInvocation(InvocationKind.SubtractAssign, "Event"); tPoco.Event += tEvent; tCachedInvoke.Invoke(tPoco, tEvent); tPoco.OnEvent(null, null); Assert.AreEqual(false, tTest); tCachedInvoke.Invoke(tPoco, tEvent);//Test Second Time var tPoco2 = new PropPoco() { Event = 3 }; tCachedInvoke.Invoke(tPoco2, 4); Assert.AreEqual(-1, tPoco2.Event); }
public void TestCacheableDyanmicSetAndPocoSetAndSetNull() { dynamic tExpando = new ExpandoObject(); var tSetValueD = "4"; var tCachedInvoke = new CacheableInvocation(InvocationKind.Set, "Prop1"); tCachedInvoke.Invoke((object)tExpando, tSetValueD); Assert.AreEqual(tSetValueD, tExpando.Prop1); var tPoco = new PropPoco(); var tSetValue = "1"; tCachedInvoke.Invoke(tPoco, tSetValue); Assert.AreEqual(tSetValue, tPoco.Prop1); String tSetValue2 = null; tCachedInvoke.Invoke(tPoco, tSetValue2); Assert.AreEqual(tSetValue2, tPoco.Prop1); }
public void TestCacheableGet() { var tCached = new CacheableInvocation(InvocationKind.Get, "Prop1"); var tSetValue = "1"; var tAnon = new PropPoco { Prop1 = tSetValue }; var tOut = tCached.Invoke(tAnon); Assert.AreEqual(tSetValue, tOut); var tSetValue2 = "2"; tAnon = new PropPoco { Prop1 = tSetValue2 }; var tOut2 = tCached.Invoke(tAnon); Assert.AreEqual(tSetValue2, tOut2); }
public void TestSetTimed() { // Compares PB duck-typing with plain reflection and ImpromptuInterfaces (InvokeSet and using an ActLike<> invocation) // So far, PB-duck-typing is about twice as slow (when profiled) as II. Perhaps this can get better... Though the penalty // may be worth it when considering the extra features (like fuzzy-ducking) var tPoco = new PropPoco(); var tSetValue = "1"; var tWatch = TimeIt.Go(() => { Impromptu.InvokeSet(tPoco, "Prop1", tSetValue); }, 500000); var tPropertyInfo = tPoco.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] {}), TIMES); var ducked = tPoco.DuckAs <IPropPoco>(); Assert.IsNotNull(ducked); var tWatch3 = TimeIt.Go(() => ducked.Prop1 = tSetValue, TIMES); TestContext.WriteLine("InvokeSet: " + tWatch.Elapsed); TestContext.WriteLine("Reflection: " + tWatch2.Elapsed); TestContext.WriteLine("Ducked: " + tWatch3.Elapsed); }
public void CacheableGetValueTimed() { var tSetValue = "1"; var tAnon = new PropPoco() { Prop1 = tSetValue }; var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1"); Timer.Action1 = () => { var tOut = tInvoke.Invoke(tAnon); }; var tPropertyInfo = tAnon.GetType().GetProperty("Prop1"); Timer.Action2 = () => { var tOut = tPropertyInfo.GetValue(tAnon, null); }; var elapsed = Timer.Go(2 * TimeIt.Million); Console.WriteLine("Impromptu: " + elapsed.Item1); Console.WriteLine("Refelection: " + elapsed.Item2); Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed)); Assert.Less(elapsed.Item1, elapsed.Item2); }
public void TestPocoSubtractAssign() { var tPoco = new PocoEvent(); bool tTest = false; var tEvent = new EventHandler <EventArgs>((@object, args) => { tTest = true; }); tPoco.Event += tEvent; Dynamic.InvokeSubtractAssignMember(tPoco, "Event", tEvent); tPoco.OnEvent(null, null); Assert.AreEqual(false, tTest); Dynamic.InvokeSubtractAssignMember(tPoco, "Event", tEvent);//Test Second Time var tPoco2 = new PropPoco() { Prop2 = 3 }; Dynamic.InvokeSubtractAssignMember(tPoco2, "Prop2", 4); Assert.AreEqual(-1L, tPoco2.Prop2); }
public void TestPocoSet() { var tPoco = new PropPoco(); var tSetValue = "1"; Dynamic.InvokeSet(tPoco, "Prop1", tSetValue); Assert.AreEqual(tSetValue, tPoco.Prop1); }
public void TestPocoSet() { var tPoco = new PropPoco(); var tSetValue = "1"; Impromptu.InvokeSet(tPoco, "Prop1", tSetValue); Assert.AreEqual(tSetValue, tPoco.Prop1); }
public void TestToStringProxyCall() { var tAnon = new PropPoco() { Prop1 = "A", Prop2 = 1 }; dynamic tProxy = tAnon.ProxyToString( it => string.Format("{0}:{1}", it.Prop1, it.Prop2)); Assert.AreEqual(tAnon.Prop2, tProxy.Prop2); }
public void TestToStringProxyDictionaryMassage() { var tPropPoco = new PropPoco() { Prop1 = "A" }; dynamic tData = Builder.New().Object(ReturnProp: tPropPoco.ProxyToString(it => "Print Me")); IPropPocoProp tInter = Impromptu.ActLike <IPropPocoProp>(tData); Assert.AreEqual(tPropPoco.GetType(), tInter.ReturnProp.GetType()); }
public void TestRoundTripSerial() { ISimpeleClassProps value = new PropPoco() { Prop1 = "POne", Prop2 = 45L, Prop3 = Guid.NewGuid() }.ActLike <ISimpeleClassProps>(); var tDeValue = SerialAndDeSerialize(value); Assert.AreEqual(value.Prop1, tDeValue.Prop1); Assert.AreEqual(value.Prop2, tDeValue.Prop2); Assert.AreEqual(value.Prop3, tDeValue.Prop3); }
public void TestToStringProxyConvertImplicit() { var tAnon = new PropPoco() { Prop1 = "A", Prop2 = 1 }; dynamic tProxy = tAnon.ProxyToString( it => string.Format("{0}:{1}", it.Prop1, it.Prop2)); var tAnon2 = ImplicitCast(tProxy); Assert.AreEqual(tAnon.GetType(), tAnon2.GetType()); }
public void TestSetNullTimed() { var tPoco = new PropPoco(); String tSetValue = null; var tWatch = TimeIt.Go(() => Impromptu.InvokeSet(tPoco, "Prop1", tSetValue), 500000); var tPropertyInfo = tPoco.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }), 500000); TestContext.WriteLine("Impromptu: " + tWatch.Elapsed); TestContext.WriteLine("Refelection: " + tWatch2.Elapsed); TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks); Assert.Less(tWatch.Elapsed, tWatch2.Elapsed); }
public void TestCacheableSetNullTimed() { var tPoco = new PropPoco(); String tSetValue = null; var tCachedInvoke = new CacheableInvocation(InvocationKind.Set, "Prop1"); var tWatch = TimeIt.Go(() => tCachedInvoke.Invoke(tPoco, tSetValue), 500000); var tPropertyInfo = tPoco.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }), 500000); TestContext.WriteLine("Impromptu: " + tWatch.Elapsed); TestContext.WriteLine("Refelection: " + tWatch2.Elapsed); TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks); Assert.Less(tWatch.Elapsed, tWatch2.Elapsed); }
public void TestSetTimed() { var tPoco = new PropPoco(); var tSetValue = "1"; var tWatch = TimeIt.Go(() => Impromptu.InvokeSet(tPoco, "Prop1", tSetValue), 500000); var tPropertyInfo = tPoco.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }), 500000); TestContext.WriteLine("Impromptu: " + tWatch.Elapsed); TestContext.WriteLine("Refelection: " + tWatch2.Elapsed); TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks); Assert.Less(tWatch.Elapsed, tWatch2.Elapsed); }
public void TestCacheableSetTimed() { var tPoco = new PropPoco(); var tSetValue = "1"; var tCacheable = new CacheableInvocation(InvocationKind.Set, "Prop1"); var tWatch = TimeIt.Go(() => tCacheable.Invoke(tPoco, tSetValue), 500000); var tPropertyInfo = tPoco.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { }), 500000); TestContext.WriteLine("Impromptu: " + tWatch.Elapsed); TestContext.WriteLine("Refelection: " + tWatch2.Elapsed); TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks); Assert.Less(tWatch.Elapsed, tWatch2.Elapsed); }
public void CacheableSetNullTimed() { var tPoco = new PropPoco(); String tSetValue = null; var tCachedInvoke = new CacheableInvocation(InvocationKind.Set, "Prop1"); Timer.Action1 = (() => tCachedInvoke.Invoke(tPoco, tSetValue)); var tPropertyInfo = tPoco.GetType().GetProperty("Prop1"); Timer.Action2 = (() => tPropertyInfo.SetValue(tPoco, tSetValue, new object[] { })); var elapsed = Timer.Go(); Console.WriteLine("Impromptu: " + elapsed.Item1); Console.WriteLine("Refelection: " + elapsed.Item2); Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed)); Assert.Less(elapsed.Item1, elapsed.Item2); }
public void TestPocoAddAssign() { var tPoco = new PocoEvent(); bool tTest = false; Dynamic.InvokeAddAssignMember(tPoco, "Event", new EventHandler <EventArgs>((@object, args) => { tTest = true; })); tPoco.OnEvent(null, null); Assert.AreEqual(true, tTest); var tPoco2 = new PropPoco() { Prop2 = 3 }; Dynamic.InvokeAddAssignMember(tPoco2, "Prop2", 4); Assert.AreEqual(7L, tPoco2.Prop2); }
public void SetTimed() { #if DEBUG Assert.Ignore("Visual Studio slows down dynamic too much in debug mode"); #endif var tPoco1 = new PropPoco(); var tPoco2 = new PropPoco(); var tSetValue = "1"; Timer.Action1 = () => Dynamic.InvokeSet(tPoco1, "Prop1", tSetValue); var tPropertyInfo = tPoco2.GetType().GetProperty("Prop1"); Timer.Action2 = () => tPropertyInfo.SetValue(tPoco2, tSetValue, new object[] { }); var elapsed = Timer.Go(5 * TimeIt.Million); Console.WriteLine("Impromptu: " + elapsed.Item1); Console.WriteLine("Refelection: " + elapsed.Item2); Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed)); Assert.Less(elapsed.Item1, elapsed.Item2); }
public void TestCacheablePocoAddAssign() { var tPoco = new PocoEvent(); bool tTest = false; var tCachedInvoke = new CacheableInvocation(InvocationKind.AddAssign, "Event"); tCachedInvoke.Invoke(tPoco, new EventHandler <EventArgs>((@object, args) => { tTest = true; })); tPoco.OnEvent(null, null); Assert.AreEqual(true, tTest); var tPoco2 = new PropPoco() { Event = 3 }; tCachedInvoke.Invoke(tPoco2, 4); Assert.AreEqual(7L, tPoco2.Event); }
public void TestCacheableGetValueTimed() { var tSetValue = "1"; var tAnon = new PropPoco() { Prop1 = tSetValue }; var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1"); var tWatch = TimeIt.Go(() => { var tOut = tInvoke.Invoke(tAnon); }, 500000); var tPropertyInfo = tAnon.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => { var tOut = tPropertyInfo.GetValue(tAnon, null); }, 500000); TestContext.WriteLine("Impromptu: " + tWatch.Elapsed); TestContext.WriteLine("Refelection: " + tWatch2.Elapsed); TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks); Assert.Less(tWatch.Elapsed, tWatch2.Elapsed); }
public void TestCacheablePocoAddAssign() { var tPoco = new PocoEvent(); bool tTest = false; var tCachedInvoke = new CacheableInvocation(InvocationKind.AddAssign, "Event"); tCachedInvoke.Invoke(tPoco, new EventHandler<EventArgs>((@object, args) => { tTest = true; })); tPoco.OnEvent(null, null); Assert.AreEqual(true, tTest); var tPoco2 = new PropPoco() { Event = 3 }; tCachedInvoke.Invoke(tPoco2, 4); Assert.AreEqual(7L, tPoco2.Event); }
public void SetTimed() { #if DEBUG Assert.Ignore("Visual Studio slows down dynamic too much in debug mode"); #endif var tPoco1 = new PropPoco(); var tPoco2 = new PropPoco(); var tSetValue = "1"; Timer.Action1 = () => Dynamic.InvokeSet(tPoco1, "Prop1", tSetValue); var tPropertyInfo = tPoco2.GetType().GetProperty("Prop1"); Timer.Action2 = () => tPropertyInfo.SetValue(tPoco2, tSetValue, new object[] { }); var elapsed = Timer.Go(5* TimeIt.Million); Console.WriteLine("Impromptu: " + elapsed.Item1); Console.WriteLine("Refelection: " + elapsed.Item2); Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed)); Assert.Less(elapsed.Item1, elapsed.Item2); }
public void CacheableGetValueTimed() { var tSetValue = "1"; var tAnon = new PropPoco() { Prop1 = tSetValue }; var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1"); Timer.Action1 = () => { var tOut = tInvoke.Invoke(tAnon); }; var tPropertyInfo = tAnon.GetType().GetProperty("Prop1"); Timer.Action2 = () => { var tOut = tPropertyInfo.GetValue(tAnon, null); }; var elapsed = Timer.Go(2*TimeIt.Million); Console.WriteLine("Impromptu: " + elapsed.Item1); Console.WriteLine("Refelection: " + elapsed.Item2); Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed)); Assert.Less(elapsed.Item1, elapsed.Item2); }
public void CacheableSetTimed() { var tPoco1 = new PropPoco(); var tPoco2 = new PropPoco(); var tSetValue = "1"; var tCacheable = new CacheableInvocation(InvocationKind.Set, "Prop1"); Timer.Action1 = () => tCacheable.Invoke(tPoco1, tSetValue); var tPropertyInfo = tPoco2.GetType().GetProperty("Prop1"); Timer.Action2 = () => tPropertyInfo.SetValue(tPoco2, tSetValue, new object[] { }); var elapsed = Timer.Go(); Console.WriteLine("Impromptu: " + elapsed.Item1); Console.WriteLine("Refelection: " + elapsed.Item2); Console.WriteLine("Impromptu VS Reflection: {0}", TimeIt.RelativeSpeed(elapsed)); Assert.Less(elapsed.Item1, elapsed.Item2); }
public void TestCacheableGetValueTimed() { var tSetValue = "1"; var tAnon = new PropPoco() {Prop1 = tSetValue}; var tInvoke = new CacheableInvocation(InvocationKind.Get, "Prop1"); var tWatch = TimeIt.Go(() => { var tOut = tInvoke.Invoke(tAnon); }, 500000); var tPropertyInfo = tAnon.GetType().GetProperty("Prop1"); var tWatch2 = TimeIt.Go(() => { var tOut = tPropertyInfo.GetValue(tAnon, null); }, 500000); TestContext.WriteLine("Impromptu: " + tWatch.Elapsed); TestContext.WriteLine("Refelection: " + tWatch2.Elapsed); TestContext.WriteLine("Impromptu VS Reflection: {0:0.0} x faster", (double)tWatch2.Elapsed.Ticks / tWatch.Elapsed.Ticks); Assert.Less(tWatch.Elapsed, tWatch2.Elapsed); }
private PropPoco ImplicitCast(PropPoco value) { return(value); }
public void TestPocoAddAssign() { var tPoco = new PocoEvent(); bool tTest = false; Impromptu.InvokeAddAssignMember(tPoco, "Event", new EventHandler<EventArgs>((@object, args) => { tTest = true; })); tPoco.OnEvent(null, null); Assert.AreEqual(true, tTest); var tPoco2 = new PropPoco() { Prop2 = 3 }; Impromptu.InvokeAddAssignMember(tPoco2, "Prop2", 4); Assert.AreEqual(7L, tPoco2.Prop2); }
public void TestCacheableGet() { var tCached =new CacheableInvocation(InvocationKind.Get, "Prop1"); var tSetValue = "1"; var tAnon = new PropPoco{ Prop1 = tSetValue }; var tOut = tCached.Invoke(tAnon); Assert.AreEqual(tSetValue, tOut); var tSetValue2 = "2"; tAnon = new PropPoco { Prop1 = tSetValue2 }; var tOut2 = tCached.Invoke(tAnon); Assert.AreEqual(tSetValue2, tOut2); }
public void TestCacheablePocoSubtractAssign() { var tPoco = new PocoEvent(); bool tTest = false; var tEvent = new EventHandler<EventArgs>((@object, args) => { tTest = true; }); var tCachedInvoke = new CacheableInvocation(InvocationKind.SubtractAssign, "Event"); tPoco.Event += tEvent; tCachedInvoke.Invoke(tPoco, tEvent); tPoco.OnEvent(null, null); Assert.AreEqual(false, tTest); tCachedInvoke.Invoke(tPoco, tEvent);//Test Second Time var tPoco2 = new PropPoco() { Event = 3 }; tCachedInvoke.Invoke(tPoco2, 4); Assert.AreEqual(-1, tPoco2.Event); }
public void TestPocoSubtractAssign() { var tPoco = new PocoEvent(); bool tTest = false; var tEvent = new EventHandler<EventArgs>((@object, args) => { tTest = true; }); tPoco.Event += tEvent; Impromptu.InvokeSubtractAssignMember(tPoco, "Event", tEvent); tPoco.OnEvent(null, null); Assert.AreEqual(false, tTest); Impromptu.InvokeSubtractAssignMember(tPoco, "Event", tEvent);//Test Second Time var tPoco2 = new PropPoco() {Prop2 = 3}; Impromptu.InvokeSubtractAssignMember(tPoco2, "Prop2", 4); Assert.AreEqual( -1L,tPoco2.Prop2); }