Наследование: System.Windows.Controls.Control
Пример #1
0
        public void ArrangeAppliesTemplate()
        {
            ConcreteControl c = (ConcreteControl)XamlReader.Load(@"
<x:ConcreteControl	xmlns=""http://schemas.microsoft.com/client/2007""
					xmlns:x=""clr-namespace:MoonTest.System.Windows.Controls;assembly=moon-unit"">
	<x:ConcreteControl.Template>
		<ControlTemplate>
			<Grid />
		</ControlTemplate>
	</x:ConcreteControl.Template>
</x:ConcreteControl>");

            c.CallBaseArrangeOverride = false;
            c.CallBaseMeasureOverride = false;

            Assert.IsFalse(c.TemplateAppled, "#1");
            c.Methods.Clear();
            c.Arrange(new Rect(0, 0, 1000, 1000));
            Assert.IsTrue(c.TemplateAppled, "#2");

            Assert.AreEqual(3, c.Methods.Count, "#3");
            Assert.AreEqual(0, c.Methods.IndexOf("Template"), "No template");
            Assert.AreEqual(1, c.Methods.IndexOf("Measure"), "No measure");
            Assert.AreEqual(2, c.Methods.IndexOf("Arrange"), "No arrange");
        }
Пример #2
0
        public void OnNull()
        {
            ConcreteControl c = new ConcreteControl();

            Assert.Throws <ArgumentNullException> (delegate {
                c.OnGotFocus_(null);
            }, "OnGotFocus");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnLostFocus_(null);
            }, "LostFocus");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnKeyDown_(null);
            }, "OnKeyDown");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnKeyUp_(null);
            }, "OnKeyU");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnMouseEnter_(null);
            }, "OnMouseEnter");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnMouseLeave_(null);
            }, "OnMouseLeave");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnMouseMove_(null);
            }, "OnMouseMove");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnMouseLeftButtonDown_(null);
            }, "OnMouseLeftButtonDown");
            Assert.Throws <ArgumentNullException> (delegate {
                c.OnMouseLeftButtonUp_(null);
            }, "OnMouseLeftButtonUp");
        }
Пример #3
0
        public void DefaultStyleKeyTest_More()
        {
            ConcreteControl c = new ConcreteControl();

            Assert.IsNull(c.DefaultStyleKey_, "null");

            // and some working tests
            c.DefaultStyleKey_ = typeof(ConcreteControl);
            Assert.AreEqual(typeof(ConcreteControl), c.DefaultStyleKey_, "DefaultStyleKey");

            MoreConcreteControl mc = new MoreConcreteControl();

            mc.DefaultStyleKey_ = typeof(ConcreteControl);
            Assert.AreEqual(typeof(ConcreteControl), mc.DefaultStyleKey_, "DefaultStyleKey-Base");

            c = new ConcreteControl();
            c.DefaultStyleKey_ = typeof(MoreConcreteControl);
            Assert.AreEqual(typeof(MoreConcreteControl), c.DefaultStyleKey_, "DefaultStyleKey-Inherited");

            mc = new MoreConcreteControl();
            mc.DefaultStyleKey_ = typeof(SiblingControl);
            Assert.AreEqual(typeof(SiblingControl), mc.DefaultStyleKey_, "DefaultStyleKey-Sibling");

            mc = new MoreConcreteControl();
            Assert.Throws <ArgumentException> (delegate {
                mc.DefaultStyleKey_ = typeof(Control);
            }, "Control");
        }
Пример #4
0
        public void DefaultMethods()
        {
            ConcreteControl c = new ConcreteControl();

            CheckDefaultMethods(c);
            // Focus returns false and does not trigger [Get|Lost]Focus
            Assert.IsFalse(c.GotFocusCalled, "GotFocusCalled");
            Assert.IsFalse(c.LostFocusCalled, "LostFocusCalled");
        }
