public void TestCombinerPropertiesPresentBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxCombinerSourceStepDescription() { Combiner = new MvxAddValueCombiner(), InnerSteps = new List <MvxSourceStepDescription>() { new MvxPathSourceStepDescription() { SourcePropertyPath = "DoubleProperty1", }, new MvxPathSourceStepDescription() { SourcePropertyPath = "DoubleProperty2", }, } }; var source = new MySource() { DoubleProperty1 = 12.34, DoubleProperty2 = 23.45 }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(double), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual(35.79, value); var changes = new List <object>(); sourceStep.Changed += (sender, args) => { changes.Add(sourceStep.GetValue()); }; source.DoubleProperty1 = 11.11; Assert.AreEqual(1, changes.Count); Assert.AreEqual(34.56, changes[0]); value = sourceStep.GetValue(); Assert.AreEqual(34.56, value); source.DoubleProperty2 = 12.11; Assert.AreEqual(2, changes.Count); Assert.AreEqual(23.22, changes[1]); value = sourceStep.GetValue(); Assert.AreEqual(23.22, value); }
public void TestCombinerPropertiesMissingBinding_Part2() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxCombinerSourceStepDescription() { Combiner = new MvxAddValueCombiner(), InnerSteps = new List <MvxSourceStepDescription>() { new MvxPathSourceStepDescription() { SourcePropertyPath = "SubSource.SubProperty1", FallbackValue = "It was missing" }, new MvxPathSourceStepDescription() { SourcePropertyPath = "DoubleProperty1", }, } }; var source = new MySource() { DoubleProperty1 = 12.34, }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(object), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("It was missing12.34", value); var changes = new List <object>(); sourceStep.Changed += (sender, args) => { changes.Add(sourceStep.GetValue()); }; source.DoubleProperty1 = 11.11; Assert.AreEqual(1, changes.Count); Assert.AreEqual("It was missing11.11", changes[0]); value = sourceStep.GetValue(); Assert.AreEqual("It was missing11.11", value); source.DoubleProperty1 = 12.11; Assert.AreEqual(2, changes.Count); Assert.AreEqual("It was missing12.11", changes[1]); value = sourceStep.GetValue(); Assert.AreEqual("It was missing12.11", value); source.SubSource = new MySubSource() { SubProperty1 = "Hello" }; Assert.AreEqual(3, changes.Count); Assert.AreEqual("Hello12.11", changes[2]); value = sourceStep.GetValue(); Assert.AreEqual("Hello12.11", value); }