public void Transform_ThrowsArgumentException_IfThereIsNoFieldOrPropertyWithName() { // Creating the expression "instance.GetNonExistentField()" Expression instance = Expression.Parameter(typeof(Fixture), "instance"); Expression input = Expression.Call(instance, FixtureGetNonExistentField); // Validating that FieldGetAttribute fails on non-existent field FieldGetAttribute attribute = new FieldGetAttribute("NonExistentField"); Assert.ThrowsException <ArgumentException>(() => attribute.Transform(input)); }
public void Transform_ReplacesMethodCallExpressionWithAddAssignExpression_ForFieldEvents() { // Creating the expression "instance.GetField()" ParameterExpression instance = Expression.Parameter(typeof(Fixture), "instance"); Expression input = Expression.Call(instance, FixtureGetField); // Validating that FieldGetAttribute creates expression reading Field Expression output = new FieldGetAttribute("Field").Transform(input); Func <Fixture, int> getField = Expression.Lambda <Func <Fixture, int> >(output, new[] { instance }).Compile(); Fixture fixture = new Fixture() { Field = 5 }; Assert.AreEqual(5, getField(fixture)); }