FrameViewTests.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Microsoft.VisualStudio.TestPlatform.Utilities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Xunit;
  8. using Xunit.Abstractions;
  9. namespace Terminal.Gui.ViewsTests {
  10. public class FrameViewTests {
  11. readonly ITestOutputHelper output;
  12. public FrameViewTests (ITestOutputHelper output)
  13. {
  14. this.output = output;
  15. }
  16. [Fact]
  17. public void Constuctors_Defaults ()
  18. {
  19. var fv = new FrameView ();
  20. Assert.Equal (string.Empty, fv.Title);
  21. Assert.Equal (string.Empty, fv.Text);
  22. Assert.NotNull (fv.Border);
  23. fv = new FrameView ("Test");
  24. Assert.Equal ("Test", fv.Title);
  25. Assert.Equal (string.Empty, fv.Text);
  26. Assert.NotNull (fv.Border);
  27. fv = new FrameView (new Rect (1, 2, 10, 20), "Test");
  28. Assert.Equal ("Test", fv.Title);
  29. Assert.Equal (string.Empty, fv.Text);
  30. Assert.NotNull (fv.Border);
  31. fv.BeginInit ();
  32. fv.EndInit ();
  33. Assert.Equal (new Rect (1, 2, 10, 20), fv.Frame);
  34. }
  35. [Fact, AutoInitShutdown]
  36. public void Draw_Defaults ()
  37. {
  38. ((FakeDriver)Application.Driver).SetBufferSize (10, 10);
  39. var fv = new FrameView ();
  40. Assert.Equal (string.Empty, fv.Title);
  41. Assert.Equal (string.Empty, fv.Text);
  42. Assert.NotNull (fv.Border);
  43. Application.Top.Add (fv);
  44. Application.Begin (Application.Top);
  45. Assert.Equal (new Rect (0, 0, 0, 0), fv.Frame);
  46. TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
  47. fv.Height = 5;
  48. fv.Width = 5;
  49. Assert.Equal (new Rect (0, 0, 5, 5), fv.Frame);
  50. Application.Refresh ();
  51. TestHelpers.AssertDriverContentsWithFrameAre (@"
  52. ┌───┐
  53. │ │
  54. │ │
  55. │ │
  56. └───┘", output);
  57. fv.X = 1;
  58. fv.Y = 2;
  59. Assert.Equal (new Rect (1, 2, 5, 5), fv.Frame);
  60. Application.Refresh ();
  61. TestHelpers.AssertDriverContentsWithFrameAre (@"
  62. ┌───┐
  63. │ │
  64. │ │
  65. │ │
  66. └───┘", output);
  67. fv.X = -1;
  68. fv.Y = -2;
  69. Assert.Equal (new Rect (-1, -2, 5, 5), fv.Frame);
  70. Application.Refresh ();
  71. TestHelpers.AssertDriverContentsWithFrameAre (@"
  72. ───┘", output);
  73. fv.X = 7;
  74. fv.Y = 8;
  75. Assert.Equal (new Rect (7, 8, 5, 5), fv.Frame);
  76. Application.Refresh ();
  77. TestHelpers.AssertDriverContentsWithFrameAre (@"
  78. ┌──
  79. │ ", output);
  80. }
  81. }
  82. }