ColorPickerTests.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. namespace Terminal.Gui.ViewsTests;
  2. /// <summary>
  3. /// Pure unit tests for <see cref="ColorPicker"/> that don't require Application.Driver or View context.
  4. /// These tests can run in parallel without interference.
  5. /// </summary>
  6. public class ColorPickerTests : UnitTests.Parallelizable.ParallelizableBase
  7. {
  8. [Fact]
  9. public void ColorPicker_ChangedEvent_Fires ()
  10. {
  11. Color newColor = default;
  12. var count = 0;
  13. var cp = new ColorPicker ();
  14. cp.ColorChanged += (s, e) =>
  15. {
  16. count++;
  17. newColor = e.Result;
  18. Assert.Equal (cp.SelectedColor, e.Result);
  19. };
  20. cp.SelectedColor = new (1, 2, 3);
  21. Assert.Equal (1, count);
  22. Assert.Equal (new (1, 2, 3), newColor);
  23. cp.SelectedColor = new (2, 3, 4);
  24. Assert.Equal (2, count);
  25. Assert.Equal (new (2, 3, 4), newColor);
  26. // Set to same value
  27. cp.SelectedColor = new (2, 3, 4);
  28. // Should have no effect
  29. Assert.Equal (2, count);
  30. }
  31. }