NavigationEventArgsTests.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Avalonia.UnitTests;
  2. using Xunit;
  3. namespace Avalonia.Controls.UnitTests;
  4. public class NavigationEventArgsTests
  5. {
  6. public class NavigatedToEventArgsTests : ScopedTestBase
  7. {
  8. [Fact]
  9. public void Properties_RoundTrip()
  10. {
  11. var prev = new ContentPage { Header = "Prev" };
  12. var args = new NavigatedToEventArgs(prev, NavigationType.Push);
  13. Assert.Same(prev, args.PreviousPage);
  14. Assert.Equal(NavigationType.Push, args.NavigationType);
  15. }
  16. [Fact]
  17. public void NullPreviousPage_IsAllowed()
  18. {
  19. var args = new NavigatedToEventArgs(null, NavigationType.PopToRoot);
  20. Assert.Null(args.PreviousPage);
  21. }
  22. }
  23. public class NavigatedFromEventArgsTests : ScopedTestBase
  24. {
  25. [Fact]
  26. public void Properties_RoundTrip()
  27. {
  28. var dest = new ContentPage { Header = "Dest" };
  29. var args = new NavigatedFromEventArgs(dest, NavigationType.Pop);
  30. Assert.Same(dest, args.DestinationPage);
  31. Assert.Equal(NavigationType.Pop, args.NavigationType);
  32. }
  33. }
  34. public class NavigatingFromEventArgsTests : ScopedTestBase
  35. {
  36. [Fact]
  37. public void Cancel_DefaultIsFalse()
  38. {
  39. var args = new NavigatingFromEventArgs(null, NavigationType.Push);
  40. Assert.False(args.Cancel);
  41. }
  42. [Fact]
  43. public void Cancel_CanBeSetTrue()
  44. {
  45. var args = new NavigatingFromEventArgs(null, NavigationType.Push) { Cancel = true };
  46. Assert.True(args.Cancel);
  47. }
  48. }
  49. public class NavigationEventArgsConstructionTests : ScopedTestBase
  50. {
  51. [Fact]
  52. public void Properties_RoundTrip()
  53. {
  54. var page = new ContentPage();
  55. var args = new NavigationEventArgs(page, NavigationType.Push);
  56. Assert.Same(page, args.Page);
  57. Assert.Equal(NavigationType.Push, args.NavigationType);
  58. }
  59. }
  60. public class ModalPushedEventArgsTests : ScopedTestBase
  61. {
  62. [Fact]
  63. public void Properties_RoundTrip()
  64. {
  65. var modal = new ContentPage();
  66. var args = new ModalPushedEventArgs(modal);
  67. Assert.Same(modal, args.Modal);
  68. }
  69. }
  70. public class ModalPoppedEventArgsTests : ScopedTestBase
  71. {
  72. [Fact]
  73. public void Properties_RoundTrip()
  74. {
  75. var modal = new ContentPage();
  76. var args = new ModalPoppedEventArgs(modal);
  77. Assert.Same(modal, args.Modal);
  78. }
  79. }
  80. public class PageSelectionChangedEventArgsTests : ScopedTestBase
  81. {
  82. [Fact]
  83. public void Properties_RoundTrip()
  84. {
  85. var prev = new ContentPage { Header = "Tab 1" };
  86. var current = new ContentPage { Header = "Tab 2" };
  87. var args = new PageSelectionChangedEventArgs(SelectingMultiPage.SelectionChangedEvent, prev, current);
  88. Assert.Same(prev, args.PreviousPage);
  89. Assert.Same(current, args.CurrentPage);
  90. }
  91. }
  92. public class NavigationTypeEnumTests : ScopedTestBase
  93. {
  94. [Fact]
  95. public void AllValuesAreDefined()
  96. {
  97. var values = System.Enum.GetValues<NavigationType>();
  98. Assert.Contains(NavigationType.Push, values);
  99. Assert.Contains(NavigationType.Pop, values);
  100. Assert.Contains(NavigationType.PopToRoot, values);
  101. Assert.Contains(NavigationType.Insert, values);
  102. Assert.Contains(NavigationType.Remove, values);
  103. Assert.Contains(NavigationType.Replace, values);
  104. }
  105. }
  106. }