Inheritance: MonoBehaviour
        public void Negative_Margin_Should_Be_Respected()
        {
            TestControl target;
            var container = new Canvas
            {
                Width = 100,
                Height = 100,
                ClipToBounds = true,
                Children = new Controls.Controls
                {
                    new Border
                    {
                        Margin = new Thickness(100, 100, 0, 0),
                        Child = target = new TestControl
                        {
                            Width = 10,
                            Height = 10,
                            Margin = new Thickness(-100, -100, 0, 0),
                        }
                    }
                }
            };

            Render(container);

            Assert.True(target.Rendered);
        }
        public void Out_Of_Bounds_Control_Should_Not_Be_Rendered()
        {
            TestControl target;
            var container = new Canvas
            {
                Width = 100,
                Height = 100,
                ClipToBounds = true,
                Children = new Controls.Controls
                {
                    (target = new TestControl
                    {
                        Width = 10,
                        Height = 10,
                        ClipToBounds = true,
                        [Canvas.LeftProperty] = 110,
                        [Canvas.TopProperty] = 110,
                    })
                }
            };

            Render(container);

            Assert.False(target.Rendered);
        }
示例#3
0
        public void SmokeTestUserControl()
        {
            var target = new ReactiveUI.Winforms.ActivationForViewFetcher();
            using(var userControl = new TestControl())
            using (var parent = new TestForm()) {
                var userControlActivator = target.GetActivationForView(userControl);

                int userControlActivateCount = 0, userControlDeActivateCount = 0;
                userControlActivator.Subscribe(activated => {
                    if (activated) {
                        userControlActivateCount++;
                    } else {
                        userControlDeActivateCount++;
                    }
                });

                parent.Visible = true;
                parent.Controls.Add(userControl);

                userControl.Visible = true;
                Assert.Equal(1, userControlActivateCount);
                userControl.Visible = false;
                Assert.Equal(1, userControlDeActivateCount);

                userControl.Visible = true;
                Assert.Equal(2, userControlActivateCount);

                //closing the form deactivated the usercontrol
                parent.Close();
                Assert.Equal(2, userControlDeActivateCount);
            }
        }
 public void TestNormalSituation() {
     //
     TestControl x = new TestControl() { Name = "x" };
     TestControl ancestor = new TestControl() { Name = "ancestor" };
     x.AddChild( ancestor );
     TestControl a = new TestControl() { Name = "a" };
     ancestor.AddChild( a );
     TestControl aa = new TestControl() { Name = "aa" };
     a.AddChild( aa );
     TestControl aaa = new TestControl() { Name = "aaa" };
     aa.AddChild( aaa );
     TestControl b = new TestControl() { Name = "b" };
     ancestor.AddChild( b );
     Assert.AreEqual(Control.FindCommonAncestor(a, b), ancestor);
     Assert.AreEqual(Control.FindCommonAncestor(aa, b), ancestor);
     TestControl bb = new TestControl() { Name = "bb" };
     b.AddChild( bb );
     Assert.AreEqual(Control.FindCommonAncestor(aa, bb), ancestor);
     //
     Assert.AreEqual(Control.FindCommonAncestor(a, aa), a);
     Assert.AreEqual(Control.FindCommonAncestor(aa, ancestor), ancestor);
     Assert.AreEqual(Control.FindCommonAncestor(b, bb), b);
     Assert.AreEqual(Control.FindCommonAncestor(bb, ancestor), ancestor);
     //
     Assert.AreEqual(Control.FindCommonAncestor(aaa, ancestor), ancestor);
 }
        public void Validated_Direct_Property_Receives_BindingNotifications()
        {
            var source = new ValidationTestModel { MustBePositive = 5 };
            var target = new TestControl
            {
                DataContext = source,
            };

            target.Bind(
                TestControl.ValidatedDirectProperty,
                new Binding(nameof(source.MustBePositive), BindingMode.TwoWay));

            target.ValidatedDirect = 6;
            target.ValidatedDirect = -1;
            target.ValidatedDirect = 7;

            Assert.Equal(
                new[]
                {
                    new BindingNotification(5),
                    new BindingNotification(6),
                    new BindingNotification(new ArgumentOutOfRangeException("value"), BindingErrorType.DataValidationError),
                    new BindingNotification(7),
                },
                target.Notifications.AsEnumerable());
        }
 public void AddControlContentTwice()
 {
     var control = new TestControl();
     control.IsActive = false;
     Assert.AreEqual(false, control.IsActive);
     control.IsActive = true;
     Assert.AreEqual(false, control.IsActive);
 }
        public void Setting_IsSelected_Should_Add_Selected_Class()
        {
            var target = new TestControl();

            target.IsSelected = true;

            Assert.Equal(new[] { "selected" }, target.Classes);
        }
