AutoFake
AutoFake copied to clipboard
Provide MemberExpression example (MemberInfo)
See AcceptMemberVisitor_UnsupportedMemberExpression_Throws
[Fact]
public void AcceptMemberVisitor_UnsupportedMemberExpression_Throws()
{
var factory = new Fake<Expression.InvocationExpression>().Services.Resolve<IMemberVisitorFactory>();
Expression<Func<DateTime>> expression = () => DateTime.Now;
var memberExpression = expression.Body as MemberExpression;
var fake = new Fake<Expression.InvocationExpression>(factory, memberExpression);
fake.Options.DisableVirtualMembers = true;
var sut = fake.Rewrite(s => s.AcceptMemberVisitor(new GetValueMemberVisitor(null)));
sut.Replace((MemberExpression e) => e.Member).Return(new FakeMemberInfo());
Action act = () => sut.Execute();
act.Should().Throw<NotSupportedException>("*is not supported*");
}
private class FakeMemberInfo : MemberInfo
{
public override Type DeclaringType => throw new NotImplementedException();
public override MemberTypes MemberType => throw new NotImplementedException();
public override string Name => throw new NotImplementedException();
public override Type ReflectedType => throw new NotImplementedException();
public override object[] GetCustomAttributes(bool inherit) => throw new NotImplementedException();
public override object[] GetCustomAttributes(Type attributeType, bool inherit) => throw new NotImplementedException();
public override bool IsDefined(Type attributeType, bool inherit) => throw new NotImplementedException();
}
You cannot pass MemberInfo even throug Expression.MakeMemberAccess because it requires either property or field