public void TestGetObjectInstanceFromExpressionValueType() { DateTime dateTime = new DateTime(); Expression <Func <DateTime> > expression = () => dateTime.AddDays(2); Assert.ThrowsException <NotSupportedException>( () => ShimHelper.GetObjectInstanceFromExpression((expression.Body as MethodCallExpression).Object)); }
public static Shim Replace(Expression <Action> expression) { MethodCallExpression methodCall = expression.Body as MethodCallExpression; return(new Shim(methodCall.Method, null) { _instance = ShimHelper.GetObjectInstanceFromExpression(methodCall.Object) }); }
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); }