示例#1
0
            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"));
            }
示例#2
0
 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());
 }
示例#3
0
            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 }));
            }
示例#4
0
            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" }));
            }
示例#5
0
            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"));
            }
示例#6
0
            public void Test()
            {
                var proxy = SimpleProxyFactory.CreateProxyWithoutTarget <IInterface>(new DelegateHandler(c => "42"));

                Assert.That(proxy.Foo(), Is.EqualTo("42"));
            }