public void SimpleParamsMethod()
        {
            var simple  = new SimpleWithNotification();
            var simple2 = new SimpleWithNotification();
            Expression <Func <int> > expr = () => Add(simple.Value, simple2.Value);
            var node = ExpressionParser.GetChildSources(expr);

            node.Count.ShouldBe(2);
            var valueNode = node[0];

            valueNode.FullPath.ShouldBe("simple.Value");
            var rootNode = valueNode.SourcePaths.Single();

            rootNode.FullPath.ShouldBe("simple");

            var thisNode = rootNode.SourcePaths.Single();

            thisNode.FullPath.ShouldBe("this");
            thisNode.SourcePaths.ShouldBeEmpty();

            var valueNode2 = node[1];

            valueNode2.FullPath.ShouldBe("simple2.Value");
            var rootNode2 = valueNode2.SourcePaths.Single();

            rootNode2.FullPath.ShouldBe("simple2");

            thisNode = rootNode2.SourcePaths.Single();
            thisNode.FullPath.ShouldBe("this");
            thisNode.SourcePaths.ShouldBeEmpty();
        }
        public void PreventsReentrancy()
        {
            var one   = new SimpleWithNotification();
            var two   = new SimpleWithNotification();
            var three = new SimpleWithNotification();
            var four  = new SimpleWithNotification();

            /*     +--3<--+
             *     ▼      |
             *     4      1
             *     ^      |
             *     +--2<--+
             */
            engine.Assign(() => four.Value)
            .From(() => two.Value + three.Value, e => { });
            engine.Assign(() => two.Value)
            .From(() => one.Value, e => { });
            engine.Assign(() => three.Value)
            .From(() => one.Value, e => { });

            Console.WriteLine(engine.ToDotFormat(string.Empty));

            one.Value = 1;

            four.Value.ShouldBe(2);
            engineInstrumentation.AssertSetCount("four.Value", 1);
        }
        public void VerifyProperties()
        {
            var viewModel = new SimpleWithNotification();
            var mortgateCalculatorViewModel = new MortgateCalculatorViewModel();

            VerifyExpression(() => Foo, "Foo");
            VerifyExpression(() => viewModel.Value, "viewModel.Value");
            VerifyExpression(() => mortgateCalculatorViewModel.PaymentSchedule.HasValidationError, "mortgateCalculatorViewModel.PaymentSchedule.HasValidationError");
        }
Example #4
0
        public void ExpressionCanTriggerAction2()
        {
            var    simple        = new SimpleWithNotification();
            var    actionInvoked = 0;
            Action action        = () => actionInvoked++;

            engine.When(() => simple.Value).Do(v => action(), ex => { });
            actionInvoked.ShouldBe(0);

            simple.Value = 2;

            actionInvoked.ShouldBe(1);
            Console.WriteLine(engine.ToString());
        }