Procházet zdrojové kódy

add test parameters to styled/direct binding tests for #855 and #824

donandren před 8 roky
rodič
revize
ce387271cc

+ 20 - 6
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs

@@ -385,8 +385,10 @@ namespace Avalonia.Base.UnitTests
             }
         }
 
-        [Fact]
-        public void SetValue_Should_Not_Cause_StackOverflow_And_Have_Correct_Values()
+        [Theory]
+        [InlineData(true)]
+        [InlineData(false)]
+        public void SetValue_Should_Not_Cause_StackOverflow_And_Have_Correct_Values(bool useXamlBinding)
         {
             var viewModel = new TestStackOverflowViewModel()
             {
@@ -401,12 +403,24 @@ namespace Avalonia.Base.UnitTests
             //    [~~Class1.DoubleValueProperty] = target[~~Class1.DoubleValueProperty]
             //};
 
-            target.Bind(Class1.DoubleValueProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = viewModel });
+            target.Bind(Class1.DoubleValueProperty,
+                new Binding("Value") { Mode = BindingMode.TwoWay, Source = viewModel });
+
+            var child = new Class1();
 
-            var child = new Class1()
+            if (useXamlBinding)
             {
-                [~~Class1.DoubleValueProperty] = target[~~Class1.DoubleValueProperty]
-            };
+                child.Bind(Class1.DoubleValueProperty,
+                    new Binding("DoubleValue")
+                    {
+                        Mode = BindingMode.TwoWay,
+                        Source = target
+                    });
+            }
+            else
+            {
+                child[!!Class1.DoubleValueProperty] = target[!!Class1.DoubleValueProperty];
+            }
 
             Assert.Equal(1, viewModel.SetterInvokedCount);
 

+ 23 - 6
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs

@@ -440,8 +440,10 @@ namespace Avalonia.Base.UnitTests
             Assert.Equal(BindingMode.OneWayToSource, bar.GetMetadata<Class2>().DefaultBindingMode);
         }
 
-        [Fact]
-        public void SetValue_Should_Not_Cause_StackOverflow_And_Have_Correct_Values()
+        [Theory]
+        [InlineData(true)]
+        [InlineData(false)]
+        public void SetValue_Should_Not_Cause_StackOverflow_And_Have_Correct_Values(bool useXamlBinding)
         {
             var viewModel = new TestStackOverflowViewModel()
             {
@@ -456,12 +458,27 @@ namespace Avalonia.Base.UnitTests
             //    [~~Class1.DoubleValueProperty] = target[~~Class1.DoubleValueProperty]
             //};
 
-            target.Bind(Class1.DoubleValueProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = viewModel });
+            target.Bind(Class1.DoubleValueProperty, new Binding("Value")
+                                                    {
+                                                        Mode = BindingMode.TwoWay,
+                                                        Source = viewModel
+                                                    });
+
+            var child = new Class1();
 
-            var child = new Class1()
+            if (useXamlBinding)
             {
-                [~~Class1.DoubleValueProperty] = target[~~Class1.DoubleValueProperty]
-            };
+                child.Bind(Class1.DoubleValueProperty,
+                    new Binding("DoubleValue")
+                    {
+                        Mode = BindingMode.TwoWay,
+                        Source = target
+                    });
+            }
+            else
+            {
+                child[!!Class1.DoubleValueProperty] = target[!!Class1.DoubleValueProperty];
+            }
 
             Assert.Equal(1, viewModel.SetterInvokedCount);