ControlTests.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Moq;
  5. using Perspex.Layout;
  6. using Perspex.Platform;
  7. using Perspex.Rendering;
  8. using Perspex.Styling;
  9. using Xunit;
  10. namespace Perspex.Controls.UnitTests
  11. {
  12. public class ControlTests
  13. {
  14. [Fact]
  15. public void Classes_Should_Initially_Be_Empty()
  16. {
  17. var target = new Control();
  18. Assert.Equal(0, target.Classes.Count);
  19. }
  20. [Fact]
  21. public void Adding_Control_To_IRenderRoot_Should_Style_Control()
  22. {
  23. using (PerspexLocator.EnterScope())
  24. {
  25. var root = new TestRoot();
  26. var target = new Control();
  27. var styler = new Mock<IStyler>();
  28. PerspexLocator.CurrentMutable.Bind<IStyler>().ToConstant(styler.Object);
  29. root.Child = target;
  30. styler.Verify(x => x.ApplyStyles(target), Times.Once());
  31. }
  32. }
  33. [Fact]
  34. public void Adding_Tree_To_ILayoutRoot_Should_Style_Controls()
  35. {
  36. using (PerspexLocator.EnterScope())
  37. {
  38. var root = new TestRoot();
  39. var parent = new Border();
  40. var child = new Border();
  41. var grandchild = new Control();
  42. var styler = new Mock<IStyler>();
  43. PerspexLocator.CurrentMutable.Bind<IStyler>().ToConstant(styler.Object);
  44. parent.Child = child;
  45. child.Child = grandchild;
  46. styler.Verify(x => x.ApplyStyles(It.IsAny<IStyleable>()), Times.Never());
  47. root.Child = parent;
  48. styler.Verify(x => x.ApplyStyles(parent), Times.Once());
  49. styler.Verify(x => x.ApplyStyles(child), Times.Once());
  50. styler.Verify(x => x.ApplyStyles(grandchild), Times.Once());
  51. }
  52. }
  53. private class TestRoot : Decorator, ILayoutRoot, IRenderRoot
  54. {
  55. public Size ClientSize
  56. {
  57. get { throw new NotImplementedException(); }
  58. }
  59. public ILayoutManager LayoutManager
  60. {
  61. get { throw new NotImplementedException(); }
  62. }
  63. public IRenderTarget RenderTarget
  64. {
  65. get { throw new NotImplementedException(); }
  66. }
  67. public IRenderQueueManager RenderQueueManager
  68. {
  69. get { throw new NotImplementedException(); }
  70. }
  71. public Point TranslatePointToScreen(Point p)
  72. {
  73. throw new NotImplementedException();
  74. }
  75. }
  76. }
  77. }