示例#8
0
        public void CanFetchActivatorForControl()
        {
            var control = new TestControl();
            var target = new ReactiveUI.Winforms.ActivationForViewFetcher();
            var activator = target.GetActivationForView(control);

            Assert.NotNull(activator);
        }
示例#9
0
        public void Arrange_With_IsMeasureValid_False_Calls_Measure()
        {
            var target = new TestControl();

            Assert.False(target.IsMeasureValid);
            target.Arrange(new Rect(0, 0, 120, 120));
            Assert.True(target.IsMeasureValid);
            Assert.Equal(new Size(120, 120), target.MeasureConstraint);
        }
示例#10
0
        public void Clearing_IsSelected_Should_Remove_Selected_Class()
        {
            var target = new TestControl();

            target.IsSelected = true;
            target.IsSelected = false;

            Assert.Empty(target.Classes);
        }
示例#11
0
        public void LogicalParent_Should_Be_Set_To_Parent()
        {
            var parent = new Decorator();
            var target = new TestControl();

            parent.Child = target;

            Assert.Equal(parent, target.InheritanceParent);
        }
示例#12
0
        public void LogicalParent_Should_Be_Cleared_When_Removed_From_Parent()
        {
            var parent = new Decorator();
            var target = new TestControl();

            parent.Child = target;
            parent.Child = null;

            Assert.Null(target.InheritanceParent);
        }
示例#13
0
        public void Setting_Parent_Should_Also_Set_InheritanceParent()
        {
            var parent = new Decorator();
            var target = new TestControl();

            parent.Child = target;

            Assert.Equal(parent, target.Parent);
            Assert.Equal(parent, target.InheritanceParent);
        }
示例#14
0
        public void CanFetchActivatorForControl()
        {
            var control = new TestControl();
            var target = new ActivationForViewFetcher();
            var activator = target.GetActivationForView(control);

            Assert.NotNull(activator);
            Assert.NotNull(activator.Item1);
            Assert.NotNull(activator.Item2);
        }
        public void Non_Validated_Property_Does_Not_Receive_BindingNotifications()
        {
            var source = new ValidationTestModel { MustBePositive = 5 };
            var target = new TestControl
            {
                DataContext = source,
                [!TestControl.NonValidatedProperty] = new Binding(nameof(source.MustBePositive)),
            };

            Assert.Empty(target.Notifications);
        }
示例#16
0
        public void InheritanceParent_Should_Be_Cleared_When_Removed_From_Parent_When_Has_Different_InheritanceParent()
        {
            var parent = new Decorator();
            var inheritanceParent = new Decorator();
            var target = new TestControl();

            ((ISetInheritanceParent)target).SetParent(inheritanceParent);
            parent.Child = target;
            parent.Child = null;

            Assert.Null(target.InheritanceParent);
        }
示例#17
0
 public void TestRootCanvasIsCommonAncestor() {
     TestControl a = new TestControl();
     TestControl b = new TestControl();
     TestControl aa = new TestControl();
     a.AddChild(aa);
     TestControl bb = new TestControl();
     b.AddChild(bb);
     Control commonAncestor = Control.FindCommonAncestor(aa, bb);
     Control commonAncestor2 = Control.FindCommonAncestor(bb, aa);
     Assert.IsNull(commonAncestor);
     Assert.IsNull(commonAncestor2);
 }
示例#18
0
        public void Setting_Parent_Should_Not_Set_InheritanceParent_If_Already_Set()
        {
            var parent = new Decorator();
            var inheritanceParent = new Decorator();
            var target = new TestControl();

            ((ISetInheritanceParent)target).SetParent(inheritanceParent);
            parent.Child = target;

            Assert.Equal(parent, target.Parent);
            Assert.Equal(inheritanceParent, target.InheritanceParent);
        }
        public void Content_Can_Be_Larger_Than_Viewport()
        {
            TestControl content;
            var target = new ScrollContentPresenter
            {
                Content = (content = new TestControl()),
            };

            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            Assert.Equal(new Rect(0, 0, 150, 150), content.Bounds);
        }
示例#20
0
        public void Setting_IsSelected_Should_Raise_IsSelectedChangedEvent()
        {
            var target = new TestControl();
            var raised = false;

            target.AddHandler(
                SelectingItemsControl.IsSelectedChangedEvent,
                (s, e) => raised = true);

            target.IsSelected = true;

            Assert.True(raised);
        }