Пример #5
0
        public void GetTemplateChildTest()
        {
            ConcreteControl c = new ConcreteControl();

            Assert.Throws <ArgumentException> (delegate {
                c.GetTemplateChild_(null);
            }, "null");
            Assert.IsNull(c.GetTemplateChild_(String.Empty), "Empty");
        }
Пример #6
0
        public void ApplyTemplate()
        {
            ConcreteControl poker = new ConcreteControl();

            Assert.IsNull(poker.Template, "#1");
            Assert.IsNull(poker.Style);
            Assert.IsFalse(poker.ApplyTemplate(), "#2");
            Assert.IsNull(poker.Template, "#3");
            Assert.IsNull(poker.Style, "#4");
        }
Пример #7
0
        public void MeasureAppliesTemplate()
        {
            ConcreteControl c = new ConcreteControl {
                CallBaseArrangeOverride = false, CallBaseMeasureOverride = false
            };

            Assert.IsFalse(c.TemplateAppled, "#1");
            c.Measure(new Size(100, 100));
            Assert.IsFalse(c.TemplateAppled, "#2");
            c.ApplyTemplate();
            Assert.IsFalse(c.TemplateAppled, "#3");
        }
Пример #8
0
        public void DefaultStyleKeyTest_Null()
        {
            ConcreteControl c = new ConcreteControl();

            Assert.IsNull(c.DefaultStyleKey_, "null");

            // issue here is that we can't assign the current (null) value without an exception
            // but the PropertyChange logic is "smart" enough not to allow this...
            Assert.Throws <ArgumentException> (delegate {
                c.DefaultStyleKey_ = null;
            }, "null");

            // ... and guess what it's not part of the PropertyChange validation!
            c.SetValue(ConcreteControl.DefaultStyleKeyProperty_, null);
        }
Пример #9
0
        public void Events()
        {
            bool            changed = false;
            ConcreteControl c       = new ConcreteControl();

            c.IsEnabledChanged += delegate(object sender, DependencyPropertyChangedEventArgs e) {
                Assert.AreSame(c, sender, "sender");
                Assert.AreEqual(Control.IsEnabledProperty, e.Property, "IsEnabledProperty");
                Assert.IsFalse((bool)e.NewValue, "NewValue");
                Assert.IsTrue((bool)e.OldValue, "OldValue");
                changed = true;
            };
            c.IsEnabled = false;
            Assert.IsFalse(c.IsEnabled, "IsEnabled");
            Assert.IsFalse(changed, "Should be async");
        }
Пример #10
0
        public void InvalidValues()
        {
            ConcreteControl c = new ConcreteControl();

            Assert.Throws <ArgumentException>(() => {
                c.FontSize = -1;
            }, "#1");
            Assert.Throws <ArgumentException>(() => {
                c.FontSize = 0;
            }, "#2");
            c.FontSize = 1000000;

            c.Foreground = null;
            Assert.Throws <ArgumentException>(() => {
                c.FontFamily = null;
            }, "#3");
        }
