Esempio n. 1
0
        public void Transform_ThrowsArgumentException_IfThereIsNoFieldOrPropertyWithName()
        {
            // Creating the expression "instance.RemoveNonExistentDelegate(handler)"
            Expression instance = Expression.Parameter(typeof(Fixture), "instance");
            Expression handler  = Expression.Parameter(typeof(Action), "handler");
            Expression input    = Expression.Call(instance, FixtureRemoveNonExistentDelegate, handler);

            // Validating that DelegateRemoveAttribute fails on non-existent field or property
            DelegateRemoveAttribute attribute = new DelegateRemoveAttribute("NonExistentDelegate");

            Assert.ThrowsException <ArgumentException>(() => attribute.Transform(input));
        }
Esempio n. 2
0
        public void Transform_ReplacesMethodCallExpressionWithAddAssignExpression_ForPropertyEvents()
        {
            // Creating the expression "instance.RemovePropertyDelegate(handler)"
            ParameterExpression instance = Expression.Parameter(typeof(Fixture), "instance");
            ParameterExpression handler  = Expression.Parameter(typeof(Action), "handler");
            Expression          input    = Expression.Call(instance, FixtureRemovePropertyDelegate, handler);

            // Validating that DelegateAddAttribute creates expression unsubscribing to PropertyDelegate
            Expression output = new DelegateRemoveAttribute("PropertyDelegate").Transform(input);
            Action <Fixture, Action> removePropertyDelegate = Expression.Lambda <Action <Fixture, Action> >(output, new[] { instance, handler }).Compile();

            Fixture fixture = new Fixture();
            Action  action  = () => { };

            fixture.PropertyDelegate += action;
            removePropertyDelegate(fixture, action);
            Assert.IsNull(fixture.PropertyDelegate);
        }