public void Containers_Correct_After_Clear_Add_Remove() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { // Issue #1936 var items = new AvaloniaList <string>(Enumerable.Range(0, 11).Select(x => $"Item {x}")); var target = new ListBox { Template = ListBoxTemplate(), Items = items, ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock { Width = 20, Height = 10 }), SelectedIndex = 0, }; Prepare(target); items.Clear(); items.AddRange(Enumerable.Range(0, 11).Select(x => $"Item {x}")); items.Remove("Item 2"); Assert.Equal( items, target.Presenter.Panel.Children.Cast <ListBoxItem>().Select(x => (string)x.Content)); } }
public void Should_Add_Containers_For_Items_After_Clear() { var target = CreateTarget(itemCount: 10); var defaultItems = (IList <string>)target.Items; var items = new AvaloniaList <string>(defaultItems); target.Items = items; target.ApplyTemplate(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(10, target.Panel.Children.Count); items.Clear(); target.Panel.Measure(new Size(100, 100)); target.Panel.Arrange(new Rect(target.Panel.DesiredSize)); target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); Assert.Empty(target.Panel.Children); items.AddRange(defaultItems.Select(s => s + " new")); target.Panel.Measure(new Size(100, 100)); target.Panel.Arrange(new Rect(target.Panel.DesiredSize)); target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(10, target.Panel.Children.Count); }
public void AddRange_Items_Should_Raise_Correct_CollectionChanged() { var target = new AvaloniaList <object>(); var eventItems = new List <object>(); target.CollectionChanged += (sender, args) => { eventItems.AddRange(args.NewItems.Cast <object>()); }; target.AddRange(Enumerable.Range(0, 10).Select(i => new object())); Assert.Equal(eventItems, target); }
public void AddRange_IEnumerable_Should_Raise_Count_PropertyChanged() { var target = new AvaloniaList <int>(new[] { 1, 2, 3, 4, 5 }); var raised = false; target.PropertyChanged += (s, e) => { Assert.Equal(e.PropertyName, nameof(target.Count)); Assert.Equal(target.Count, 7); raised = true; }; target.AddRange(Enumerable.Range(6, 2)); Assert.True(raised); }
public void Adding_Items_Should_Raise_CollectionChanged() { var target = new AvaloniaList <int>(new[] { 1, 2 }); var raised = false; target.CollectionChanged += (s, e) => { Assert.Equal(target, s); Assert.Equal(NotifyCollectionChangedAction.Add, e.Action); Assert.Equal(new[] { 3, 4 }, e.NewItems.Cast <int>()); Assert.Equal(2, e.NewStartingIndex); raised = true; }; target.AddRange(new[] { 3, 4 }); Assert.True(raised); }
public void AddRange_With_Null_Should_Throw_Exception() { var target = new AvaloniaList <int>(); Assert.Throws <ArgumentNullException>(() => target.AddRange(null)); }
public void AddRange_With_Null_Should_Throw_Exception() { var target = new AvaloniaList<int>(); Assert.Throws<ArgumentNullException>(() => target.AddRange(null)); }
public void Adding_Items_Should_Raise_CollectionChanged() { var target = new AvaloniaList<int>(new[] { 1, 2 }); var raised = false; target.CollectionChanged += (s, e) => { Assert.Equal(target, s); Assert.Equal(NotifyCollectionChangedAction.Add, e.Action); Assert.Equal(new[] { 3, 4 }, e.NewItems.Cast<int>()); Assert.Equal(2, e.NewStartingIndex); raised = true; }; target.AddRange(new[] { 3, 4 }); Assert.True(raised); }
public void Should_Add_Containers_For_Items_After_Clear() { var target = CreateTarget(itemCount: 10); var defaultItems = (IList<string>)target.Items; var items = new AvaloniaList<string>(defaultItems); target.Items = items; target.ApplyTemplate(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(10, target.Panel.Children.Count); items.Clear(); target.Panel.Measure(new Size(100, 100)); target.Panel.Arrange(new Rect(target.Panel.DesiredSize)); target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(0, target.Panel.Children.Count); items.AddRange(defaultItems.Select(s => s + " new")); target.Panel.Measure(new Size(100, 100)); target.Panel.Arrange(new Rect(target.Panel.DesiredSize)); target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(10, target.Panel.Children.Count); }