public void TestBasicInvalidations() { var panel = new StackPanel(); var child = new StackPanel(); panel.Children.Add(child); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(panel, () => child.DependencyProperties.Set(ZIndexPropertyKey, 37)); }
public void TestBasicInvalidations() { // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(this, () => Font = new DummyFont()); Font = null; UIElementLayeringTests.TestMeasureInvalidation(this, () => Text = "New Text"); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => TextColor = new Color(1, 2, 3, 4)); }
public void TestBasicInvalidations() { // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(this, () => ScrollMode = ScrollingMode.InDepthHorizontal); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => Deceleration = 5.5f); UIElementLayeringTests.TestNoInvalidation(this, () => TouchScrollingEnabled = !TouchScrollingEnabled); UIElementLayeringTests.TestNoInvalidation(this, () => ScrollBarColor = new Color(1, 2, 3, 4)); UIElementLayeringTests.TestNoInvalidation(this, () => ScrollBarThickness = 34); }
public void TestBasicInvalidations() { var newButton = new Button(); // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(this, () => Content = newButton); var sameButton = newButton; // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => Content = sameButton); }
public void TestBasicInvalidations() { SizeToContent = true; // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => PressedImage = (SpriteFromTexture) new Sprite()); UIElementLayeringTests.TestNoInvalidation(this, () => NotPressedImage = (SpriteFromTexture) new Sprite()); SizeToContent = false; // - test the properties that are supposed to invalidate the object layout state UIElementLayeringTests.TestMeasureInvalidation(this, () => PressedImage = (SpriteFromTexture) new Sprite()); UIElementLayeringTests.TestMeasureInvalidation(this, () => NotPressedImage = (SpriteFromTexture) new Sprite()); }
public void TestBasicInvalidations() { var canvas = new Canvas(); var child = new Canvas(); canvas.Children.Add(child); // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0.1f, 0.2f, 0.3f))); UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(RelativePositionPropertyKey, new Vector3(1f, 2f, 3f))); UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(1f, 2f, 3f))); UIElementLayeringTests.TestMeasureInvalidation(canvas, () => child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(1f, 2f, 3f))); }
public void TestBasicInvalidations() { var grid = new UniformGrid { Rows = 2, Columns = 2, Layers = 2 }; var child = new UniformGrid(); grid.Children.Add(child); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(ColumnPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(RowPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(LayerPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(ColumnSpanPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(RowSpanPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(LayerSpanPropertyKey, 2)); }
public void TestAddRemoveHandler() { var testRoutedEvent = EventManager.RegisterRoutedEvent <RoutedEventArgs>("Test1", RoutingStrategy.Tunnel, typeof(UIElementLayeringTests)); var element = new UIElementLayeringTests(); // test for ArgumentNullException Assert.Throws <ArgumentNullException>(() => element.AddHandler <RoutedEventArgs>(null, TestDelegate2)); Assert.Throws <ArgumentNullException>(() => element.AddHandler(testRoutedEvent, null)); Assert.Throws <ArgumentNullException>(() => element.RemoveHandler <RoutedEventArgs>(null, TestDelegate2)); Assert.Throws <ArgumentNullException>(() => element.RemoveHandler(testRoutedEvent, null)); // test that adding and removing 2 times the same element does not throws any exceptions element.AddHandler(testRoutedEvent, TestDelegate2); element.AddHandler(testRoutedEvent, TestDelegate2); element.RemoveHandler(testRoutedEvent, TestDelegate2); element.RemoveHandler(testRoutedEvent, TestDelegate2); element.RemoveHandler(testRoutedEvent, TestDelegate2); }
public static void Main() { var uiElementTest = new UIElementLayeringTests(); uiElementTest.TestAll(); var panelTest = new PanelTests(); panelTest.TestAll(); var controlTest = new ControlTests(); controlTest.TestAll(); var stackPanelTest = new StackPanelTests(); stackPanelTest.TestAll(); var canvasTest = new CanvasTests(); canvasTest.TestAll(); var contentControlTest = new ContentControlTest(); contentControlTest.TestAll(); var eventManagerTest = new EventManagerTests(); eventManagerTest.TestAll(); var routedEventArgTest = new RoutedEventArgsTest(); routedEventArgTest.TestAll(); var uiElementEventTest = new UIElementEventTests(); uiElementEventTest.TestAll(); var gridTest = new GridTests(); gridTest.TestAll(); }
public void TestBasicInvalidations() { var source = new Sprite(); // ReSharper disable ImplicitlyCapturedClosure // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(this, () => StretchType = StretchType.None); UIElementLayeringTests.TestMeasureInvalidation(this, () => StretchDirection = StretchDirection.DownOnly); UIElementLayeringTests.TestMeasureInvalidation(this, () => Source = (SpriteFromTexture)source); UIElementLayeringTests.TestMeasureInvalidation(this, () => source.Region = new Rectangle(1, 2, 3, 4)); UIElementLayeringTests.TestMeasureInvalidation(this, () => source.Orientation = ImageOrientation.Rotated90); UIElementLayeringTests.TestMeasureInvalidation(this, () => source.Borders = Vector4.One); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => source.Region = new Rectangle(8, 9, 3, 4)); // if the size of the region does not change we avoid re-measuring UIElementLayeringTests.TestNoInvalidation(this, () => source.Orientation = ImageOrientation.Rotated90); // no changes UIElementLayeringTests.TestNoInvalidation(this, () => source.Borders = Vector4.One); // no changes // ReSharper restore ImplicitlyCapturedClosure }
public void TestBasicInvalidations() { var slider = new Slider(); // - test the properties that are supposed to invalidate the object layout state UIElementLayeringTests.TestMeasureInvalidation(slider, () => slider.Orientation = Orientation.Vertical); UIElementLayeringTests.TestMeasureInvalidation(slider, () => slider.TrackBackgroundImage = new UIImage()); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(slider, () => slider.AreTicksDisplayed = true); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.CanBeHitByUser = false); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.ShouldSnapToTicks = true); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.DrawLayerNumber = 60); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.Value = 0.5f); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.Step = 0.2f); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.Maximum = 0.2f); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.Minimum = 0.1f); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.TrackForegroundImage = new UIImage()); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.ThumbImage = new UIImage()); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.MouseOverThumbImage = new UIImage()); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.DependencyProperties.Set(Slider.TickImagePropertyKey, new UIImage())); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.TickOffset = new float()); UIElementLayeringTests.TestNoInvalidation(slider, () => slider.TrackStartingOffsets = new Vector2()); }
public void TestPropagateEvent() { // create a hierarchy of UIElements // (00) // | // (10) // / \ // (20) (21) // | / \ // (30) (31) (32) var element00 = new ContentControlTest(); var element10 = new StackPanel(); var element20 = new ContentControlTest(); var element21 = new StackPanel(); var element30 = new UIElementLayeringTests(); var element31 = new UIElementLayeringTests(); var element32 = new UIElementLayeringTests(); element00.Content = element10; element10.Children.Add(element20); element10.Children.Add(element21); element20.Content = element30; element21.Children.Add(element31); element21.Children.Add(element32); var elements = new List <UIElement> { element00, element10, element20, element21, element30, element31, element32 }; // create routed events var tunnelingEvent = EventManager.RegisterRoutedEvent <RoutedEventArgs>("TestTuneling", RoutingStrategy.Tunnel, typeof(UIElementLayeringTests)); var bubblingEvent = EventManager.RegisterRoutedEvent <RoutedEventArgs>("TestBubbling", RoutingStrategy.Bubble, typeof(UIElementLayeringTests)); var directEvent = EventManager.RegisterRoutedEvent <RoutedEventArgs>("TestDirect", RoutingStrategy.Direct, typeof(UIElementLayeringTests)); // test propagation direction, propagation bounds and sender values foreach (var uiElement in elements) { uiElement.AddHandler(tunnelingEvent, TestAddSenderToList); uiElement.AddHandler(bubblingEvent, TestAddSenderToList); uiElement.AddHandler(directEvent, TestAddSenderToList); } // tunneling test 1 senderList.Clear(); element20.RaiseEvent(new RoutedEventArgs(tunnelingEvent)); Assert.Equal(3, senderList.Count); Assert.Equal(element00, senderList[0]); Assert.Equal(element10, senderList[1]); Assert.Equal(element20, senderList[2]); // tunneling test 2 senderList.Clear(); element31.RaiseEvent(new RoutedEventArgs(tunnelingEvent)); Assert.Equal(4, senderList.Count); Assert.Equal(element00, senderList[0]); Assert.Equal(element10, senderList[1]); Assert.Equal(element21, senderList[2]); Assert.Equal(element31, senderList[3]); // direct test senderList.Clear(); element10.RaiseEvent(new RoutedEventArgs(directEvent)); Assert.Equal(1, senderList.Count); Assert.Equal(element10, senderList[0]); // tunneling test 1 senderList.Clear(); element30.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.Equal(4, senderList.Count); Assert.Equal(element30, senderList[0]); Assert.Equal(element20, senderList[1]); Assert.Equal(element10, senderList[2]); Assert.Equal(element00, senderList[3]); // tunneling test 2 senderList.Clear(); element20.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.Equal(3, senderList.Count); Assert.Equal(element20, senderList[0]); Assert.Equal(element10, senderList[1]); Assert.Equal(element00, senderList[2]); // test with another type of handler var eventMyTestHandler = EventManager.RegisterRoutedEvent <MyTestRoutedEventArgs>("TestMyTestHandler", RoutingStrategy.Direct, typeof(UIElementLayeringTests)); AddHandler(eventMyTestHandler, TestMyTestHandler); RaiseEvent(new MyTestRoutedEventArgs(eventMyTestHandler)); Assert.Equal(true, testMyTestHandlerCalled); // test Handled and EventHandledToo foreach (var uiElement in elements) { uiElement.RemoveHandler(bubblingEvent, TestAddSenderToList); uiElement.AddHandler(bubblingEvent, TestHandledHandler); } senderList.Clear(); element00.AddHandler(bubblingEvent, TestEventHandledHandler, true); element32.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.Equal(1, senderList.Count); Assert.Equal(element32, senderList[0]); Assert.Equal(true, testEventHandledTooCalled); // test class handlers basic working foreach (var uiElement in elements) { uiElement.RemoveHandler(bubblingEvent, TestHandledHandler); } EventManager.RegisterClassHandler(typeof(ContentControl), bubblingEvent, TestAddSenderToClassHandlerList); element30.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.Equal(2, classHandlerSenderList.Count); Assert.Equal(element20, classHandlerSenderList[0]); Assert.Equal(element00, classHandlerSenderList[1]); // test that class handlers are called before instance handlers + test handledEventToo for class handlers senderList.Clear(); classHandlerSenderList.Clear(); EventManager.RegisterClassHandler(typeof(ContentControl), bubblingEvent, TestClassHandlerHandled); EventManager.RegisterClassHandler(typeof(StackPanel), bubblingEvent, TestClassHandlerEventHandled, true); foreach (var uiElement in elements) { uiElement.AddHandler(bubblingEvent, TestAddSenderToList); } element20.RaiseEvent(new RoutedEventArgs(bubblingEvent)); Assert.Equal(1, classHandlerSenderList.Count); Assert.Equal(element20, classHandlerSenderList[0]); Assert.Equal(0, senderList.Count); Assert.Equal(true, testClassHandlerEventHandledTooCalled); }
public void TestBasicInvalidations() { // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => OverlayColor = new Color(1, 2, 3, 4)); UIElementLayeringTests.TestNoInvalidation(this, () => IsModal = !IsModal); }
public void TestBasicInvalidations() { // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => PressedImage = new UIImage()); UIElementLayeringTests.TestNoInvalidation(this, () => NotPressedImage = new UIImage()); }
public void TestBasicInvalidations() { // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestMeasureInvalidation(this, () => Padding = Thickness.UniformRectangle(23)); }
public void TestBasicInvalidations() { // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(this, () => ClickMode = ClickMode.Press); }