浏览代码

add simple unit test for multibinding

Andrey Kunchev 5 年之前
父节点
当前提交
7f0c502c29
共有 1 个文件被更改,包括 59 次插入0 次删除
  1. 59 0
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_MultiBinding.cs

+ 59 - 0
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_MultiBinding.cs

@@ -0,0 +1,59 @@
+// Copyright (c) The Avalonia Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Reactive.Linq;
+using System.Reactive.Subjects;
+using Avalonia.Data;
+using Avalonia.Data.Converters;
+using Xunit;
+
+namespace Avalonia.Base.UnitTests
+{
+    public class AvaloniaObjectTests_MultiBinding
+    {
+        [Fact]
+        public void Should_Update()
+        {
+            var target = new Class1();
+
+            var b = new Subject<object>();
+
+            var mb = new MultiBinding()
+            {
+                Converter = StringJoinConverter,
+                Bindings = new[]
+                {
+                    b.ToBinding()
+                }
+            };
+            target.Bind(Class1.FooProperty, mb);
+
+            Assert.Equal(null, target.Foo);
+
+            b.OnNext("Foo");
+
+            Assert.Equal("Foo", target.Foo);
+
+            b.OnNext("Bar");
+
+            Assert.Equal("Bar", target.Foo);
+        }
+
+        private static IMultiValueConverter StringJoinConverter = new FuncMultiValueConverter<object, string>(v => string.Join(",", v.ToArray()));
+
+        private class Class1 : AvaloniaObject
+        {
+            public static readonly StyledProperty<string> FooProperty =
+                AvaloniaProperty.Register<Class1, string>("Foo");
+
+            public string Foo
+            {
+                get => GetValue(FooProperty);
+                set => SetValue(FooProperty, value);
+            }
+        }
+    }
+}