예제 #1
0
        public void TestGetObjectInstanceFromExpressionValueType()
        {
            DateTime dateTime = new DateTime();
            Expression <Func <DateTime> > expression = () => dateTime.AddDays(2);

            Assert.ThrowsException <NotSupportedException>(
                () => ShimHelper.GetObjectInstanceFromExpression((expression.Body as MethodCallExpression).Object));
        }
예제 #2
0
파일: Shim.cs 프로젝트: dr-BEat/pose
        public static Shim Replace(Expression <Action> expression)
        {
            MethodCallExpression methodCall = expression.Body as MethodCallExpression;

            return(new Shim(methodCall.Method, null)
            {
                _instance = ShimHelper.GetObjectInstanceFromExpression(methodCall.Object)
            });
        }
예제 #3
0
        public void TestGetObjectInstanceFromExpression()
        {
            ShimHelperTests     shimHelperTests = new ShimHelperTests();
            Expression <Action> expression      = () => shimHelperTests.TestGetObjectInstanceFromExpression();
            var instance = ShimHelper.GetObjectInstanceFromExpression((expression.Body as MethodCallExpression).Object);

            Assert.IsNotNull(instance);
            Assert.AreEqual <Type>(typeof(ShimHelperTests), instance.GetType());
            Assert.AreSame(shimHelperTests, instance);
            Assert.AreNotSame(new ShimHelperTests(), instance);
        }