Browse Source

Add Unit Test

Tim 3 years ago
parent
commit
ab4bb208f5
1 changed files with 20 additions and 0 deletions
  1. 20 0
      tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs

+ 20 - 0
tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using Avalonia.Collections;
 using Avalonia.Controls.Presenters;
 using Avalonia.Controls.Templates;
+using Avalonia.Data;
 using Avalonia.Input;
 using Avalonia.LogicalTree;
 using Avalonia.Styling;
@@ -736,6 +737,25 @@ namespace Avalonia.Controls.UnitTests
             root.Child = null;
             root.Child = target;
         }
+        
+        [Fact]
+        public void Should_Use_DisplayMemberBinding()
+        {
+            var target = new ItemsControl
+            {
+                Template = GetTemplate(),
+                DisplayMemberBinding = new Binding("Length")
+            };
+
+            target.Items = new[] { "Foo" };
+            target.ApplyTemplate();
+            target.Presenter.ApplyTemplate();
+
+            var container = (ContentPresenter)target.Presenter.Panel.Children[0];
+            container.UpdateChild();
+
+            Assert.Equal(container.Child!.GetValue(TextBlock.TextProperty), "3");
+        }
 
         private class Item
         {