Пример #1
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);
 }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
 public void StringPropertySet()
 {
     var handWritten = new HandWritten();
     var proxy = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
     {
         invocation.Arguments[0] = "AStringValue" + invocation.Arguments[0];
         await invocation.Proceed();
         return null;
     }));
     proxy.StringProperty = "test";
     Assert.AreEqual("AStringValue" + "test", handWritten.StringProperty);
 }
Пример #6
0
 public void StringPropertyGet()
 {
     var handWritten = new HandWritten();
     handWritten.StringProperty = "AStringProperty";
     var proxy = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
     {
         var returnValue = await invocation.Proceed();
         return (string)returnValue + "test";
     }));
     var result = proxy.StringProperty;
     Assert.AreEqual("AStringProperty" + "test", result);
 }
Пример #7
0
        public void StringPropertySet()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
            {
                invocation.Arguments[0] = "AStringValue" + invocation.Arguments[0];
                await invocation.Proceed();
                return(null);
            }));

            proxy.StringProperty = "test";
            Assert.AreEqual("AStringValue" + "test", handWritten.StringProperty);
        }
Пример #8
0
        public async Task DoSomethingAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(async invocation =>
            {
                await Task.Delay(1);
                await invocation.Proceed();
                return(null);
            }));
            await proxy.DoSomethingAsync();

            Assert.IsTrue(handWritten.DoSomethingAsyncCalled);
        }
Пример #9
0
        public async Task GetStringAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(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);
        }
Пример #10
0
        public void StringPropertyGet()
        {
            var handWritten = new HandWritten();

            handWritten.StringProperty = "AStringProperty";
            var proxy = new HandWrittenProxy(handWritten, new InvocationHandler(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 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);
        }
Пример #13
0
        public void GetStringThrowsExcpetionIfAsync()
        {
            var handWritten = new HandWritten();
            var proxy       = new HandWrittenProxy(handWritten, new InvocationHandler(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)
            {
            }
        }
Пример #14
0
 public void GetStringThrowsExcpetionIfAsync()
 {
     var handWritten = new HandWritten();
     var proxy = new HandWrittenProxy(handWritten, new InvocationHandler(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)
     {
     }
 }
Пример #15
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);
 }
Пример #16
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);
 }