| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // Copyright (c) The Perspex Project. All rights reserved.
- // Licensed under the MIT license. See licence.md file in the project root for full license information.
- using System.Linq;
- using Perspex.Controls.Presenters;
- using Perspex.Controls.Primitives;
- using Perspex.Controls.Templates;
- using Perspex.LogicalTree;
- using Xunit;
- namespace Perspex.Controls.UnitTests
- {
- public class CarouselTests
- {
- [Fact]
- public void First_Item_Should_Be_Selected_By_Default()
- {
- var target = new Carousel
- {
- Template = new FuncControlTemplate<Carousel>(CreateTemplate),
- Items = new[]
- {
- "Foo",
- "Bar"
- }
- };
- target.ApplyTemplate();
- Assert.Equal(0, target.SelectedIndex);
- Assert.Equal("Foo", target.SelectedItem);
- }
- [Fact]
- public void LogicalChild_Should_Be_Selected_Item()
- {
- var target = new Carousel
- {
- Template = new FuncControlTemplate<Carousel>(CreateTemplate),
- Items = new[]
- {
- "Foo",
- "Bar"
- }
- };
- target.ApplyTemplate();
- target.Presenter.ApplyTemplate();
- Assert.Equal(1, target.GetLogicalChildren().Count());
- var child = target.GetLogicalChildren().Single();
- Assert.IsType<TextBlock>(child);
- Assert.Equal("Foo", ((TextBlock)child).Text);
- }
- private Control CreateTemplate(Carousel control)
- {
- return new CarouselPresenter
- {
- Name = "PART_ItemsPresenter",
- [~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty],
- [~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty],
- [~CarouselPresenter.SelectedIndexProperty] = control[~SelectingItemsControl.SelectedIndexProperty],
- [~CarouselPresenter.TransitionProperty] = control[~Carousel.TransitionProperty],
- };
- }
- }
- }
|