protected MvxBindingDescription CreateBindingDescription() { EnsureTargetNameSet(); MvxSourceStepDescription source; if (_sourceSpec == null) { source = new MvxPathSourceStepDescription() { Converter = _sourceStepDescription.Converter, ConverterParameter = _sourceStepDescription.ConverterParameter, FallbackValue = _sourceStepDescription.FallbackValue }; } else { source = _sourceSpec.CreateSourceStep(_sourceStepDescription); } var toReturn = new MvxBindingDescription() { Mode = BindingDescription.Mode, TargetName = BindingDescription.TargetName, Source = source }; return(toReturn); }
public void TestSimpleCollectionBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "Collection[0]", FallbackValue = "Pah" }; var source = new MySource() { }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(string), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("Pah", value); source.Collection.Add("Hi there"); value = sourceStep.GetValue(); Assert.AreEqual("Hi there", value); sourceStep.SetValue("New value"); Assert.AreEqual("New value", source.Collection[0]); }
public void TestSimpleDoubleBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "DoubleProperty1" }; var source = new MySource() { DoubleProperty1 = 42.21 }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(double), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual(42.21, value); sourceStep.SetValue(13.72); Assert.AreEqual(13.72, source.DoubleProperty1); }
public void TestSimpleIntBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "IntProperty1" }; var source = new MySource() { IntProperty1 = 42 }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(int), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual(42, value); sourceStep.SetValue(72); Assert.AreEqual(72, source.IntProperty1); sourceStep.SetValue("101"); Assert.AreEqual(101, source.IntProperty1); }
public void TestSimpleStringBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "Property1" }; var source = new MySource() { Property1 = "Test 42" }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(string), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("Test 42", value); sourceStep.SetValue("Life line"); Assert.AreEqual("Life line", source.Property1); }
public MvxBindingDescription(string targetName, string sourcePropertyPath, IMvxValueConverter converter, object converterParameter, object fallbackValue, MvxBindingMode mode) { TargetName = targetName; Mode = mode; Source = new MvxPathSourceStepDescription { SourcePropertyPath = sourcePropertyPath, Converter = converter, ConverterParameter = converterParameter, FallbackValue = fallbackValue, }; }
public void TestSimpleSubPropertyBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "SubSource.SubProperty2" }; var source = new MySource() { SubSource = new MySubSource() { SubProperty2 = "Hello World" } }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(string), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("Hello World", value); source.SubSource.SubProperty2 = "Hello Mum"; Assert.AreEqual(typeof(string), sourceStep.SourceType); value = sourceStep.GetValue(); Assert.AreEqual("Hello Mum", value); source.SubSource.SubProperty2 = "Hello Mum"; source.SubSource = null; Assert.AreEqual(typeof(object), sourceStep.SourceType); value = sourceStep.GetValue(); Assert.AreEqual(MvxBindingConstant.UnsetValue, value); }
public void TestSimpleIntWithValueConversionBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "IntProperty1", Converter = new IntPlus1ValueConverter() }; var source = new MySource() { IntProperty1 = 42 }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(int), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual(43, value); int changed = -99; sourceStep.Changed += (sender, args) => changed = (int)sourceStep.GetValue(); source.IntProperty1 = 71; Assert.AreEqual(72, changed); value = sourceStep.GetValue(); Assert.AreEqual(72, value); sourceStep.SetValue(101); Assert.AreEqual(100, source.IntProperty1); }
public void TestSimpleSubObjectChangePropagationBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "SubSource.SubProperty1" }; var source = new MySource() { SubSource = new MySubSource() { SubProperty1 = "Test 42" } }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(string), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("Test 42", value); var changes = new List <object>(); sourceStep.Changed += (sender, args) => { changes.Add(sourceStep.GetValue()); }; source.SubSource.SubProperty1 = "Changed to 17"; Assert.AreEqual(1, changes.Count); Assert.AreEqual("Changed to 17", changes[0]); value = sourceStep.GetValue(); Assert.AreEqual("Changed to 17", value); var oldSubSource = source.SubSource; source.SubSource = new MySubSource() { SubProperty1 = "New Sub object" }; Assert.AreEqual(2, changes.Count); Assert.AreEqual("New Sub object", changes[1]); value = sourceStep.GetValue(); Assert.AreEqual("New Sub object", value); oldSubSource.SubProperty1 = "Should not fire"; Assert.AreEqual(2, changes.Count); source.SubSource.SubProperty1 = "Should fire"; Assert.AreEqual(3, changes.Count); Assert.AreEqual("Should fire", changes[2]); }
public void TestIndedexedChangePropagationBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "Collection[0]" }; var source = new MySource() { }; source.Collection.Add("Initial"); var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(string), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("Initial", value); var changes = new List <object>(); sourceStep.Changed += (sender, args) => { changes.Add(sourceStep.GetValue()); }; source.Collection[0] = "Changed to 17"; Assert.AreEqual(1, changes.Count); Assert.AreEqual("Changed to 17", changes[0]); value = sourceStep.GetValue(); Assert.AreEqual("Changed to 17", value); sourceStep.DataContext = new MySource(); value = sourceStep.GetValue(); Assert.AreEqual(MvxBindingConstant.UnsetValue, value); source.Collection[0] = "Changed again 19"; Assert.AreEqual(1, changes.Count); sourceStep.DataContext = source; Assert.AreEqual(1, changes.Count); value = sourceStep.GetValue(); Assert.AreEqual("Changed again 19", value); source.Collection[0] = "Changed again again 19"; Assert.AreEqual(2, changes.Count); Assert.AreEqual("Changed again again 19", changes[1]); value = sourceStep.GetValue(); Assert.AreEqual("Changed again again 19", value); }
public void TestSimpleChangePropagationBinding() { var realSourceStepFactory = this.SetupSourceStepFactory(); var sourceStepDescription = new MvxPathSourceStepDescription() { SourcePropertyPath = "Property1" }; var source = new MySource() { Property1 = "Test 42" }; var sourceStep = realSourceStepFactory.Create(sourceStepDescription); sourceStep.DataContext = source; Assert.AreEqual(typeof(string), sourceStep.SourceType); object value = sourceStep.GetValue(); Assert.AreEqual("Test 42", value); var changes = new List <object>(); sourceStep.Changed += (sender, args) => { changes.Add(sourceStep.GetValue()); }; source.Property1 = "Changed to 17"; Assert.AreEqual(1, changes.Count); Assert.AreEqual("Changed to 17", changes[0]); value = sourceStep.GetValue(); Assert.AreEqual("Changed to 17", value); sourceStep.DataContext = new MySource(); value = sourceStep.GetValue(); Assert.AreEqual(null, value); source.Property1 = "Changed again 19"; Assert.AreEqual(1, changes.Count); sourceStep.DataContext = source; Assert.AreEqual(1, changes.Count); value = sourceStep.GetValue(); Assert.AreEqual("Changed again 19", value); source.Property1 = "Changed again again 19"; Assert.AreEqual(2, changes.Count); Assert.AreEqual("Changed again again 19", changes[1]); value = sourceStep.GetValue(); Assert.AreEqual("Changed again again 19", value); }