public void GetInvertedHarderNode() { var viewModel = new MortgateCalculatorViewModel(); viewModel.RegeneratePaymentSchedule(false); Expression <Func <bool> > expr = () => !viewModel.PaymentSchedule.HasValidationError; var node = ExpressionParser.GetChildSources(expr); node.Count.ShouldBe(1); var validationErrorNode = node[0]; validationErrorNode.FullPath.ShouldBe("viewModel.PaymentSchedule.HasValidationError"); validationErrorNode.SourcePaths.Count.ShouldBe(1); var paymentScheduleNode = validationErrorNode.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 VerifyProperties() { var viewModel = new SimpleWithNotification(); var mortgateCalculatorViewModel = new MortgateCalculatorViewModel(); VerifyExpression(() => Foo, "Foo"); VerifyExpression(() => viewModel.Value, "viewModel.Value"); VerifyExpression(() => mortgateCalculatorViewModel.PaymentSchedule.HasValidationError, "mortgateCalculatorViewModel.PaymentSchedule.HasValidationError"); }
public void VerifyFormulas() { var notifies = new Totals { TaxPercentage = 20 }; var mortgateCalculatorViewModel = new MortgateCalculatorViewModel(); VerifyExpression(() => (int)(notifies.SubTotal * (1m + (notifies.TaxPercentage / 100m))), "(notifies.SubTotal * (1 + (notifies.TaxPercentage / 100)))"); VerifyExpression(() => InstanceMethodCall(), "InstanceMethodCall()"); VerifyExpression(() => notifies.InstanceMethod(), "notifies.InstanceMethod()"); VerifyExpression(() => mortgateCalculatorViewModel.RegeneratePaymentSchedule(true), "mortgateCalculatorViewModel.RegeneratePaymentSchedule(true)"); VerifyExpression(() => StaticMethod(notifies.SubTotal), "StaticMethod(notifies.SubTotal)"); VerifyExpression(() => StaticMethodLotsOfArguments(notifies.TaxPercentage, notifies.TaxPercentage, notifies.TaxPercentage, notifies.TaxPercentage), "StaticMethodLotsOfArguments(...)"); }
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); }
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); }
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()); }