FrameViewTests.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.Equal (LineStyle.Single, fv.BorderStyle);
  23. fv = new FrameView ("Test");
  24. Assert.Equal ("Test", fv.Title);
  25. Assert.Equal (string.Empty, fv.Text);
  26. Assert.Equal (LineStyle.Single, fv.BorderStyle);
  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. fv.BeginInit ();
  31. fv.EndInit ();
  32. Assert.Equal (LineStyle.Single, fv.BorderStyle);
  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. Application.Top.Add (fv);
  43. Application.Begin (Application.Top);
  44. Assert.Equal (new Rect (0, 0, 0, 0), fv.Frame);
  45. TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
  46. fv.Height = 5;
  47. fv.Width = 5;
  48. Assert.Equal (new Rect (0, 0, 5, 5), fv.Frame);
  49. Application.Refresh ();
  50. TestHelpers.AssertDriverContentsWithFrameAre (@"
  51. ┌───┐
  52. │ │
  53. │ │
  54. │ │
  55. └───┘", output);
  56. fv.X = 1;
  57. fv.Y = 2;
  58. Assert.Equal (new Rect (1, 2, 5, 5), fv.Frame);
  59. Application.Refresh ();
  60. TestHelpers.AssertDriverContentsWithFrameAre (@"
  61. ┌───┐
  62. │ │
  63. │ │
  64. │ │
  65. └───┘", output);
  66. fv.X = -1;
  67. fv.Y = -2;
  68. Assert.Equal (new Rect (-1, -2, 5, 5), fv.Frame);
  69. Application.Refresh ();
  70. TestHelpers.AssertDriverContentsWithFrameAre (@"
  71. ───┘", output);
  72. fv.X = 7;
  73. fv.Y = 8;
  74. Assert.Equal (new Rect (7, 8, 5, 5), fv.Frame);
  75. Application.Refresh ();
  76. TestHelpers.AssertDriverContentsWithFrameAre (@"
  77. ┌──
  78. │ ", output);
  79. }
  80. }
  81. }