示例#21
0
        public void Margin_Should_Be_Subtracted_From_Arrange_FinalSize()
        {
            var target = new TestControl
            {
                Width = 100,
                Height = 100,
                Margin = new Thickness(8),
            };

            target.Measure(Size.Infinity);
            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(new Size(100, 100), target.ArrangeFinalSize);
        }
示例#22
0
文件: MainForm.cs 项目: mono/gert
	void OnSelectedIndexChanged (object sender, EventArgs e)
	{
		TabPage page = ((TabControl) sender).SelectedTab;
		if (page == _tabPage2) {
			_control = new TestControl ();
			_control.Dock = DockStyle.Fill;
			_tabPage2.Controls.Clear ();
			_tabPage2.Controls.Add (_control);
		} else {
			if (_control != null)
				_control.Dispose ();
			_control = null;
		}
	}
示例#23
0
        public void ArrangeOverride_Receives_Requested_Size_When_Arranged_To_DesiredSize()
        {
            var target = new TestControl
            {
                MeasureResult = new Size(100, 100),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(8),
            };

            target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(new Size(100, 100), target.ArrangeFinalSize);
        }
示例#24
0
        public void ArrangeOverride_Receives_Available_Size_Minus_Margin_When_Stretched()
        {
            var target = new TestControl
            {
                MeasureResult = new Size(100, 100),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Margin = new Thickness(8),
            };

            target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            target.Arrange(new Rect(0, 0, 200, 200));

            Assert.Equal(new Size(184, 184), target.ArrangeFinalSize);
        }
        public void Passed_Validation_Should_Not_Add_Invalid_Pseudo_Class()
        {
            var control = new TestControl();
            var model = new ValidationTestModel { MustBePositive = 1 };
            var binding = new Binding
            {
                Path = nameof(model.MustBePositive),
                Mode = BindingMode.TwoWay,
                EnableValidation = true,
            };

            control.Bind(TestControl.ValidationTestProperty, binding);
            control.DataContext = model;
            Assert.DoesNotContain(control.Classes, x => x == ":invalid");
        }
        public void Enabled_Validation_Should_Trigger_Validation_Change_On_Exception()
        {
            var source = new ValidationTestModel { MustBePositive = 5 };
            var target = new TestControl { DataContext = source };
            var binding = new Binding
            {
                Path = nameof(source.MustBePositive),
                Mode = BindingMode.TwoWay,
                EnableValidation = true,
            };

            target.Bind(TestControl.ValidationTestProperty, binding);

            target.ValidationTest = -5;
            Assert.False(target.ValidationStatus.IsValid);
        }
示例#27
0
文件: MainForm.cs 项目: mono/gert
	public MainForm ()
	{
		// 
		// _testControl
		// 
		_testControl = new TestControl ();
		_testControl.MouseEnter += new EventHandler (TestControl_MouseEnter);
		_testControl.MouseLeave += new EventHandler (TestControl_MouseLeave);
		Controls.Add (_testControl);
		// 
		// _resetButton
		//
		_resetButton = new Button ();
		_resetButton.Location = new Point (340, 8);
		_resetButton.Size = new Size (60, 20);
		_resetButton.Text = "Reset";
		_resetButton.Click += new EventHandler (ResetButton_Click);
		Controls.Add (_resetButton);
		// 
		// _eventsText
		// 
		_eventsText = new TextBox ();
		_eventsText.Dock = DockStyle.Bottom;
		_eventsText.Height = 200;
		_eventsText.Multiline = true;
		_eventsText.ScrollBars = ScrollBars.Vertical;
		Controls.Add (_eventsText);
		// 
		// MainForm
		// 
		ClientSize = new Size (400, 400);
		Location = new Point (200, 100);
		StartPosition = FormStartPosition.Manual;
		Text = "bug #323234";
		Load += new EventHandler (MainForm_Load);
	}
 public void InitializeAutoFields_PublicAutoElement_IsInitialized()
 {
     var control = new TestControl();
     _initializer.InitializeAutoFields(control);
     Assert.That(control.TxtName.GetType().Name, Is.EqualTo("WatElement"));
 }
 public void InitializeAutoFields_AutoElementWithCustomId_GivenIdIsUsed()
 {
     var control = new TestControl();
     _initializer.InitializeAutoFields(control);
     Assert.That(control.CustomId.ToString(), Is.StringContaining("custom_id"));
 }
 public void InitializeAutoFields_AutoControl_IsInitialized()
 {
     var control = new TestControl();
     _initializer.InitializeAutoFields(control);
     Assert.That(control.TopMenu.GetControlElement().GetType().Name, Is.EqualTo("WatElement"));
 }
