Example #1
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());
        }
        public void SimpleMethod()
        {
            var simple = new SimpleWithNotification();
            Expression<Func<int>> expr = () => Negate(simple.Value);
            var node = ExpressionParser.GetChildSources(expr);
            node.Count.ShouldBe(1);
            var valueNode = node.Single();
            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();
        }
        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);
        }