| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- // -----------------------------------------------------------------------
- // <copyright file="DecoratorTests.cs" company="Steven Kirk">
- // Copyright 2013 MIT Licence. See licence.md for more information.
- // </copyright>
- // -----------------------------------------------------------------------
- namespace Perspex.Controls.UnitTests
- {
- using System.Collections.Specialized;
- using System.Linq;
- using Xunit;
- public class DecoratorTests
- {
- [Fact]
- public void Setting_Content_Should_Set_Child_Controls_Parent()
- {
- var decorator = new Decorator();
- var child = new Control();
- decorator.Child = child;
- Assert.Equal(child.Parent, decorator);
- Assert.Equal(((ILogical)child).LogicalParent, decorator);
- }
- [Fact]
- public void Clearing_Content_Should_Clear_Child_Controls_Parent()
- {
- var decorator = new Decorator();
- var child = new Control();
- decorator.Child = child;
- decorator.Child = null;
- Assert.Null(child.Parent);
- Assert.Null(((ILogical)child).LogicalParent);
- }
- [Fact]
- public void Content_Control_Should_Appear_In_LogicalChildren()
- {
- var decorator = new Decorator();
- var child = new Control();
- decorator.Child = child;
- Assert.Equal(new[] { child }, ((ILogical)decorator).LogicalChildren.ToList());
- }
- [Fact]
- public void Clearing_Content_Should_Remove_From_LogicalChildren()
- {
- var decorator = new Decorator();
- var child = new Control();
- decorator.Child = child;
- decorator.Child = null;
- Assert.Equal(new ILogical[0], ((ILogical)decorator).LogicalChildren.ToList());
- }
- [Fact]
- public void Setting_Content_Should_Fire_LogicalChildren_CollectionChanged()
- {
- var decorator = new Decorator();
- var child = new Control();
- var called = false;
- ((ILogical)decorator).LogicalChildren.CollectionChanged += (s, e) =>
- called = e.Action == NotifyCollectionChangedAction.Add;
- decorator.Child = child;
- Assert.True(called);
- }
- [Fact]
- public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
- {
- var decorator = new Decorator();
- var child = new Control();
- var called = false;
- decorator.Child = child;
- ((ILogical)decorator).LogicalChildren.CollectionChanged += (s, e) =>
- called = e.Action == NotifyCollectionChangedAction.Remove;
- decorator.Child = null;
- Assert.True(called);
- }
- [Fact]
- public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
- {
- var decorator = new Decorator();
- var child1 = new Control();
- var child2 = new Control();
- var called = false;
- decorator.Child = child1;
- ((ILogical)decorator).LogicalChildren.CollectionChanged += (s, e) => called = true;
- decorator.Child = child2;
- Assert.True(called);
- }
- [Fact]
- public void Measure_Should_Return_Padding_When_No_Child_Present()
- {
- var target = new Decorator
- {
- Padding = new Thickness(8),
- };
- target.Measure(new Size(100, 100));
- Assert.Equal(new Size(16, 16), target.DesiredSize);
- }
- }
- }
|