Exemplo n.º 1
0
        public void WriteOnlyPropertiesThrowMemberAccessExceptionWhenReadFrom()
        {
            var propertyInfo = typeof(Foo).GetProperty("SomeWriteonlyProperty");

            var looseGetExpression = ExpressionFactory.CreateGetValueFuncExpression(propertyInfo);
            var getExpression      = ExpressionFactory.CreateGetValueFuncExpression <Foo, string>(propertyInfo);

            var looseGet = looseGetExpression.Compile();
            var get      = getExpression.Compile();

            var foo = new Foo();

            Assert.That(() => looseGet(foo), Throws.TypeOf <MemberAccessException>());
            Assert.That(() => get(foo), Throws.TypeOf <MemberAccessException>());
        }