NotificationsTests.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System.Linq;
  2. using Avalonia.Controls.Notifications;
  3. using Avalonia.UnitTests;
  4. using Xunit;
  5. using Notification = Avalonia.Controls.Notifications.Notification;
  6. namespace Avalonia.Controls.UnitTests
  7. {
  8. public class WindowNotificationManagerTests : ScopedTestBase
  9. {
  10. [Fact]
  11. public void Show_Notifications_With_Same_String()
  12. {
  13. WindowNotificationManager manager = new();
  14. manager.Show("Notification text");
  15. manager.Show("Notification text");
  16. manager.Show("Notification text");
  17. Assert.Equal(3, manager.Notifications.Count());
  18. }
  19. [Fact]
  20. public void Show_And_Close_Notification()
  21. {
  22. WindowNotificationManager manager = new();
  23. manager.Show("Notification text");
  24. Assert.Equal(1, manager.Notifications.Count());
  25. manager.Close("Notification text");
  26. Assert.True(!manager.Notifications.Any(x => !x.IsClosing));
  27. }
  28. [Fact]
  29. public void Show_And_Close_All_Notifications()
  30. {
  31. WindowNotificationManager manager = new();
  32. manager.Show("Notification 1");
  33. manager.Show("Notification 2");
  34. Assert.Equal(2, manager.Notifications.Count());
  35. manager.CloseAll();
  36. Assert.True(!manager.Notifications.Any(x => !x.IsClosing));
  37. }
  38. }
  39. public class INotificationManagerTests : ScopedTestBase
  40. {
  41. [Fact]
  42. public void Show_Notifications_With_Same_Content()
  43. {
  44. INotificationManager manager = new WindowNotificationManager();
  45. Notification notification = new()
  46. {
  47. Message = "Notification text"
  48. };
  49. manager.Show(notification);
  50. manager.Show(notification);
  51. manager.Show(notification);
  52. Assert.Equal(3, ((WindowNotificationManager)manager).Notifications.Count());
  53. }
  54. [Fact]
  55. public void Show_And_Close_Notification()
  56. {
  57. INotificationManager manager = new WindowNotificationManager();
  58. Notification notification = new()
  59. {
  60. Message = "Notification text"
  61. };
  62. manager.Show(notification);
  63. Assert.Equal(1, ((WindowNotificationManager)manager).Notifications.Count());
  64. manager.Close(notification);
  65. Assert.True(!((WindowNotificationManager)manager).Notifications.Any(x => !x.IsClosing));
  66. }
  67. [Fact]
  68. public void Show_And_Close_All_Notifications()
  69. {
  70. INotificationManager manager = new WindowNotificationManager();
  71. Notification notification1 = new()
  72. {
  73. Message = "Notification text"
  74. };
  75. Notification notification2 = new()
  76. {
  77. Message = "Notification text"
  78. };
  79. manager.Show(notification1);
  80. manager.Show(notification2);
  81. Assert.Equal(2, ((WindowNotificationManager)manager).Notifications.Count());
  82. manager.CloseAll();
  83. Assert.True(!((WindowNotificationManager)manager).Notifications.Any(x => !x.IsClosing));
  84. }
  85. }
  86. }