public void Test() { var proxy = SimpleProxyFactory.CreateProxyWithoutTarget <IOne>(new DelegateHandler(c => c.MethodInfo.Name), typeof(ITwo)); Assert.That(proxy.One(), Is.EqualTo("One")); Assert.That(((ITwo)proxy).Two(), Is.EqualTo("Two")); }
public Benchmark() { manualWithoutTarget = new Impl(); manualForTarget = new Decorator(new Impl()); castleForTarget = new ProxyGenerator().CreateInterfaceProxyWithTarget <IInterface>(new Impl(), new CastleInterceptor(true)); simpleForTarget = SimpleProxyFactory.CreateProxyForTarget <IInterface>(new SimpleInterceptor(), new Impl()); castleWithoutTarget = new ProxyGenerator().CreateInterfaceProxyWithoutTarget <IInterface>(new CastleInterceptor(false)); simpleWithoutTarget = SimpleProxyFactory.CreateProxyWithoutTarget <IInterface>(new SimpleInterceptor()); }
public void Test() { var invocations = new List <MethodInvocation>(); var proxy = SimpleProxyFactory.CreateProxyWithoutTarget <IFoo>(new DelegateHandler(c => invocations.Add(c))); proxy.Foo(1, 2, 3); Assert.That(invocations.Single().MethodInfo.Name, Is.EqualTo("Foo")); Assert.That(invocations.Single().Arguments.Single(), Is.EqualTo(new object[] { 1, 2, 3 })); }
public void Test() { var invocations = new List <MethodInvocation>(); var proxy = SimpleProxyFactory.CreateProxyWithoutTarget <IFoo>(new DelegateHandler(c => invocations.Add(c))); proxy.Foo("one", "two"); Assert.That(invocations.Single().MethodInfo, Is.EqualTo(typeof(IFoo).GetMethod("Foo"))); Assert.That(invocations.Single().Arguments, Is.EqualTo(new object[] { "one", "two" })); }
public void Test() { var withoutTarget1 = SimpleProxyFactory.CreateProxyWithoutTarget <IInterface>(new DelegateHandler(_ => "withoutTarget1")); var withoutTarget2 = SimpleProxyFactory.CreateProxyWithoutTarget <IInterface>(new DelegateHandler(_ => "withoutTarget2")); var withTarget1 = SimpleProxyFactory.CreateProxyForTarget <IInterface>(new DelegateInterceptor(args => args.Result = "newValue1"), new Impl("originalValue1")); var withTarget2 = SimpleProxyFactory.CreateProxyForTarget <IInterface>(new DelegateInterceptor(args => args.Result = "newValue2"), new Impl("originalValue2")); Assert.That(withoutTarget1.Foo(), Is.EqualTo("withoutTarget1")); Assert.That(withoutTarget2.Foo(), Is.EqualTo("withoutTarget2")); Assert.That(withTarget1.Foo(), Is.EqualTo("newValue1")); Assert.That(withTarget2.Foo(), Is.EqualTo("newValue2")); }
public void Test() { var proxy = SimpleProxyFactory.CreateProxyWithoutTarget <IInterface>(new DelegateHandler(c => "42")); Assert.That(proxy.Foo(), Is.EqualTo("42")); }