Пример #11
0
        public void MeasureAppliesTemplate3()
        {
            ConcreteControl c = (ConcreteControl)XamlReader.Load(@"
<x:ConcreteControl	xmlns=""http://schemas.microsoft.com/client/2007""
					xmlns:x=""clr-namespace:MoonTest.System.Windows.Controls;assembly=moon-unit"">
	<x:ConcreteControl.Template>
		<ControlTemplate>
			<Grid />
		</ControlTemplate>
	</x:ConcreteControl.Template>
</x:ConcreteControl>");

            c.CallBaseArrangeOverride = false;
            c.CallBaseMeasureOverride = false;

            Assert.IsFalse(c.TemplateAppled, "#1");
            c.Measure(new Size(100, 100));
            Assert.IsTrue(c.TemplateAppled, "#3");
        }
Пример #12
0
        public void MultipleTemplatesInsideTemplates()
        {
            var template = (ControlTemplate)XamlReader.Load(@"
<ControlTemplate x:Name=""OuterTemplate""
  xmlns='http://schemas.microsoft.com/client/2007'
  xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <ContentControl x:Name=""InnerControl"">
        <ContentControl.Resources>
            <DataTemplate x:Name=""dataTemplate"">
                <Rectangle/>
            </DataTemplate>
            <ControlTemplate x:Name=""controlTemplate"">
                <ContentControl ContentTemplate=""{StaticResource dataTemplate}""/>
            </ControlTemplate>
        </ContentControl.Resources>
        <ContentControl.Template>
            <StaticResource ResourceKey=""controlTemplate""/>
        </ContentControl.Template>
    </ContentControl>
</ControlTemplate>
");
            var control  = new ConcreteControl();

            TestPanel.Children.Add(control);
            control.Template = template;
            control.UpdateLayout();

            Assert.VisualChildren(control, "#1",
                                  new VisualNode <ContentControl>("#1a",
                                                                  new VisualNode <ContentControl>("#1b",
                                                                                                  new VisualNode <ContentPresenter> ("#1c",
                                                                                                                                     new VisualNode <Rectangle> ("#1d")
                                                                                                                                     )
                                                                                                  )
                                                                  )
                                  );
        }
Пример #13
0
		public void Events ()
		{
			bool changed = false;
			ConcreteControl c = new ConcreteControl ();
			c.IsEnabledChanged += delegate (object sender, DependencyPropertyChangedEventArgs e) {
				Assert.AreSame (c, sender, "sender");
				Assert.AreEqual (Control.IsEnabledProperty, e.Property, "IsEnabledProperty");
				Assert.IsFalse ((bool) e.NewValue, "NewValue");
				Assert.IsTrue ((bool) e.OldValue, "OldValue");
				changed = true;
			};
			c.IsEnabled = false;
			Assert.IsFalse (c.IsEnabled, "IsEnabled");
			Assert.IsFalse (changed, "Should be async");
		}
Пример #14
0
		public void DefaultMethods ()
		{
			ConcreteControl c = new ConcreteControl ();
			CheckDefaultMethods (c);
			// Focus returns false and does not trigger [Get|Lost]Focus
			Assert.IsFalse (c.GotFocusCalled, "GotFocusCalled");
			Assert.IsFalse (c.LostFocusCalled, "LostFocusCalled");
		}
Пример #15
0
		public void InvalidValues()
		{
			ConcreteControl c = new ConcreteControl();
			Assert.Throws<ArgumentException>(() => {
				c.FontSize = -1;
			}, "#1");
			Assert.Throws<ArgumentException>(() => {
				c.FontSize = 0;
			}, "#2");
			c.FontSize = 1000000;

			c.Foreground = null;
			Assert.Throws<ArgumentException>(() => {
				c.FontFamily = null;
			}, "#3");
		}
Пример #16
0
		public void GetTemplateChildTest ()
		{
			ConcreteControl c = new ConcreteControl ();
			Assert.Throws<ArgumentException> (delegate {
				c.GetTemplateChild_ (null);
			}, "null");
			Assert.IsNull (c.GetTemplateChild_ (String.Empty), "Empty");
		}
Пример #17
0
		public void DefaultStyleKeyTest_More ()
		{
			ConcreteControl c = new ConcreteControl ();
			Assert.IsNull (c.DefaultStyleKey_, "null");

			// and some working tests
			c.DefaultStyleKey_ = typeof (ConcreteControl);
			Assert.AreEqual (typeof (ConcreteControl), c.DefaultStyleKey_, "DefaultStyleKey");

			MoreConcreteControl mc = new MoreConcreteControl ();
			mc.DefaultStyleKey_ = typeof (ConcreteControl);
			Assert.AreEqual (typeof (ConcreteControl), mc.DefaultStyleKey_, "DefaultStyleKey-Base");

			c = new ConcreteControl ();
			c.DefaultStyleKey_ = typeof (MoreConcreteControl);
			Assert.AreEqual (typeof (MoreConcreteControl), c.DefaultStyleKey_, "DefaultStyleKey-Inherited");

			mc = new MoreConcreteControl ();
			mc.DefaultStyleKey_ = typeof (SiblingControl);
			Assert.AreEqual (typeof (SiblingControl), mc.DefaultStyleKey_, "DefaultStyleKey-Sibling");

			mc = new MoreConcreteControl ();
			Assert.Throws<ArgumentException> (delegate {
				mc.DefaultStyleKey_ = typeof (Control);
			}, "Control");
		}
Пример #18
0
		public void DefaultStyleKeyTest_Null ()
		{
			ConcreteControl c = new ConcreteControl ();
			Assert.IsNull (c.DefaultStyleKey_, "null");

			// issue here is that we can't assign the current (null) value without an exception
			// but the PropertyChange logic is "smart" enough not to allow this...
			Assert.Throws<ArgumentException> (delegate {
				c.DefaultStyleKey_ = null;
			}, "null");

			// ... and guess what it's not part of the PropertyChange validation!
			c.SetValue (ConcreteControl.DefaultStyleKeyProperty_, null);
		}
Пример #19
0
		public void ApplyTemplate ()
		{
			ConcreteControl poker = new ConcreteControl ();
			Assert.IsNull (poker.Template, "#1");
			Assert.IsNull (poker.Style);
			Assert.IsFalse (poker.ApplyTemplate (), "#2");
			Assert.IsNull (poker.Template, "#3");
			Assert.IsNull (poker.Style, "#4");
		}
Пример #20
0
		public void OnNull ()
		{
			ConcreteControl c = new ConcreteControl ();
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnGotFocus_ (null);
			}, "OnGotFocus");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnLostFocus_ (null);
			}, "LostFocus");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnKeyDown_ (null);
			}, "OnKeyDown");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnKeyUp_ (null);
			}, "OnKeyU");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnMouseEnter_ (null);
			}, "OnMouseEnter");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnMouseLeave_ (null);
			}, "OnMouseLeave");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnMouseMove_ (null);
			}, "OnMouseMove");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnMouseLeftButtonDown_ (null);
			}, "OnMouseLeftButtonDown");
			Assert.Throws<ArgumentNullException> (delegate {
				c.OnMouseLeftButtonUp_ (null);
			}, "OnMouseLeftButtonUp");
		}
