public void BindingBackAssert <TTargetProperty>( CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Func <object> sourcePropertyGetter, FrameworkElement targetObject, DependencyProperty targetProperty, Action <TTargetProperty> targetPropertySetter, TTargetProperty targetPropertyValue1, TTargetProperty targetPropertyValue2, object sourcePropertyValue1, object sourcePropertyValue2, Dictionary <string, Type> resolvedTypes = null) { targetObject.DataContext = source; var bindingExpression = calcBinding.ProvideValue(new ServiceProviderMock(targetObject, targetProperty, resolvedTypes)); targetObject.SetValue(targetProperty, bindingExpression); //act targetPropertySetter(targetPropertyValue1); //assert var realSourcePropertyValue1 = sourcePropertyGetter(); Assert.AreEqual(sourcePropertyValue1, realSourcePropertyValue1); //act targetPropertySetter(targetPropertyValue2); //assert var realSourcePropertyValue2 = sourcePropertyGetter(); Assert.AreEqual(sourcePropertyValue2, realSourcePropertyValue2); }
public void BindingAssert <TTargetProperty>( CalcBinding.Binding calcBinding, INotifyPropertyChanged source, FrameworkElement targetObject, DependencyProperty targetProperty, Func <TTargetProperty> targetPropertyGetter, Action sourcePropertySetter1, TTargetProperty targetValue1, Action sourcePropertySetter2, TTargetProperty targetValue2 ) { //var test = new ExampleViewModel(); targetObject.DataContext = source; var bindingExpression = calcBinding.ProvideValue(new ServiceProviderMock(targetObject, targetProperty)); targetObject.SetValue(targetProperty, bindingExpression); //act sourcePropertySetter1(); //assert var realValue1 = targetPropertyGetter(); Assert.AreEqual(targetValue1, realValue1); //act sourcePropertySetter2(); //assert var realValue2 = targetPropertyGetter(); Assert.AreEqual(targetValue2, realValue2); }
public void BindingTextBoxToStaticReadonlyPropertyWithDefaultModeFailsTest() { var metadata = TextBox.TextProperty.GetMetadata(typeof(TextBox)); Assert.IsInstanceOfType(metadata, typeof(FrameworkPropertyMetadata), "Metadata of TextBox should be FrameworkMetadata"); Assert.AreEqual(true, (metadata as FrameworkPropertyMetadata).BindsTwoWayByDefault); var calcBinding = new CalcBinding.Binding("local:StaticExampleClass.ReadOnlyName") { UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.Default }; var source = new ExampleViewModel(); var element = new TextBox(); BindingBackAssert(calcBinding, null, () => StaticExampleClass.ReadOnlyName, element, TextBox.TextProperty, (string s) => element.Text = s, "10", "100", "10", "100", new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } }); }
public void BoolBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, bool targetValue1, Action sourcePropertySetter2, bool targetValue2) { var checkbox = new CheckBox(); BindingAssert(calcBinding, source, checkbox, CheckBox.IsCheckedProperty, () => checkbox.IsChecked, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2); }
public void VisibilityBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, Visibility targetValue1, Action sourcePropertySetter2, Visibility targetValue2) { var label = new Label(); BindingAssert(calcBinding, source, label, Label.VisibilityProperty, () => label.Visibility, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2); }
public void StringBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, string targetValue1, Action sourcePropertySetter2, string targetValue2) { var textBox = new TextBox(); BindingAssert(calcBinding, source, textBox, TextBox.TextProperty, () => textBox.Text, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2); }
public void ObjectBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, object targetValue1, Action sourcePropertySetter2, object targetValue2, Dictionary <string, Type> resolvedTypes = null ) { LabelBindingAssert(calcBinding, source, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2, resolvedTypes); }
public void StringBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, string targetValue1, Action sourcePropertySetter2, string targetValue2, Dictionary <string, Type> resolvedTypes = null) { var textBox = new TextBox(); BindingAssert(calcBinding, source, textBox, TextBox.TextProperty, () => textBox.Text, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2, resolvedTypes); }
public void VisibilityBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, Visibility targetValue1, Action sourcePropertySetter2, Visibility targetValue2, Dictionary <string, Type> resolvedTypes = null ) { var label = new Label(); BindingAssert(calcBinding, source, label, Label.VisibilityProperty, () => label.Visibility, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2, resolvedTypes); }
public void BoolBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, bool targetValue1, Action sourcePropertySetter2, bool targetValue2, Dictionary <string, Type> resolvedTypes = null ) { var checkbox = new CheckBox(); BindingAssert(calcBinding, source, checkbox, CheckBox.IsCheckedProperty, () => checkbox.IsChecked, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2, resolvedTypes); }
public void LabelBindingAssert(CalcBinding.Binding calcBinding, INotifyPropertyChanged source, Action sourcePropertySetter1, object targetValue1, Action sourcePropertySetter2, object targetValue2, Dictionary <string, Type> resolvedTypes = null ) { var label = new Label(); BindingAssert(calcBinding, source, label, Label.ContentProperty, () => label.Content, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2, resolvedTypes); }
public void CharWithoutSingleQuotesModeErrorTest() { var source = new ExampleViewModel(); var binding = new CalcBinding.Binding("(Symbol == 'a' ? \"12'24\" : \"BC\""); StringAndObjectBindingAssert(binding, source, () => source.Symbol = 'a', "", null, () => source.Symbol = '1', "", null ); }
public void SingleQuotesStringTest() { var binding = new CalcBinding.Binding("local:StaticExampleClass.StaticString+'1224'"); StringAndObjectBindingAssert(binding, null, () => StaticExampleClass.StaticString = "0'-1", "0'-11224", "0'-11224", () => StaticExampleClass.StaticString = "'G", "'G1224", "'G1224", new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } } ); }
public void CharWithDoubleQuotesWithSingleQuotesModeTest() { var source = new ExampleViewModel(); var binding = new CalcBinding.Binding("Symbol == \"2\" ? 1224 : 24"); binding.SingleQuotes = true; StringAndObjectBindingAssert(binding, source, () => source.Symbol = '1', "24", 24, () => source.Symbol = '2', "1224", 1224 ); }
public void StringWithSingleQuoteErrorTest() { var binding = new CalcBinding.Binding("local:StaticExampleClass.StaticString+\"12'2\""); StringAndObjectBindingAssert(binding, null, () => StaticExampleClass.StaticString = "0'-1'", "", null, () => StaticExampleClass.StaticString = "'G", "", null, new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } } ); }
public void BindingAssert <TTargetProperty>( string path, INotifyPropertyChanged source, FrameworkElement targetObject, DependencyProperty targetProperty, Func <TTargetProperty> targetPropertyGetter, Action sourcePropertySetter1, TTargetProperty targetValue1, Action sourcePropertySetter2, TTargetProperty targetValue2 ) { var calcBinding = new CalcBinding.Binding(path); BindingAssert(calcBinding, source, targetObject, targetProperty, targetPropertyGetter, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2); }
public void DoubleQuotesInCharTest() { var binding = new CalcBinding.Binding("local:StaticExampleClass.StaticChar == 'A' ? 4 : 5"); binding.SingleQuotes = true; StringAndObjectBindingAssert(binding, null, () => StaticExampleClass.StaticChar = 'D', "5", 5, () => StaticExampleClass.StaticChar = 'A', "4", 4, new Dictionary <string, Type> { { "local:StaticExampleClass", typeof(StaticExampleClass) } } ); }
public void DoubleQuotesStringErrorTest() { var binding = new CalcBinding.Binding("local:StaticExampleClass.StaticString+\"1224\""); binding.SingleQuotes = true; StringAndObjectBindingAssert(binding, null, () => StaticExampleClass.StaticString = "0'-1", "", null, () => StaticExampleClass.StaticString = "'G", "", null, new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } } ); }
public void BindingBackAssert <TTargetProperty>( string path, INotifyPropertyChanged source, Func <object> sourcePropertyGetter, FrameworkElement targetObject, DependencyProperty targetProperty, Action <TTargetProperty> targetPropertySetter, TTargetProperty targetPropertyValue1, TTargetProperty targetPropertyValue2, object sourcePropertyValue1, object sourcePropertyValue2, BindingMode mode) { var calcBinding = new CalcBinding.Binding(path) { UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged, Mode = mode }; BindingBackAssert(calcBinding, source, sourcePropertyGetter, targetObject, targetProperty, targetPropertySetter, targetPropertyValue1, targetPropertyValue2, sourcePropertyValue1, sourcePropertyValue2); }
public void DefaultDifferQuotesIsFalseTest() { // default - DifferQuotes = false var binding = new CalcBinding.Binding("A"); Assert.AreEqual(false, binding.SingleQuotes); var exampleViewModel = new ExampleViewModel(); StringBindingAssert("Name + 'D'", exampleViewModel, () => exampleViewModel.Name = "ABC", "ABCD", () => exampleViewModel.Name = "A", "AD" ); StringBindingAssert("Name + \"DEF\"", exampleViewModel, () => exampleViewModel.Name = "ABC", "ABCDEF", () => exampleViewModel.Name = "A", "ADEF" ); }
public void BindingTextBoxToReadonlyPropertyWithoutSettingModeFailsTest() { var metadata = TextBox.TextProperty.GetMetadata(typeof(TextBox)); Assert.IsInstanceOfType(metadata, typeof(FrameworkPropertyMetadata), "Metadata of TextBox should be FrameworkMetadata"); Assert.AreEqual(true, (metadata as FrameworkPropertyMetadata).BindsTwoWayByDefault); var calcBinding = new CalcBinding.Binding("ReadonlyA") { UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged }; var source = new ExampleViewModel(); var element = new TextBox(); BindingBackAssert(calcBinding, source, () => source.A, element, TextBox.TextProperty, (string s) => element.Text = s, "10", "100", (double)10, (double)100); }
public void BindingLabelContentToReadonlyPropertyWithoutSettingModeSuccessTest() { var metadata = Label.ContentProperty.GetMetadata(typeof(Label)); Assert.IsInstanceOfType(metadata, typeof(FrameworkPropertyMetadata), "Metadata of Label should be FrameworkMetadata"); Assert.AreEqual(false, (metadata as FrameworkPropertyMetadata).BindsTwoWayByDefault); var calcBinding = new CalcBinding.Binding("ReadonlyA") { UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged }; var source = new ExampleViewModel(); var element = new Label(); BindingBackAssert(calcBinding, source, () => source.A, element, Label.ContentProperty, (string s) => element.Content = s, "10", "100", (double)10, (double)10); }
public void BindingAssert <TTargetProperty>( string path, INotifyPropertyChanged source, FrameworkElement targetObject, DependencyProperty targetProperty, Func <TTargetProperty> targetPropertyGetter, Action sourcePropertySetter1, TTargetProperty targetValue1, Action sourcePropertySetter2, TTargetProperty targetValue2, Dictionary <string, Type> resolvedTypes = null, object fallbackValue = null ) { var calcBinding = new CalcBinding.Binding(path); if (fallbackValue != null) { calcBinding.FallbackValue = fallbackValue; } BindingAssert(calcBinding, source, targetObject, targetProperty, targetPropertyGetter, sourcePropertySetter1, targetValue1, sourcePropertySetter2, targetValue2, resolvedTypes); }
public void SingleStaticPropertyWithoutBracketsTest() { StringAndObjectBindingAssert("local:StaticExampleClass.StaticA", null, () => StaticExampleClass.StaticA = 10, "10", (double)10, () => StaticExampleClass.StaticA = 20.34, "20.34", 20.34, new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } } ); var binding = new CalcBinding.Binding(); binding.Path = "local:StaticExampleClass.StaticA"; StringAndObjectBindingAssert(binding, null, () => StaticExampleClass.StaticA = 10, "10", (double)10, () => StaticExampleClass.StaticA = 20.34, "20.34", 20.34, new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } } ); }
public void BindingLabelContentToStaticReadonlyPropertyWithoutSettingModeSuccessTest() { var metadata = Label.ContentProperty.GetMetadata(typeof(Label)); Assert.IsInstanceOfType(metadata, typeof(FrameworkPropertyMetadata), "Metadata of Label should be FrameworkMetadata"); Assert.AreEqual(false, (metadata as FrameworkPropertyMetadata).BindsTwoWayByDefault); var calcBinding = new CalcBinding.Binding("local:StaticExampleClass.ReadOnlyName") { UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged }; var source = new ExampleViewModel(); var element = new Label(); BindingBackAssert(calcBinding, null, () => StaticExampleClass.ReadOnlyName, element, Label.ContentProperty, (string s) => element.Content = s, "10", "100", "ReadonlyName", "ReadonlyName", new Dictionary <string, Type>() { { "local:StaticExampleClass", typeof(StaticExampleClass) } }); }