public void Should_MethodFromDelegateResult_throw_if_expression_is_not_returning_delegate() { Expression <Action> methodCall = () => SomeClass.Bar(); var exception = Assert.Throws <ArgumentException>(() => methodCall.MethodFromDelegateResult()); Assert.That(exception.Message, Is.EqualTo("Expected lambda expression returning method delegate, got: () => Bar()")); }
public void Should_MethodInfoFromMethodCall_throw_if_expression_is_not_accessing_property_getter() { Expression <Action> methodCall = () => SomeClass.Bar(); var exception = Assert.Throws <ArgumentException>(() => methodCall.PropertyFromGetter()); Assert.That(exception.Message, Is.EqualTo("Expected getter selector lambda, got: () => Bar()")); }
public void Should_MethodInfoFromMethodCall_throw_if_expression_is_not_method_call() { Expression <Func <object> > methodCall = () => (object)SomeClass.Bar(); var exception = Assert.Throws <ArgumentException>(() => methodCall.MethodFromMethodCall()); Assert.That(exception.Message, Is.EqualTo("Expected method call lambda expression, got: () => Convert(Bar())")); }
public void Should_get_most_outer_method_info() { Expression <Func <string> > methodCall = () => SomeClass.Bar().ToString(CultureInfo.InvariantCulture); Assert.That(methodCall.MethodFromMethodCall(), Is.EqualTo(typeof(int).GetMethod("ToString", new[] { typeof(IFormatProvider) }))); }
public void Should_get_method_info_from_static_method_call() { Expression <Action> methodCall = () => SomeClass.Bar(); Assert.That(methodCall.MethodFromMethodCall(), Is.EqualTo(typeof(SomeClass).GetMethod("Bar"))); }