Inheritance: IHandWritten
コード例 #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 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);
 }
コード例 #3
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);
 }
コード例 #4
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);
        }
コード例 #5
0
        public async Task 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       = 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);
 }