示例#31
0
        public void Selected_Class_Should_Not_Initially_Be_Added()
        {
            var target = new TestControl();

            Assert.Empty(target.Classes);
        }
示例#32
0
 // Use this for initialization
 void Start()
 {
     m_sm = new TestControl();
     m_sm.Start();
 }
示例#33
0
 public void TestControlStopSuiteExceptionIfDoesNotThrowOnFalse() => TestControl.StopSuiteIf("false");
示例#34
0
 public void TestControlStopSuiteExceptionIfThrowsOnNonBool() => TestControl.StopSuiteIf("$ok");
示例#35
0
 public void TestControlStopSuiteExceptionIfThrowsOnTrue() => TestControl.StopSuiteIf("true");
示例#36
0
 public void TestControlStopTestExceptionIfNotDoesNotThrowOnTrue() => TestControl.StopTestIfNot("true");
示例#37
0
 public void TestControlStopTestExceptionIfNotThrowsOnFalse() => TestControl.StopTestIfNot("false");
示例#38
0
        public void HttpProxy_Multi_ConcurrentUse_Success(bool manualConfig)
        {
            const string MultiProxyConfig = "http://proxy-a.com http://proxy-b.com http://proxy-c.com";

            RemoteExecutor.Invoke(manualValue =>
            {
                bool manual = bool.Parse(manualValue);

                Uri requestUri  = new Uri("http://request.com");
                Uri firstProxy  = new Uri("http://proxy-a.com");
                Uri secondProxy = new Uri("http://proxy-b.com");
                Uri thirdProxy  = new Uri("http://proxy-c.com");

                TestControl.ResetAll();

                if (manual)
                {
                    FakeRegistry.WinInetProxySettings.Proxy = MultiProxyConfig;
                }
                else
                {
                    FakeRegistry.WinInetProxySettings.AutoConfigUrl = "http://dummy.com";
                }

                Assert.True(HttpWindowsProxy.TryCreate(out IWebProxy p));
                HttpWindowsProxy wp = Assert.IsType <HttpWindowsProxy>(p);

                if (!manual)
                {
                    // Now that HttpWindowsProxy has been constructed to use autoconfig,
                    // set Proxy which will be used by Fakes for all the per-URL calls.
                    FakeRegistry.WinInetProxySettings.Proxy = MultiProxyConfig;
                }

                MultiProxy multiA = wp.GetMultiProxy(requestUri);
                MultiProxy multiB = wp.GetMultiProxy(requestUri);

                // Assert first proxy is returned across all three methods.
                Assert.True(multiA.ReadNext(out Uri proxyA, out _));
                Assert.True(multiB.ReadNext(out Uri proxyB, out _));
                Assert.Equal(firstProxy, proxyA);
                Assert.Equal(firstProxy, proxyB);
                Assert.Equal(firstProxy, p.GetProxy(requestUri));

                // Assert second proxy is returned across all three methods.
                Assert.True(multiA.ReadNext(out proxyA, out _));
                Assert.True(multiB.ReadNext(out proxyB, out _));
                Assert.Equal(secondProxy, proxyA);
                Assert.Equal(secondProxy, proxyB);
                Assert.Equal(secondProxy, p.GetProxy(requestUri));

                // Assert third proxy is returned from multiA.
                Assert.True(multiA.ReadNext(out proxyA, out _));
                Assert.Equal(thirdProxy, proxyA);
                Assert.Equal(thirdProxy, p.GetProxy(requestUri));

                // Enumerating multiA once more should exhaust all of our proxies.
                // So, multiB, still on secondProxy, should now also be exhausted because
                // when it tries thirdProxy it will see it marked as failed.
                Assert.False(multiA.ReadNext(out proxyA, out _));
                Assert.False(multiB.ReadNext(out proxyB, out _));

                // GetProxy should now return the proxy closest to being turned back on, which should be firstProxy.
                Assert.Equal(firstProxy, p.GetProxy(requestUri));

                // Enumerating a new MultiProxy should again return the proxy closed to being turned back on, and no others.
                MultiProxy multiC = wp.GetMultiProxy(requestUri);
                Assert.True(multiC.ReadNext(out Uri proxyC, out _));
                Assert.Equal(firstProxy, proxyC);
                Assert.False(multiC.ReadNext(out proxyC, out _));
                return(RemoteExecutor.SuccessExitCode);
            }, manualConfig.ToString()).Dispose();
        }