public void LeafPropertiesShouldBeListenedTo()
        {
            var viewModel = new MortgateCalculatorViewModel();
            viewModel.RegeneratePaymentSchedule(true);

            engine.Assign(() => Foo)
                  .From(() => CalcSomethingToDoWithSchedule(viewModel.PaymentSchedule), e => { });

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

            Foo.ShouldNotBe(42);
            viewModel.PaymentSchedule.HasValidationError = false;
            Foo.ShouldBe(42);
            engineInstrumentation.AssertSetCount("Foo", 1);
        }
Exemplo n.º 2
0
        public void GetHarderNode()
        {
            var viewModel = new MortgateCalculatorViewModel();
            viewModel.RegeneratePaymentSchedule(false);
            Expression<Func<bool>> expr = () => viewModel.PaymentSchedule.HasValidationError;
            var node = ExpressionParser.GetChildSources(expr).Single();
            node.FullPath.ShouldBe("viewModel.PaymentSchedule.HasValidationError");
            node.SourcePaths.Count.ShouldBe(1);
            var paymentScheduleNode = node.SourcePaths[0];
            paymentScheduleNode.FullPath.ShouldBe("viewModel.PaymentSchedule");

            var rootNode = paymentScheduleNode.SourcePaths.Single();
            rootNode.FullPath.ShouldBe("viewModel");

            var thisNode = rootNode.SourcePaths.Single();
            thisNode.FullPath.ShouldBe("this");
            thisNode.SourcePaths.ShouldBeEmpty();
        }
        public void ListensToNestedProperties()
        {
            var viewModel = new MortgateCalculatorViewModel();

            engine.Assign(() => viewModel.CanApply)
                  .From(() => !viewModel.PaymentSchedule.HasValidationError, e => { });

            viewModel.RegeneratePaymentSchedule(hasValidationError: true);
            Console.WriteLine(engine.ToDotFormat());
            viewModel.CanApply.ShouldBe(false);
            engineInstrumentation.AssertSetCount("viewModel.CanApply", 1);

            viewModel.RegeneratePaymentSchedule(hasValidationError: false);
            Console.WriteLine(engine.ToDotFormat());
            viewModel.CanApply.ShouldBe(true);
            engineInstrumentation.AssertSetCount("viewModel.CanApply", 2);

            viewModel.PaymentSchedule.HasValidationError = true;
            Console.WriteLine(engine.ToDotFormat());
            viewModel.CanApply.ShouldBe(false);
            engineInstrumentation.AssertSetCount("viewModel.CanApply", 3);

            Console.WriteLine(engine.ToDotFormat());
        }
Exemplo n.º 4
0
        public void TracksNestedProperties()
        {
            var mortgateCalculator = new MortgateCalculatorViewModel();
            mortgateCalculator.RegeneratePaymentSchedule(false);

            engine
                .Assign(() => Prop)
                .From(() => mortgateCalculator.PaymentSchedule.HasValidationError, ex => { });

            string dotFormat = engine.ToDotFormat("Foo");
            Console.WriteLine(dotFormat);
            mortgateCalculator.PaymentSchedule.HasValidationError = true;

            engine.ValueHasChanged(mortgateCalculator.PaymentSchedule, "HasValidationError");
            Prop.ShouldBe(true);
        }