Browse Source

Simplify ListBox unit test template creation.

pull/554/head
Steven Kirk 10 years ago
parent
commit
cfdfa9400e
  1. 30
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

30
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -19,7 +19,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = CreateListBoxTemplate(),
ItemTemplate = new FuncDataTemplate<string>(_ => new Canvas()), ItemTemplate = new FuncDataTemplate<string>(_ => new Canvas()),
}; };
@ -40,7 +40,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = CreateListBoxTemplate(),
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -54,7 +54,7 @@ namespace Avalonia.Controls.UnitTests
var items = new[] { "Foo", "Bar", "Baz " }; var items = new[] { "Foo", "Bar", "Baz " };
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = CreateListBoxTemplate(),
Items = items, Items = items,
}; };
@ -77,7 +77,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = CreateListBoxTemplate(),
Items = new[] { "Foo", "Bar", "Baz " }, Items = new[] { "Foo", "Bar", "Baz " },
}; };
@ -104,7 +104,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = CreateListBoxTemplate(),
DataContext = "Base", DataContext = "Base",
DataTemplates = new DataTemplates DataTemplates = new DataTemplates
{ {
@ -125,17 +125,19 @@ namespace Avalonia.Controls.UnitTests
dataContexts); dataContexts);
} }
private Control CreateListBoxTemplate(ITemplatedControl parent) private FuncControlTemplate CreateListBoxTemplate()
{ {
return new ScrollViewer return new FuncControlTemplate<ListBox>(parent =>
{ new ScrollViewer
Template = new FuncControlTemplate(CreateScrollViewerTemplate),
Content = new ItemsPresenter
{ {
Name = "PART_ItemsPresenter", Name = "PART_ScrollViewer",
[~ItemsPresenter.ItemsProperty] = parent.GetObservable(ItemsControl.ItemsProperty), Template = new FuncControlTemplate(CreateScrollViewerTemplate),
} Content = new ItemsPresenter
}; {
Name = "PART_ItemsPresenter",
[~ItemsPresenter.ItemsProperty] = parent.GetObservable(ItemsControl.ItemsProperty),
}
});
} }
private FuncControlTemplate ListBoxItemTemplate() private FuncControlTemplate ListBoxItemTemplate()

Loading…
Cancel
Save