public virtual void WrapInTheDesiredType() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems(); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.IsInstanceOfType(converter.Convert(item, typeof(double), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Thickness), "15", DefaultCulture), typeof(Thickness)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Point), "15", DefaultCulture), typeof(Point)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Rect), "15", DefaultCulture), typeof(Rect)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Size), "15", DefaultCulture), typeof(Size)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(GridLength), "15", DefaultCulture), typeof(GridLength)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(int), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(float), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(decimal), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(string), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, null, "15", DefaultCulture), typeof(double))); }
public virtual void AssociateWithTreeViewItems() { TreeViewItemCheckBox c1 = new TreeViewItemCheckBox { Content = "First" }; TreeViewItemCheckBox c2 = new TreeViewItemCheckBox { Content = "Second" }; TreeViewItemCheckBox c3 = new TreeViewItemCheckBox { Content = "Third" }; TreeViewItemCheckBox c4 = new TreeViewItemCheckBox { Content = "Fourth" }; TreeViewItemCheckBox c5 = new TreeViewItemCheckBox { Content = "Fifth" }; TreeViewItem t1, t2, t3, t4, t5; TreeView view = new TreeViewBuilder() .Items(c1).Expand().Named(out t1) .Items(c2).Expand().Named(out t2) .Item(c3).Expand().Named(out t3).Set(t => t.SetIsChecked(true)) .Item(c4).Expand().Named(out t4) .EndItems() .EndItems() .Item(c5).Named(out t5).Set(t => t.SetIsChecked(true)); TestAsync( view, () => Assert.AreEqual(t1.GetIsChecked(), c1.IsChecked, "First didn't match!"), () => Assert.AreEqual(t2.GetIsChecked(), c2.IsChecked, "Second didn't match!"), () => Assert.AreEqual(t3.GetIsChecked(), c3.IsChecked, "Third didn't match!"), () => Assert.AreEqual(t4.GetIsChecked(), c4.IsChecked, "Fourth didn't match!"), () => Assert.AreEqual(t5.GetIsChecked(), c5.IsChecked, "Fifth didn't match!")); }
public virtual void WrapIndentOnTheLeft() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems(); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => { Thickness value = (Thickness)converter.Convert(item, typeof(Thickness), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Left, "Thickness.Left should be non-zero!"); Assert.AreEqual(0.0, value.Right, "Thickness.Right should be zero!"); Assert.AreEqual(0.0, value.Top, "Thickness.Top should be zero!"); Assert.AreEqual(0.0, value.Bottom, "Thickness.Bottom should be zero!"); }, () => { Point value = (Point)converter.Convert(item, typeof(Point), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.X, "Point.X should be non-zero!"); Assert.AreEqual(0.0, value.Y, "Point.Y should be zero!"); }, () => { Rect value = (Rect)converter.Convert(item, typeof(Rect), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Left, "Rect.Left should be non-zero!"); Assert.AreEqual(0.0, value.Width, "Rect.Width should be zero!"); Assert.AreEqual(0.0, value.Top, "Rect.Top should be zero!"); Assert.AreEqual(0.0, value.Height, "Rect.Height should be zero!"); }, () => { Size value = (Size)converter.Convert(item, typeof(Size), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Width, "Size.Width should be non-zero!"); Assert.AreEqual(0.0, value.Height, "Size.Height should be zero!"); }, () => { GridLength value = (GridLength)converter.Convert(item, typeof(GridLength), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Value, "GridLength.Value should be non-zero!"); Assert.IsTrue(value.IsAbsolute, "GridLength should be absolute!"); }); }
public virtual void GetItemsHostForTreeViewItem() { TreeViewItem item; TreeView control = new TreeViewBuilder() .Items("first").Named(out item).Expand() .Item("a") .Item("b") .Item("c") .EndItems() .Item("d"); Panel host = null; TestAsync( control, () => host = item.GetItemsHost(), () => Assert.IsNotNull(host, "ItemsHost not found!")); }
public virtual void CultureInfoIsRespected() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems() .Item("fourth"); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), "15.0", new CultureInfo("en-US")), "en-US"), () => Assert.AreEqual(10.0, converter.Convert(item, typeof(double), "5,0", new CultureInfo("vi-VN")), "vi-VN")); }
public virtual void Indentation() { TreeViewItem first, second, third, fourth; TreeView view = new TreeViewBuilder() .Items("first").Expand().Named(out first) .Items("second").Expand().Named(out second) .Item("third").Named(out third) .EndItems() .EndItems() .Item("fourth").Named(out fourth); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(0.0, converter.Convert(first, typeof(double), "15", DefaultCulture), "first should not be indented!"), () => Assert.AreEqual(15.0, converter.Convert(second, typeof(double), "15", DefaultCulture), "second should be indented once!"), () => Assert.AreEqual(30.0, converter.Convert(third, typeof(double), "15", DefaultCulture), "third should be indented twice!"), () => Assert.AreEqual(0.0, converter.Convert(fourth, typeof(double), "15", DefaultCulture), "fourth should not be indented!")); }
public virtual void GetItemsAndContainersDoesNotRecurse() { TreeView view = new TreeViewBuilder() .Items("first").Expand() .Item("a") .Item("b") .Item("c") .EndItems() .Items("second").Expand() .Item("1") .Item("2") .Item("3") .EndItems(); ItemsControl control = view as ItemsControl; TestAsync( control, () => Assert.AreEqual(2, control.GetItemsAndContainers <TreeViewItem>().Count(), "Only expecting two containers!")); }
public virtual void InvalidConverterParameters() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems() .Item("fourth"); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), null, DefaultCulture), "(null)"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), string.Empty, DefaultCulture), "(empty)"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), 10, DefaultCulture), "10"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), 10.0, DefaultCulture), "10.0"), () => Assert.AreEqual(0.0, converter.Convert(item, typeof(double), "foo", DefaultCulture), "foo")); }
public virtual void ConverterParameterDefinesIndent() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems() .Item("fourth"); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), "15", DefaultCulture), "15"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), "15.0", DefaultCulture), "15.0"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), null, DefaultCulture), "(null)"), () => Assert.AreEqual(2.0, converter.Convert(item, typeof(double), "1", DefaultCulture), "1"), () => Assert.AreEqual(10.0, converter.Convert(item, typeof(double), "5", DefaultCulture), "5")); }
public virtual void AssociateWithTreeViewItems() { TreeViewItemCheckBox c1 = new TreeViewItemCheckBox { Content = "First" }; TreeViewItemCheckBox c2 = new TreeViewItemCheckBox { Content = "Second" }; TreeViewItemCheckBox c3 = new TreeViewItemCheckBox { Content = "Third" }; TreeViewItemCheckBox c4 = new TreeViewItemCheckBox { Content = "Fourth" }; TreeViewItemCheckBox c5 = new TreeViewItemCheckBox { Content = "Fifth" }; TreeViewItem t1, t2, t3, t4, t5; TreeView view = new TreeViewBuilder() .Items(c1).Expand().Named(out t1) .Items(c2).Expand().Named(out t2) .Item(c3).Expand().Named(out t3).Set(t => t.SetIsChecked(true)) .Item(c4).Expand().Named(out t4) .EndItems() .EndItems() .Item(c5).Named(out t5).Set(t => t.SetIsChecked(true)); TestAsync( view, () => Assert.AreEqual(t1.GetIsChecked(), c1.IsChecked, "First didn't match!"), () => Assert.AreEqual(t2.GetIsChecked(), c2.IsChecked, "Second didn't match!"), () => Assert.AreEqual(t3.GetIsChecked(), c3.IsChecked, "Third didn't match!"), () => Assert.AreEqual(t4.GetIsChecked(), c4.IsChecked, "Fourth didn't match!"), () => Assert.AreEqual(t5.GetIsChecked(), c5.IsChecked, "Fifth didn't match!")); }
public virtual void WrapInTheDesiredType() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems(); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.IsInstanceOfType(converter.Convert(item, typeof(double), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Thickness), "15", DefaultCulture), typeof(Thickness)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Point), "15", DefaultCulture), typeof(Point)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Rect), "15", DefaultCulture), typeof(Rect)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(Size), "15", DefaultCulture), typeof(Size)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(GridLength), "15", DefaultCulture), typeof(GridLength)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(int), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(float), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(decimal), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, typeof(string), "15", DefaultCulture), typeof(double)), () => Assert.IsInstanceOfType(converter.Convert(item, null, "15", DefaultCulture), typeof(double))); }
public virtual void CultureInfoIsRespected() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems() .Item("fourth"); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), "15.0", new CultureInfo("en-US")), "en-US"), () => Assert.AreEqual(10.0, converter.Convert(item, typeof(double), "5,0", new CultureInfo("vi-VN")), "vi-VN")); }
public virtual void InvalidConverterParameters() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems() .Item("fourth"); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), null, DefaultCulture), "(null)"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), string.Empty, DefaultCulture), "(empty)"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), 10, DefaultCulture), "10"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), 10.0, DefaultCulture), "10.0"), () => Assert.AreEqual(0.0, converter.Convert(item, typeof(double), "foo", DefaultCulture), "foo")); }
public virtual void ConverterParameterDefinesIndent() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems() .Item("fourth"); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), "15", DefaultCulture), "15"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), "15.0", DefaultCulture), "15.0"), () => Assert.AreEqual(30.0, converter.Convert(item, typeof(double), null, DefaultCulture), "(null)"), () => Assert.AreEqual(2.0, converter.Convert(item, typeof(double), "1", DefaultCulture), "1"), () => Assert.AreEqual(10.0, converter.Convert(item, typeof(double), "5", DefaultCulture), "5")); }
public virtual void Indentation() { TreeViewItem first, second, third, fourth; TreeView view = new TreeViewBuilder() .Items("first").Expand().Named(out first) .Items("second").Expand().Named(out second) .Item("third").Named(out third) .EndItems() .EndItems() .Item("fourth").Named(out fourth); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => Assert.AreEqual(0.0, converter.Convert(first, typeof(double), "15", DefaultCulture), "first should not be indented!"), () => Assert.AreEqual(15.0, converter.Convert(second, typeof(double), "15", DefaultCulture), "second should be indented once!"), () => Assert.AreEqual(30.0, converter.Convert(third, typeof(double), "15", DefaultCulture), "third should be indented twice!"), () => Assert.AreEqual(0.0, converter.Convert(fourth, typeof(double), "15", DefaultCulture), "fourth should not be indented!")); }
public virtual void WrapIndentOnTheLeft() { TreeViewItem item; TreeView view = new TreeViewBuilder() .Items("first").Expand() .Items("second").Expand() .Item("third").Named(out item) .EndItems() .EndItems(); TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); TestAsync( view, () => { Thickness value = (Thickness)converter.Convert(item, typeof(Thickness), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Left, "Thickness.Left should be non-zero!"); Assert.AreEqual(0.0, value.Right, "Thickness.Right should be zero!"); Assert.AreEqual(0.0, value.Top, "Thickness.Top should be zero!"); Assert.AreEqual(0.0, value.Bottom, "Thickness.Bottom should be zero!"); }, () => { Point value = (Point)converter.Convert(item, typeof(Point), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.X, "Point.X should be non-zero!"); Assert.AreEqual(0.0, value.Y, "Point.Y should be zero!"); }, () => { Rect value = (Rect)converter.Convert(item, typeof(Rect), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Left, "Rect.Left should be non-zero!"); Assert.AreEqual(0.0, value.Width, "Rect.Width should be zero!"); Assert.AreEqual(0.0, value.Top, "Rect.Top should be zero!"); Assert.AreEqual(0.0, value.Height, "Rect.Height should be zero!"); }, () => { Size value = (Size)converter.Convert(item, typeof(Size), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Width, "Size.Width should be non-zero!"); Assert.AreEqual(0.0, value.Height, "Size.Height should be zero!"); }, () => { GridLength value = (GridLength)converter.Convert(item, typeof(GridLength), "15", DefaultCulture); Assert.AreNotEqual(0.0, value.Value, "GridLength.Value should be non-zero!"); Assert.IsTrue(value.IsAbsolute, "GridLength should be absolute!"); }); }
public virtual void GetItemsHostForTreeViewItem() { TreeViewItem item; TreeView control = new TreeViewBuilder() .Items("first").Named(out item).Expand() .Item("a") .Item("b") .Item("c") .EndItems() .Item("d"); Panel host = null; TestAsync( control, () => host = item.GetItemsHost(), () => Assert.IsNotNull(host, "ItemsHost not found!")); }
public virtual void GetItemsAndContainersDoesNotRecurse() { TreeView view = new TreeViewBuilder() .Items("first").Expand() .Item("a") .Item("b") .Item("c") .EndItems() .Items("second").Expand() .Item("1") .Item("2") .Item("3") .EndItems(); ItemsControl control = view as ItemsControl; TestAsync( control, () => Assert.AreEqual(2, control.GetItemsAndContainers<TreeViewItem>().Count(), "Only expecting two containers!")); }