Пример #21
0
		public void MeasureAppliesTemplate ()
		{
			ConcreteControl c = new ConcreteControl { CallBaseArrangeOverride = false, CallBaseMeasureOverride = false };
			Assert.IsFalse (c.TemplateAppled, "#1");
			c.Measure (new Size (100, 100));
			Assert.IsFalse (c.TemplateAppled, "#2");
			c.ApplyTemplate ();
			Assert.IsFalse (c.TemplateAppled, "#3");
		}
Пример #22
0
		public void MultipleTemplatesInsideTemplates ()
		{
			var template = (ControlTemplate)XamlReader.Load(@"
<ControlTemplate x:Name=""OuterTemplate""
  xmlns='http://schemas.microsoft.com/client/2007'
  xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <ContentControl x:Name=""InnerControl"">
        <ContentControl.Resources>
            <DataTemplate x:Name=""dataTemplate"">
                <Rectangle/>
            </DataTemplate>
            <ControlTemplate x:Name=""controlTemplate"">
                <ContentControl ContentTemplate=""{StaticResource dataTemplate}""/>
            </ControlTemplate>
        </ContentControl.Resources>
        <ContentControl.Template>
            <StaticResource ResourceKey=""controlTemplate""/>
        </ContentControl.Template>
    </ContentControl>
</ControlTemplate>
");
			var control = new ConcreteControl();
			TestPanel.Children.Add(control);
			control.Template = template;
			control.UpdateLayout();

			Assert.VisualChildren(control, "#1",
				new VisualNode<ContentControl>("#1a",
					new VisualNode<ContentControl>("#1b",
						new VisualNode<ContentPresenter> ("#1c",
							new VisualNode<Rectangle> ("#1d")
						)
					)
				)
			);
		}