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 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 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 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 ZeroIfNoTreeViewItem() { TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); Assert.AreEqual(0.0, converter.Convert(null, typeof(double), null, null)); }
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 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 ZeroIfNoTreeViewItem() { TreeViewItemIndentationConverter converter = new TreeViewItemIndentationConverter(); Assert.AreEqual(0.0, converter.Convert(null, typeof(double), null, null)); }