예제 #1
0
        public async void SumAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy <IHandWritten>(handWritten, async invocation =>
            {
                var value = (int)await invocation.Proceed();
                return(value + 3);
            });
            var result = await proxy.SumAsync(1, 2);

            Assert.AreEqual(6, result);
        }
예제 #2
0
        public void GetString()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy <IHandWritten>(handWritten, async invocation =>
            {
                var returnValue = await invocation.Proceed();
                return((string)returnValue + "test");
            });
            var result = proxy.GetString();

            Assert.AreEqual(HandWritten.GetStringReturnValue + "test", result);
        }
예제 #3
0
        public void GetString()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
            {
                var returnValue = await invocation.Proceed();
                return((string)returnValue + "test");
            }));
            var result = proxy.GetString();

            Assert.AreEqual(HandWritten.GetStringReturnValue + "test", result);
        }
예제 #4
0
        public void DoSomething()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy <IHandWritten>(handWritten, async invocation =>
            {
                await invocation.Proceed();
                return(null);
            });

            proxy.DoSomething();
            Assert.IsTrue(handWritten.DoSomethingCalled);
        }
예제 #5
0
        public async void SumAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
            {
                var value = (int)await invocation.Proceed();
                return(value + 3);
            }));
            var result = await proxy.SumAsync(1, 2);

            Assert.AreEqual(6, result);
        }
예제 #6
0
        public void DoSomething()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
            {
                await invocation.Proceed();
                return(null);
            }));

            proxy.DoSomething();
            Assert.IsTrue(handWritten.DoSomethingCalled);
        }
예제 #7
0
        public void StringPropertySet()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy <IHandWritten>(handWritten, async invocation =>
            {
                invocation.Arguments[0] = "AStringValue" + invocation.Arguments[0];
                await invocation.Proceed();
                return(null);
            });

            proxy.StringProperty = "test";
            Assert.AreEqual("AStringValue" + "test", handWritten.StringProperty);
        }
        public async void GetStringAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy(handWritten, async invocation =>
            {
                await Task.Delay(1);
                var returnValue = await invocation.Proceed();
                return((string)returnValue + "test");
            });
            var result = await proxy.GetStringAsync();

            Assert.AreEqual(HandWritten.GetStringAsyncReturnValue + "test", result);
        }
        public async void DoSomethingAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy(handWritten, async invocation =>
            {
                await Task.Delay(1);
                await invocation.Proceed();
                return(null);
            });
            await proxy.DoSomethingAsync();

            Assert.IsTrue(handWritten.DoSomethingAsyncCalled);
        }
예제 #10
0
        public void StringPropertyGet()
        {
            var handWritten = new HandWritten();

            handWritten.StringProperty = "AStringProperty";
            var proxy = Proxy.CreateProxy <IHandWritten>(handWritten, async invocation =>
            {
                var returnValue = await invocation.Proceed();
                return((string)returnValue + "test");
            });
            var result = proxy.StringProperty;

            Assert.AreEqual("AStringProperty" + "test", result);
        }
예제 #11
0
        public void StringPropertyPropertyInfo()
        {
            var          handWritten = new HandWritten();
            PropertyInfo property    = null;
            var          proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
            {
                var returnValue = await invocation.Proceed();
                property        = invocation.Property;
                return((string)returnValue + "test");
            }));

            // ReSharper disable once UnusedVariable (We are trying to invoke the accessor, but only to set the property variable above)
            var result = proxy.StringProperty;

            Assert.AreEqual(nameof(HandWritten.StringProperty), property.Name);
        }
예제 #12
0
        public void GetStringThrowsExcpetionIfAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = Proxy.CreateProxy <IHandWritten>(handWritten, async invocation =>
            {
                await Task.Delay(1);
                var returnValue = await invocation.Proceed();
                return((string)returnValue + "test");
            });

            try
            {
                proxy.GetString();
                Assert.Fail("Should have thrown an InvalidAsyncException");
            }
            catch (InvalidAsyncException)
            {
            }
        }