diff --git a/Upgrading-Prism.md b/Upgrading-Prism.md index 4a59c81..cbc1e6b 100644 --- a/Upgrading-Prism.md +++ b/Upgrading-Prism.md @@ -38,7 +38,9 @@ As we all know, not everything is straight forward between these two XAML techno ### Changes * `Samples` folder renamed to `e2e` -* Prism.Dialogs - _See section for more info_ +* Prism.Dialogs + * _Various updates, see section before for more info_ +* `NavigationResult` returns the property `Success` instead of `Result` #### Dialogs @@ -112,6 +114,13 @@ As we all know, not everything is straight forward between these two XAML techno | RegionManagerRequestNavigateFixture.cs | RegionViewRegistryFixture.cs +### Future Feature Work To Add + +| Project | Class | +|-|-| +| Prism.Avalonia.Tests | ItemsControlRegionAdapterFixture +| Prism.Avalonia.Tests | SelectorRegionAdapterFixture + ## Upgrading from Prism 7.2 to 8.1 * Basis of comparison: [Prism Library v7.2.0.1422...v8.1.97](https://github.com/PrismLibrary/Prism/compare/v7.2.0.1422...v8.1.97) diff --git a/src/Prism.Avalonia/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs b/src/Prism.Avalonia/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs index ab3442f..94ffbd8 100644 --- a/src/Prism.Avalonia/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs +++ b/src/Prism.Avalonia/Navigation/Regions/Behaviors/ClearChildViewsRegionBehavior.cs @@ -64,12 +64,12 @@ private static void ClearChildViews(IRegion region) { foreach (var view in region.Views) { - AvaloniaObject dependencyObject = view as AvaloniaObject; - if (dependencyObject != null) + AvaloniaObject avaloniaObject = view as AvaloniaObject; + if (avaloniaObject != null) { - if (GetClearChildViews(dependencyObject)) + if (GetClearChildViews(avaloniaObject)) { - dependencyObject.ClearValue(RegionManager.RegionManagerProperty); + avaloniaObject.ClearValue(RegionManager.RegionManagerProperty); } } } diff --git a/src/Prism.Avalonia/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs b/src/Prism.Avalonia/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs index cbe7c72..da9a3c3 100644 --- a/src/Prism.Avalonia/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs +++ b/src/Prism.Avalonia/Navigation/Regions/Behaviors/RegionManagerRegistrationBehavior.cs @@ -53,6 +53,7 @@ public AvaloniaObject HostControl { throw new InvalidOperationException(Resources.HostControlCannotBeSetAfterAttach); } + hostControl = value; } } @@ -126,16 +127,16 @@ public void OnUpdatingRegions(object sender, EventArgs e) TryRegisterRegion(); } - private IRegionManager FindRegionManager(AvaloniaObject dependencyObject) + private IRegionManager FindRegionManager(AvaloniaObject avaloniaObject) { - var regionmanager = RegionManagerAccessor.GetRegionManager(dependencyObject); + var regionmanager = RegionManagerAccessor.GetRegionManager(avaloniaObject); if (regionmanager != null) { return regionmanager; } //TODO: this is should be ok in Avalonia. I have to test it - AvaloniaObject parent = ((dependencyObject as Visual)?.GetVisualParent() ?? null) as AvaloniaObject; + AvaloniaObject parent = ((avaloniaObject as Visual)?.GetVisualParent() ?? null) as AvaloniaObject; if (parent != null) { return FindRegionManager(parent); diff --git a/src/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs b/src/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs index 9fc909f..11cc9fe 100644 --- a/src/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs +++ b/src/Prism.Avalonia/Navigation/Regions/Behaviors/SelectorItemsSourceSyncBehavior.cs @@ -18,7 +18,7 @@ using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Data; -using System.Windows.Controls.Primitives; +using Avalonia.Controls.Primitives; namespace Prism.Navigation.Regions.Behaviors { diff --git a/src/Prism.Avalonia/Navigation/Regions/Region.cs b/src/Prism.Avalonia/Navigation/Regions/Region.cs index 7f68c5a..f445c3f 100644 --- a/src/Prism.Avalonia/Navigation/Regions/Region.cs +++ b/src/Prism.Avalonia/Navigation/Regions/Region.cs @@ -207,7 +207,7 @@ protected virtual ObservableCollection ItemMetadataCollection /// Adds a new view to the region. /// Adds a new view to the region. /// The view to add. - /// The that is set on the view if it is a . It will be the current region manager when using this overload. + /// The that is set on the view if it is a . It will be the current region manager when using this overload. public IRegionManager Add(string viewName) { var view = ContainerLocator.Container.Resolve(viewName); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/ExceptionExtensionsFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/ExceptionExtensionsFixture.cs deleted file mode 100644 index 29eecb5..0000000 --- a/tests/Avalonia/Prism.Avalonia.Tests/ExceptionExtensionsFixture.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using Xunit; - -namespace Prism.Avalonia.Tests -{ - public class ExceptionExtensionsFixture - { - [Fact] - // Note, this test cannot be run twice in the same test run, because the registeration is static - // and we're not supplying an 'Unregister' method - public void CanRegisterFrameworkExceptionTypes() - { - Assert.False(ExceptionExtensions.IsFrameworkExceptionRegistered(typeof(MockException))); - - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(MockException)); - - Assert.True(ExceptionExtensions.IsFrameworkExceptionRegistered(typeof(MockException))); - } - - [Fact] - public void CanGetRootException() - { - Exception caughtException = null; - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException1)); - - try - { - try - { - throw new RootException(); - } - catch (Exception ex) - { - - throw new FrameworkException1(ex); - } - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.NotNull(caughtException); - - Exception exception = caughtException.GetRootException(); - - Assert.IsType(exception); - } - - [Fact] - public void CanCompensateForInnerFrameworkExceptionType() - { - Exception caughtException = null; - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException2)); - - try - { - try - { - try - { - throw new RootException(); - } - catch (Exception ex) - { - - throw new FrameworkException2(ex); - } - } - catch (Exception ex) - { - - throw new NonFrameworkException(ex); - } - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.NotNull(caughtException); - - Exception exception = caughtException.GetRootException(); - Assert.IsType(exception); - } - - [Fact] - public void GetRootExceptionReturnsTopExceptionWhenNoUserExceptionFound() - { - Exception caughtException = null; - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException1)); - ExceptionExtensions.RegisterFrameworkExceptionType(typeof(FrameworkException2)); - - try - { - try - { - throw new FrameworkException1(null); - } - catch (Exception ex) - { - - throw new FrameworkException2(ex); - } - } - catch (Exception ex) - { - caughtException = ex; - } - - Assert.NotNull(caughtException); - - Exception exception = caughtException.GetRootException(); - Assert.IsType(exception); - } - - private class MockException : Exception - { - } - - private class FrameworkException2 : Exception - { - public FrameworkException2(Exception innerException) - : base("", innerException) - { - } - } - - private class FrameworkException1 : Exception - { - public FrameworkException1(Exception innerException) : base("", innerException) - { - } - } - - private class RootException : Exception - { - } - - private class NonFrameworkException : Exception - { - public NonFrameworkException(Exception innerException) - : base("", innerException) - { - } - } - } -} diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockDependencyObject.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockDependencyObject.cs index f55ae46..e069e3e 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockDependencyObject.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockDependencyObject.cs @@ -1,8 +1,9 @@ -using Avalonia; +using Avalonia; namespace Prism.Avalonia.Tests.Mocks { /// MockAvaloniaObject. + /// TODO: Rename to MockAvaloniaObject. public class MockDependencyObject : AvaloniaObject { } diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockPresentationRegion.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockPresentationRegion.cs index 00bebc8..b7b4ee4 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockPresentationRegion.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockPresentationRegion.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; namespace Prism.Avalonia.Tests.Mocks { @@ -11,6 +11,9 @@ public MockPresentationRegion() { Behaviors = new MockRegionBehaviorCollection(); } + + public IRegionManager Add(string viewName) => throw new NotImplementedException(); + public IRegionManager Add(object view) { MockViews.Items.Add(view); @@ -74,7 +77,7 @@ public object Context } } - public NavigationParameters NavigationParameters + public INavigationParameters NavigationParameters { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } @@ -83,11 +86,11 @@ public NavigationParameters NavigationParameters private string name; public string Name { - get { return this.name; } + get { return name; } set { - this.name = value; - this.OnPropertyChange("Name"); + name = value; + OnPropertyChange("Name"); } } @@ -95,10 +98,7 @@ public string Name public void OnPropertyChange(string propertyName) { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public bool Navigate(Uri source) @@ -111,7 +111,7 @@ public void RequestNavigate(Uri target, Action navigationCallb throw new NotImplementedException(); } - public void RequestNavigate(Uri target, Action navigationCallback, NavigationParameters navigationParameters) + public void RequestNavigate(Uri target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } @@ -127,7 +127,6 @@ public IRegionNavigationService NavigationService set { throw new System.NotImplementedException(); } } - public Comparison SortComparison { get diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegion.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegion.cs index ee326e6..5760933 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegion.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegion.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; namespace Prism.Avalonia.Tests.Mocks { @@ -26,7 +26,7 @@ public object Context set { throw new System.NotImplementedException(); } } - public NavigationParameters NavigationParameters + public INavigationParameters NavigationParameters { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } @@ -34,6 +34,8 @@ public NavigationParameters NavigationParameters public string Name { get; set; } + public IRegionManager Add(string viewName) => throw new NotImplementedException(); + public IRegionManager Add(object view) { this.views.Add(view); @@ -87,7 +89,7 @@ public void RequestNavigate(System.Uri target, System.Action n throw new System.NotImplementedException(); } - public void RequestNavigate(System.Uri target, System.Action navigationCallback, NavigationParameters navigationParameters) + public void RequestNavigate(System.Uri target, System.Action navigationCallback, INavigationParameters navigationParameters) { throw new System.NotImplementedException(); } diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionAdapter.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionAdapter.cs index 9c70515..5025720 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionAdapter.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionAdapter.cs @@ -1,4 +1,4 @@ -using Avalonia; +using Avalonia; namespace Prism.Avalonia.Tests.Mocks { diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionManager.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionManager.cs index 7a68b6a..8442fee 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionManager.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/MockRegionManager.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; namespace Prism.Avalonia.Tests.Mocks { @@ -33,7 +33,7 @@ public IRegionManager RegisterViewWithRegion(string regionName, Type viewType) throw new NotImplementedException(); } - public IRegionManager RegisterViewWithRegion(string regionName, Func getContentDelegate) + public IRegionManager RegisterViewWithRegion(string regionName, Func getContentDelegate) { throw new NotImplementedException(); } @@ -58,22 +58,22 @@ public void RequestNavigate(string regionName, string source) throw new NotImplementedException(); } - public void RequestNavigate(string regionName, Uri target, Action navigationCallback, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, Uri target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } - public void RequestNavigate(string regionName, string target, Action navigationCallback, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, string target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } - public void RequestNavigate(string regionName, Uri target, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, Uri target, INavigationParameters navigationParameters) { throw new NotImplementedException(); } - public void RequestNavigate(string regionName, string target, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, string target, INavigationParameters navigationParameters) { throw new NotImplementedException(); } diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/ViewModels/MockBindingsViewModel.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/ViewModels/MockBindingsViewModel.cs deleted file mode 100644 index 4338a08..0000000 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/ViewModels/MockBindingsViewModel.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.ObjectModel; -using Prism.Mvvm; - -namespace Prism.Avalonia.Tests.Mocks.ViewModels -{ - internal class MockBindingsViewModel : BindableBase - { - private int _mockProperty; - private int _listItemSelected; - private string _listItemText = string.Empty; - private ObservableCollection _listItems = new(); - - public int MockProperty - { - get => _mockProperty; - set => SetProperty(ref _mockProperty, value); - } - - public int ListItemSelected - { - get => _listItemSelected; - set - { - SetProperty(ref _listItemSelected, value); - - if (value == -1) - return; - - ListItemText = ListItems[ListItemSelected]; - } - } - - public string ListItemText - { - get => _listItemText; - set => SetProperty(ref _listItemText, value); - } - - public ObservableCollection ListItems - { - get => _listItems; - set => SetProperty(ref _listItems, value); - } - } -} diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/Views/MockBindingsView.axaml b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/Views/MockBindingsView.axaml deleted file mode 100644 index e69769f..0000000 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/Views/MockBindingsView.axaml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/Views/MockBindingsView.axaml.cs b/tests/Avalonia/Prism.Avalonia.Tests/Mocks/Views/MockBindingsView.axaml.cs deleted file mode 100644 index 04d3c14..0000000 --- a/tests/Avalonia/Prism.Avalonia.Tests/Mocks/Views/MockBindingsView.axaml.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Avalonia.Controls; -using Avalonia.Markup.Xaml; - -namespace Prism.Avalonia.Tests.Mocks.Views -{ - public partial class MockBindingsView : UserControl - { - public MockBindingsView() - { - InitializeComponent(); - } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); - } - } -} diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Prism.Avalonia.Tests.csproj b/tests/Avalonia/Prism.Avalonia.Tests/Prism.Avalonia.Tests.csproj index 179465f..f96eaea 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Prism.Avalonia.Tests.csproj +++ b/tests/Avalonia/Prism.Avalonia.Tests/Prism.Avalonia.Tests.csproj @@ -31,12 +31,6 @@ - - - MockBindingsView.axaml - - - MSBuild:Compile diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs index 3947469..f728859 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs @@ -1,4 +1,5 @@ -using Prism.Avalonia.Tests.Mocks; +using Moq; +using Prism.Avalonia.Tests.Mocks; using Prism.Navigation.Regions.Behaviors; using Xunit; @@ -9,6 +10,7 @@ public class AutoPopulateRegionBehaviorFixture [Fact] public void ShouldGetViewsFromRegistryOnAttach() { + ContainerLocator.SetContainerExtension(Mock.Of()); var region = new MockPresentationRegion() { Name = "MyRegion" }; var viewFactory = new MockRegionContentRegistry(); var view = new object(); @@ -28,6 +30,7 @@ public void ShouldGetViewsFromRegistryOnAttach() [Fact] public void ShouldGetViewsFromRegistryWhenRegisteringItAfterAttach() { + ContainerLocator.SetContainerExtension(Mock.Of()); var region = new MockPresentationRegion() { Name = "MyRegion" }; var viewFactory = new MockRegionContentRegistry(); var behavior = new AutoPopulateRegionBehavior(viewFactory) @@ -60,6 +63,8 @@ public void NullRegionThrows() [Fact] public void CanAttachBeforeSettingName() { + ContainerLocator.SetContainerExtension(Mock.Of()); + ContainerLocator.SetContainerExtension(Mock.Of()); var region = new MockPresentationRegion() { Name = null }; var viewFactory = new MockRegionContentRegistry(); var view = new object(); @@ -88,7 +93,7 @@ private class MockRegionContentRegistry : IRegionViewRegistry public event EventHandler ContentRegistered; - public IEnumerable GetContents(string regionName) + public IEnumerable GetContents(string regionName, IContainerProvider container) { GetContentsCalled = true; this.GetContentsArgumentRegionName = regionName; @@ -97,7 +102,7 @@ public IEnumerable GetContents(string regionName) public void RaiseContentRegistered(string regionName, object view) { - this.ContentRegistered(this, new ViewRegisteredEventArgs(regionName, () => view)); + this.ContentRegistered(this, new ViewRegisteredEventArgs(regionName, _ => view)); } public void RegisterViewWithRegion(string regionName, Type viewType) @@ -105,7 +110,12 @@ public void RegisterViewWithRegion(string regionName, Type viewType) throw new NotImplementedException(); } - public void RegisterViewWithRegion(string regionName, Func getContentDelegate) + public void RegisterViewWithRegion(string regionName, Func getContentDelegate) + { + throw new NotImplementedException(); + } + + public void RegisterViewWithRegion(string regionName, string targetName) { throw new NotImplementedException(); } diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs index cb5b38b..0c7d948 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs @@ -161,11 +161,11 @@ public virtual void RemovesRegionItemIfDataContextReturnsKeepAliveFalse() public virtual void RemovesOnlyDeactivatedItemsInRegionBasedOnDataContextKeepAlive() { // Arrange - var retionItemDataContextToKeepAlive = new Mock(); - retionItemDataContextToKeepAlive.Setup(i => i.KeepAlive).Returns(true); + var regionItemDataContextToKeepAlive = new Mock(); + regionItemDataContextToKeepAlive.Setup(i => i.KeepAlive).Returns(true); var regionItemToKeepAlive = new MockFrameworkElement(); - regionItemToKeepAlive.DataContext = retionItemDataContextToKeepAlive.Object; + regionItemToKeepAlive.DataContext = regionItemDataContextToKeepAlive.Object; Region.Add(regionItemToKeepAlive); Region.Activate(regionItemToKeepAlive); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/ContentControlRegionAdapterFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/ContentControlRegionAdapterFixture.cs index 2c5e5e1..a060f40 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/ContentControlRegionAdapterFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/ContentControlRegionAdapterFixture.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using Avalonia.Controls; +using Avalonia.Controls; using Avalonia.Data; using Prism.Avalonia.Tests.Mocks; using Xunit; diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/ItemsControlRegionAdapterFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/ItemsControlRegionAdapterFixture.cs index c8342a7..55b0ea0 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/ItemsControlRegionAdapterFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/ItemsControlRegionAdapterFixture.cs @@ -36,6 +36,7 @@ public void AdapterAssociatesItemsControlWithRegion() [StaFact] public void AdapterAssignsARegionThatHasAllViewsActive() { + ContainerLocator.SetContainerExtension(Mock.Of()); var control = new ItemsControl(); IRegionAdapter adapter = new ItemsControlRegionAdapter(null); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs index f49124c..a78dad1 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/LocatorNavigationTargetHandlerFixture.cs @@ -1,7 +1,8 @@ -using Avalonia.Controls; +using Avalonia.Controls; using Moq; using Prism.Ioc; using Xunit; +using static Prism.Avalonia.Tests.Regions.LocatorNavigationTargetHandlerFixture; namespace Prism.Avalonia.Tests.Regions { @@ -12,6 +13,7 @@ public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView() { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -34,23 +36,21 @@ public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView() public void WhenRegionHasMultipleViews_ThenViewsWithMatchingTypeNameAreConsidered() { // Arrange + var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); var view1 = new TestView(); - var view2 = "view"; + var view2 = new Test2View(); region.Add(view1); region.Add(view2); - var navigationContext = new NavigationContext(null, new Uri(view2.GetType().Name, UriKind.Relative)); - var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object); - // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); - // Assert Assert.Same(view2, returnedView); } @@ -60,11 +60,12 @@ public void WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsi { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); var view1 = new TestView(); - var view2 = "view"; + var view2 = new Test2View(); region.Add(view1); region.Add(view2); @@ -85,6 +86,7 @@ public void WhenViewExistsAndImplementsINavigationAware_ThenViewIsQueriedForNavi { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -113,6 +115,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDa { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -143,6 +146,7 @@ public void WhenNoCurrentMatchingViewExists_ThenReturnsNewlyCreatedInstanceWithS { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -167,6 +171,7 @@ public void WhenViewExistsAndImplementsINavigationAware_ThenViewIsQueriedForNavi { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -200,6 +205,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDa { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -235,6 +241,8 @@ public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDa public void WhenViewCannotBeCreated_ThenThrowsAnException() { var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); + containerMock.Setup(sl => sl.Resolve(typeof(object), typeof(TestView).Name)).Throws(); var region = new Region(); @@ -257,6 +265,7 @@ public void WhenViewAddedByHandlerDoesNotImplementINavigationAware_ThenReturnsVi { // Arrange var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -299,6 +308,7 @@ public void WhenRequestingContentForNullRegion_ThenThrows() public void WhenRequestingContentForNullContext_ThenThrows() { var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); var region = new Region(); @@ -320,6 +330,8 @@ public TestRegionNavigationContentLoader(IContainerExtension container) } public class TestView { } + + public class Test2View { } } public class ActivationException : Exception diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationAsyncExtensionsFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationAsyncExtensionsFixture.cs index cff448b..ca769c2 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationAsyncExtensionsFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationAsyncExtensionsFixture.cs @@ -1,5 +1,4 @@ -using System; -using Moq; +using Moq; using Xunit; namespace Prism.Avalonia.Tests.Regions @@ -40,7 +39,8 @@ public void WhenNavigatingWithARelativeStringTarget_ThenNavigatesToRelativeUri() .Setup(nv => nv.RequestNavigate( It.Is(u => !u.IsAbsoluteUri && u.OriginalString == "relative"), - It.Is>(c => c != null))) + It.Is>(c => c != null), + It.IsAny())) .Verifiable(); string target = "relative"; @@ -58,7 +58,8 @@ public void WhenNavigatingWithAnAbsoluteStringTarget_ThenNavigatesToAbsoluteUri( .Setup(nv => nv.RequestNavigate( It.Is(u => u.IsAbsoluteUri && u.Host == "test" && u.AbsolutePath == "/path"), - It.Is>(c => c != null))) + It.Is>(c => c != null), + It.IsAny())) .Verifiable(); string target = "http://test/path"; @@ -91,7 +92,8 @@ public void WhenNavigatingWithAUri_ThenNavigatesToUriWithCallback() .Setup(nv => nv.RequestNavigate( target, - It.Is>(c => c != null))) + It.Is>(c => c != null), + It.IsAny())) .Verifiable(); navigateMock.Object.RequestNavigate(target); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationParametersFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationParametersFixture.cs deleted file mode 100644 index 1296466..0000000 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/NavigationParametersFixture.cs +++ /dev/null @@ -1,291 +0,0 @@ -using System.Linq; -using Prism.Navigation.Regions; -using Xunit; - -namespace Prism.Avalonia.Tests.Regions -{ - public class NavigationParametersFixture - { - const string _uri = "?id=3&name=brian"; - const string _uriWithNoQuestionMarkDelimiter = "id=3&name=brian"; - const string _uriWithArray = "color=red&color=white&color=blue"; - const string _uriWithJQueryArray = "color[]=red&color[]=white&color[]=blue"; - - [Fact] - public void ParametersParsedFromQuery() - { - var parameters = new NavigationParameters(_uri); - Assert.Equal(2, parameters.Count); - Assert.True(parameters.ContainsKey("id")); - Assert.Equal("3", parameters["id"]); - Assert.True(parameters.ContainsKey("name")); - Assert.Equal("brian", parameters["name"]); - } - - [Fact] - public void ParametersParsedFromQueryWithNoQuestionMarkDelimiter() - { - var parameters = new NavigationParameters(_uriWithNoQuestionMarkDelimiter); - Assert.Equal(2, parameters.Count); - Assert.True(parameters.ContainsKey("id")); - Assert.Equal("3", parameters["id"]); - Assert.True(parameters.ContainsKey("name")); - Assert.Equal("brian", parameters["name"]); - } - - [Fact] - public void ParametersParsedFromQueryWithArray() - { - var parameters = new NavigationParameters(_uriWithArray); - Assert.Equal(3, parameters.Count); - Assert.Contains("color", parameters.Keys.ToArray()); - } - - [Fact] - public void ParametersParsedFromQueryWithJQueryArray() - { - var parameters = new NavigationParameters(_uriWithJQueryArray); - Assert.Equal(3, parameters.Count); - Assert.Contains("color[]", parameters.Keys.ToArray()); - } - - [Fact] - public void EmptyNavigationParametersWhenGivenNull() - { - var parameters = new NavigationParameters(null); - Assert.NotNull(parameters); - Assert.Equal(0, parameters.Count); - } - - [Fact] - public void EmptyNavigationParametersWhenGivenSpace() - { - var parameters = new NavigationParameters(" "); - Assert.NotNull(parameters); - Assert.Equal(0, parameters.Count); - } - - [Fact] - public void EmptyNavigationParametersWhenGivenNoValue() - { - var parameters = new NavigationParameters("id"); - Assert.NotNull(parameters); - Assert.Equal(0, parameters.Count); - } - - [Fact] - public void ParametersHaveNoKeysWhenEmpty() - { - var parameters = new NavigationParameters(); - Assert.Empty(parameters.Keys); - } - - [Fact] - public void CountIsZeroWhenParametersAreEmpty() - { - var parameters = new NavigationParameters(); - Assert.Equal(0, parameters.Count); - } - - [Fact] - public void CountReturnsNumberOfParameters() - { - var parameters = new NavigationParameters($"{_uri}&{_uriWithArray}"); - Assert.Equal(5, parameters.Count); - } - - [Fact] - public void GetValueReturnsDefaultWhenGivenInvalidKey() - { - var parameters = new NavigationParameters(); - var result = parameters.GetValue("id"); - Assert.Equal(default(int), result); - } - - [Fact] - public void TryGetValueReturnsDefaultWhenGivenInvalidKey() - { - var parameters = new NavigationParameters(); - int value; - var result = parameters.TryGetValue("id", out value); - Assert.False(result); - Assert.Equal(default(int), value); - } - - [Fact] - public void GetValueReturnsDefaultWhenParameterValueIsNull() - { - var parameters = new NavigationParameters(); - parameters.Add("value", null); - var result = parameters.GetValue("value"); - Assert.Equal(0, result); - } - - [Fact] - public void TryGetValueReturnsDefaultWhenParameterValueIsNull() - { - var parameters = new NavigationParameters(); - parameters.Add("value", null); - int value; - var result = parameters.TryGetValue("value", out value); - Assert.True(result); - Assert.Equal(0, value); - } - - [Fact] - public void GetValueReturnsTypedParameterWhenParametersParsedFromQuery() - { - var parameters = new NavigationParameters(_uri); - var result = parameters.GetValue("id"); - Assert.IsType(result); - Assert.Equal(3, result); - } - - [Fact] - public void TryGetValueReturnsTypedParameterWhenParametersParsedFromQuery() - { - var parameters = new NavigationParameters(_uri); - int value; - var result = parameters.TryGetValue("id", out value); - Assert.True(result); - Assert.Equal(3, value); - } - - [Fact] - public void GetValueReturnsNullWhenParameterValueIsNull() - { - var parameters = new NavigationParameters(); - parameters.Add("value", null); - var result = parameters.GetValue("value"); - Assert.Null(result); - } - - [Fact] - public void GetValuesReturnsEmptyArrayWhenGivenNoKey() - { - var parameters = new NavigationParameters(); - var result = parameters.GetValues(null); - Assert.Empty(result); - } - - [Fact] - public void GetValuesReturnsEmptyArrayWhenGivenEmptyKey() - { - var parameters = new NavigationParameters(); - var result = parameters.GetValues(string.Empty); - Assert.Empty(result); - } - - [Fact] - public void GetValuesReturnsEmptyArrayWhenParametersParsedFromQueryWithInvalidKey() - { - var parameters = new NavigationParameters(_uriWithArray); - var result = parameters.GetValues("id"); - Assert.Empty(result); - } - - [Fact] - public void GetValuesReturnsArrayWhenParametersParsedFromQuery() - { - var parameters = new NavigationParameters(_uriWithArray); - var result = parameters.GetValues("color"); - Assert.Equal(3, result.Count()); - Assert.Contains("red", result); - Assert.Contains("white", result); - Assert.Contains("blue", result); - } - - [Fact] - public void GetValuesReturnsArrayWhenNotUsingQuery() - { - var parameters = new NavigationParameters(); - parameters.Add("id", new Person()); - parameters.Add("id", new Person()); - parameters.Add("id", null); - var result = parameters.GetValues("id").ToArray(); - Assert.Equal(3, result.Count()); - Assert.IsType(result[0]); - Assert.IsType(result[1]); - Assert.Null(result[2]); - } - - [Fact] - public void GetValuesConvertsValuesToStringWhenGivenUriQuery() - { - var parameters = new NavigationParameters(_uriWithArray); - var result = parameters.GetValues("color").ToArray(); - Assert.Equal(3, result.Count()); - - Assert.IsType(result[0]); - Assert.IsType(result[1]); - Assert.IsType(result[2]); - } - - [Fact] - public void GetValuesConvertsValuesToIntWhenGivenUriQuery() - { - var parameters = new NavigationParameters("id=1&id=2&id=3"); - var result = parameters.GetValues("id").ToArray(); - Assert.Equal(3, result.Count()); - Assert.IsType(result[0]); - Assert.IsType(result[1]); - Assert.IsType(result[2]); - } - - [Fact] - public void GetValueUseParentClassAsTypeParameter() - { - var parameters = new NavigationParameters(); - parameters.Add("id", new Child()); - - Assert.NotNull(parameters.GetValue("id")); - } - - [Fact] - public void TryGetValueUseParentClassAsTypeParameter() - { - var parameters = new NavigationParameters(); - parameters.Add("id", new Child()); - - Person value; - var result = parameters.TryGetValue("id", out value); - Assert.True(result); - Assert.IsType(value); - } - - [Fact] - public void GetValuesUseParentClassAsTypeParameter() - { - var parameters = new NavigationParameters(); - parameters.Add("id", new Child()); - parameters.Add("id", new Child()); - parameters.Add("id", new Person()); - - var result = parameters.GetValues("id").ToArray(); - - Assert.Equal(3, result.Count()); - Assert.NotNull(result[0]); - Assert.NotNull(result[1]); - Assert.NotNull(result[2]); - } - - [Fact] - public void ToStringWorksWithNullParameterValues() - { - var parameters = new NavigationParameters(); - parameters.Add("id1", 1); - parameters.Add("id2", null); - parameters.Add("id3", 3); - - var result = parameters.ToString(); - - Assert.Equal("?id1=1&id2=&id3=3", result); - } - } - - public class Person - { } - - public class Child : Person - { } -} diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionAdapterBaseFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionAdapterBaseFixture.cs index fbd4791..0e3d06d 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionAdapterBaseFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionAdapterBaseFixture.cs @@ -1,5 +1,4 @@ -using System; -using Prism.Avalonia.Tests.Mocks; +using Prism.Avalonia.Tests.Mocks; using Xunit; namespace Prism.Avalonia.Tests.Regions diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionFixture.cs index 1b347e9..15b0e80 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Specialized; using System.Linq; using Moq; @@ -13,6 +13,7 @@ public class RegionFixture [Fact] public void WhenRegionConstructed_SortComparisonIsDefault() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); Assert.NotNull(region.SortComparison); @@ -22,6 +23,7 @@ public void WhenRegionConstructed_SortComparisonIsDefault() [Fact] public void CanAddContentToRegion() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); Assert.Empty(region.Views.Cast()); @@ -61,6 +63,7 @@ public void RemoveInexistentViewThrows() [Fact] public void RegionExposesCollectionOfContainedViews() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object view = new object(); @@ -77,6 +80,7 @@ public void RegionExposesCollectionOfContainedViews() [Fact] public void CanAddAndRetrieveNamedViewInstance() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object myView = new object(); region.Add(myView, "MyView"); @@ -102,6 +106,7 @@ public void AddingDuplicateNamedViewThrows() [Fact] public void AddNamedViewIsAlsoListedInViewsCollection() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object myView = new object(); @@ -134,6 +139,7 @@ public void GetViewWithNullOrEmptyStringThrows() [Fact] public void AddNamedViewWithNullOrEmptyStringNameThrows() { + ContainerLocator.SetContainerExtension(Mock.Of()); var ex = Assert.Throws(() => { IRegion region = new Region(); @@ -146,6 +152,7 @@ public void AddNamedViewWithNullOrEmptyStringNameThrows() [Fact] public void GetViewReturnsNullAfterRemovingViewFromRegion() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object myView = new object(); region.Add(myView, "MyView"); @@ -170,6 +177,7 @@ public void AddViewPassesSameScopeByDefaultToView() [Fact] public void AddViewPassesSameScopeByDefaultToNamedView() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -181,8 +189,9 @@ public void AddViewPassesSameScopeByDefaultToNamedView() } [Fact] - public void AddViewPassesDiferentScopeWhenAdding() + public void AddViewPassesDifferentScopeWhenAdding() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -196,6 +205,7 @@ public void AddViewPassesDiferentScopeWhenAdding() [Fact] public void CreatingNewScopesAsksTheRegionManagerForNewInstance() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -209,6 +219,7 @@ public void CreatingNewScopesAsksTheRegionManagerForNewInstance() [Fact] public void AddViewReturnsExistingRegionManager() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new MockRegionManager(); IRegion region = new Region(); region.RegionManager = regionManager; @@ -286,6 +297,7 @@ public void ActivateNullViewThrows() [Fact] public void AddViewRaisesCollectionViewEvent() { + ContainerLocator.SetContainerExtension(Mock.Of()); bool viewAddedCalled = false; IRegion region = new Region(); @@ -305,6 +317,7 @@ public void AddViewRaisesCollectionViewEvent() [Fact] public void ViewAddedEventPassesTheViewAddedInTheEventArgs() { + ContainerLocator.SetContainerExtension(Mock.Of()); object viewAdded = null; IRegion region = new Region(); @@ -326,6 +339,7 @@ public void ViewAddedEventPassesTheViewAddedInTheEventArgs() [Fact] public void RemoveViewFiresViewRemovedEvent() { + ContainerLocator.SetContainerExtension(Mock.Of()); bool viewRemoved = false; IRegion region = new Region(); @@ -347,6 +361,7 @@ public void RemoveViewFiresViewRemovedEvent() [Fact] public void ViewRemovedEventPassesTheViewRemovedInTheEventArgs() { + ContainerLocator.SetContainerExtension(Mock.Of()); object removedView = null; IRegion region = new Region(); @@ -409,6 +424,7 @@ public void AddingSameViewTwiceThrows() [Fact] public void RemovingViewAlsoRemovesItFromActiveViews() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object model = new object(); region.Add(model); @@ -423,6 +439,7 @@ public void RemovingViewAlsoRemovesItFromActiveViews() [Fact] public void ShouldGetNotificationWhenContextChanges() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); bool contextChanged = false; region.PropertyChanged += (s, args) => { if (args.PropertyName == "Context") contextChanged = true; }; @@ -467,7 +484,7 @@ public IRegionManager RegisterViewWithRegion(string regionName, Type viewType) throw new NotImplementedException(); } - public IRegionManager RegisterViewWithRegion(string regionName, Func getContentDelegate) + public IRegionManager RegisterViewWithRegion(string regionName, Func getContentDelegate) { throw new NotImplementedException(); } @@ -492,22 +509,22 @@ public void RequestNavigate(string regionName, string source) throw new NotImplementedException(); } - public void RequestNavigate(string regionName, Uri target, Action navigationCallback, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, Uri target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } - public void RequestNavigate(string regionName, string target, Action navigationCallback, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, string target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } - public void RequestNavigate(string regionName, Uri target, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, Uri target, INavigationParameters navigationParameters) { throw new NotImplementedException(); } - public void RequestNavigate(string regionName, string target, NavigationParameters navigationParameters) + public void RequestNavigate(string regionName, string target, INavigationParameters navigationParameters) { throw new NotImplementedException(); } @@ -559,7 +576,7 @@ public void NavigateDelegatesToIRegionNavigationService() var containerMock = new Mock(); containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationService))).Returns(mockRegionNavigationService.Object); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); // Act region.RequestNavigate(uri, navigationCallback, navigationParameters); @@ -576,6 +593,7 @@ public void NavigateDelegatesToIRegionNavigationService() [Fact] public void WhenViewsWithSortHintsAdded_RegionSortsViews() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region(); object view1 = new ViewOrder1(); @@ -595,6 +613,7 @@ public void WhenViewsWithSortHintsAdded_RegionSortsViews() [StaFact] public void WhenViewHasBeenRemovedAndRegionManagerPropertyCleared_ThenItCanBeAddedAgainToARegion() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new Region { RegionManager = new MockRegionManager() }; var view = new MockFrameworkElement(); @@ -618,8 +637,10 @@ public void WhenViewHasBeenRemovedAndRegionManagerPropertyCleared_ThenItCanBeAdd [ViewSortHint("C")] private class ViewOrder1 { }; + [ViewSortHint("A")] private class ViewOrder2 { }; + [ViewSortHint("B")] private class ViewOrder3 { }; } diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerFixture.cs index be471d6..44434a7 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.Specialized; using Moq; @@ -70,6 +70,7 @@ public void AddPassesItselfAsTheRegionManagerOfTheRegion() { Name = "region" }; + regionManager.Regions.Add(region); Assert.Same(regionManager, region.RegionManager); @@ -93,8 +94,8 @@ public void CanRemoveRegion() { Name = "TestRegion" }; - regionManager.Regions.Add(region); + regionManager.Regions.Add(region); regionManager.Regions.Remove("TestRegion"); Assert.False(regionManager.Regions.ContainsRegionWithName("TestRegion")); @@ -108,8 +109,8 @@ public void ShouldRemoveRegionManagerWhenRemoving() { Name = "TestRegion" }; - regionManager.Regions.Add(region); + regionManager.Regions.Add(region); regionManager.Regions.Remove("TestRegion"); Assert.Null(region.RegionManager); @@ -155,7 +156,6 @@ public void ShouldSetObservableRegionContextWhenRegionContextChanges() var region = new MockPresentationRegion(); var view = new MockDependencyObject(); - // NOTE: AvaloniaObject performs `Dispatcher.UIThread.VerifyAccess()`, if it's FALSE the InheritanceParent returns NULL. var observableObject = RegionContext.GetObservableContext(view); bool propertyChangedCalled = false; @@ -232,6 +232,7 @@ public void OnUpdatingRegions(object sender, EventArgs e) [Fact] public void WhenAddingRegions_ThenRegionsCollectionNotifiesUpdate() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new RegionManager(); var region1 = new Region { Name = "region1" }; @@ -260,6 +261,7 @@ public void WhenAddingRegions_ThenRegionsCollectionNotifiesUpdate() [Fact] public void WhenRemovingRegions_ThenRegionsCollectionNotifiesUpdate() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new RegionManager(); var region1 = new Region { Name = "region1" }; @@ -291,6 +293,7 @@ public void WhenRemovingRegions_ThenRegionsCollectionNotifiesUpdate() [Fact] public void WhenRemovingNonExistingRegion_ThenRegionsCollectionDoesNotNotifyUpdate() { + ContainerLocator.SetContainerExtension(Mock.Of()); var regionManager = new RegionManager(); var region1 = new Region { Name = "region1" }; @@ -316,6 +319,7 @@ public void CanAddViewToRegion() { Name = "RegionName" }; + regionManager.Regions.Add(region); regionManager.AddToRegion("RegionName", view1); @@ -341,9 +345,10 @@ public void CanRegisterViewType() viewType = type; return null; }; + var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); @@ -378,7 +383,7 @@ public void CanRegisterViewTypeGeneric() var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); ContainerLocator.ResetContainer(); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); @@ -402,18 +407,19 @@ public void CanRegisterDelegate() var mockRegionContentRegistry = new MockRegionContentRegistry(); string regionName = null; - Func contentDelegate = null; + Func contentDelegate = null; + Func expectedDelegate = _ => true; - Func expectedDelegate = () => true; mockRegionContentRegistry.RegisterContentWithDelegate = (name, usedDelegate) => { regionName = name; contentDelegate = usedDelegate; return null; }; + var containerMock = new Mock(); containerMock.Setup(c => c.Resolve(typeof(IRegionViewRegistry))).Returns(mockRegionContentRegistry); - ContainerLocator.SetContainerExtension(() => containerMock.Object); + ContainerLocator.SetContainerExtension(containerMock.Object); var regionManager = new RegionManager(); @@ -461,26 +467,30 @@ internal class FrameworkException : Exception public FrameworkException(Exception inner) : base(string.Empty, inner) { - } } internal class MockRegionContentRegistry : IRegionViewRegistry { public Func RegisterContentWithViewType; - public Func, object> RegisterContentWithDelegate; + public Func, object> RegisterContentWithDelegate; public event EventHandler ContentRegistered; - public IEnumerable GetContents(string regionName) + public IEnumerable GetContents(string regionName, IContainerProvider container) { return null; } + public void RegisterViewWithRegion(string regionName, string targetName) + { + throw new NotImplementedException(); + } + void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Type viewType) { RegisterContentWithViewType?.Invoke(regionName, viewType); } - void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func getContentDelegate) + void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func getContentDelegate) { RegisterContentWithDelegate?.Invoke(regionName, getContentDelegate); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerRequestNavigateFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerRequestNavigateFixture.cs index ec54346..8a31b4f 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerRequestNavigateFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionManagerRequestNavigateFixture.cs @@ -52,33 +52,33 @@ public void WhenNonExistentRegion_ReturnNavigationResultFalse() result = null; regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r, parameters); - Assert.Equal(false, result.Result); + Assert.False(result.Success); result = null; regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r); - Assert.Equal(false, result.Result); + Assert.False(result.Success); result = null; regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r, parameters); - Assert.Equal(false, result.Result); + Assert.False(result.Success); result = null; regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r); - Assert.Equal(false, result.Result); + Assert.False(result.Success); } [Fact] public void DelegatesCallToRegion_RegionSource() { regionManager.RequestNavigate(region, source); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>())); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), It.IsAny())); } [Fact] public void DelegatesCallToRegion_RegionTarget() { regionManager.RequestNavigate(region, sourceUri); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>())); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), It.IsAny())); } [Fact] @@ -99,14 +99,14 @@ public void DelegatesCallToRegion_RegionSourceUriParameters() public void DelegatesCallToRegion_RegionSourceCallback() { regionManager.RequestNavigate(region, source, callback); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback)); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback, It.IsAny())); } [Fact] public void DelegatesCallToRegion_RegionTargetCallback() { regionManager.RequestNavigate(region, sourceUri, callback); - mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback)); + mockRegion.Verify((r) => r.RequestNavigate(sourceUri, callback, It.IsAny())); } [Fact] diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationJournalFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationJournalFixture.cs index 0d75d23..1217da8 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationJournalFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationJournalFixture.cs @@ -1,4 +1,4 @@ -using Moq; +using Moq; using Xunit; namespace Prism.Avalonia.Tests.Regions @@ -129,13 +129,13 @@ public void GoBackNavigatesBack() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); // Act target.GoBack(); @@ -174,13 +174,13 @@ public void GoBackDoesNotChangeStateWhenNavigationFails() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, false))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, false))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); // Act target.GoBack(); @@ -219,13 +219,13 @@ public void GoBackMultipleTimesNavigatesBack() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); // Act target.GoBack(); @@ -265,13 +265,13 @@ public void GoForwardNavigatesForward() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); target.GoBack(); target.GoBack(); @@ -313,13 +313,13 @@ public void GoForwardDoesNotChangeStateWhenNavigationFails() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, false))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, false))); target.GoBack(); @@ -360,13 +360,13 @@ public void GoForwardMultipleTimesNavigatesForward() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); target.GoBack(); target.GoBack(); @@ -411,13 +411,13 @@ public void WhenNavigationToNewUri_ThenCanNoLongerNavigateForward() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); target.GoBack(); @@ -459,16 +459,16 @@ public void WhenSavePreviousFalseDoNotRecordEntry() mockNavigationTarget .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget .Setup(x => x.RequestNavigate(uri4, It.IsAny>(), null)) - .Callback, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); Assert.Equal(entry4, target.CurrentEntry); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationServiceFixture.new.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationServiceFixture.new.cs index 829ab60..25346c7 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationServiceFixture.new.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionNavigationServiceFixture.new.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows; @@ -38,7 +38,7 @@ public void WhenNavigating_ViewIsActivated() // Act bool isNavigationSuccessful = false; - target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); + target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true); // Verify Assert.True(isNavigationSuccessful); @@ -74,7 +74,7 @@ public void WhenNavigatingWithQueryString_ViewIsActivated() // Act bool isNavigationSuccessful = false; - target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); + target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true); // Verify Assert.True(isNavigationSuccessful); @@ -114,7 +114,7 @@ public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError() new Uri(otherType.GetType().Name, UriKind.Relative), nr => { - error = nr.Error; + error = nr.Exception; }); // Verify @@ -146,9 +146,9 @@ public void WhenNavigatingWithNullUri_Throws() target.RequestNavigate((Uri)null, nr => navigationResult = nr); // Verify - Assert.False(navigationResult.Result.Value); - Assert.NotNull(navigationResult.Error); - Assert.IsType(navigationResult.Error); + Assert.False(navigationResult.Success); + Assert.NotNull(navigationResult.Exception); + Assert.IsType(navigationResult.Exception); } [Fact] @@ -189,12 +189,12 @@ public void WhenNavigatingAndDataContextImplementsINavigationAware_ThenNavigated // Prepare var region = new Region(); - Mock mockFrameworkElement = new Mock(); + Mock mockControl = new Mock(); Mock mockINavigationAwareDataContext = new Mock(); mockINavigationAwareDataContext.Setup(ina => ina.IsNavigationTarget(It.IsAny())).Returns(true); - mockFrameworkElement.Object.DataContext = mockINavigationAwareDataContext.Object; + mockControl.Object.DataContext = mockINavigationAwareDataContext.Object; - var view = mockFrameworkElement.Object; + var view = mockControl.Object; region.Add(view); var navigationUri = new Uri(view.GetType().Name, UriKind.Relative); @@ -224,15 +224,15 @@ public void WhenNavigatingAndBothViewAndDataContextImplementINavigationAware_The // Prepare var region = new Region(); - Mock mockFrameworkElement = new Mock(); - Mock mockINavigationAwareView = mockFrameworkElement.As(); + Mock mockControl = new Mock(); + Mock mockINavigationAwareView = mockControl.As(); mockINavigationAwareView.Setup(ina => ina.IsNavigationTarget(It.IsAny())).Returns(true); Mock mockINavigationAwareDataContext = new Mock(); mockINavigationAwareDataContext.Setup(ina => ina.IsNavigationTarget(It.IsAny())).Returns(true); - mockFrameworkElement.Object.DataContext = mockINavigationAwareDataContext.Object; + mockControl.Object.DataContext = mockINavigationAwareDataContext.Object; - var view = mockFrameworkElement.Object; + var view = mockControl.Object; region.Add(view); var navigationUri = new Uri(view.GetType().Name, UriKind.Relative); @@ -277,6 +277,7 @@ public void WhenNavigating_NavigationIsRecordedInJournal() containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(journalEntry); IContainerExtension container = containerMock.Object; + ContainerLocator.SetContainerExtension(container); RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(container); var journalMock = new Mock(); @@ -432,7 +433,7 @@ public void WhenRequestNavigateAwayAcceptsThroughCallback_ThenNavigationProceeds // Act var navigationSucceeded = false; - target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Result == true; }); + target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Success == true; }); // Verify view1Mock.VerifyAll(); @@ -477,7 +478,7 @@ public void WhenRequestNavigateAwayRejectsThroughCallback_ThenNavigationDoesNotP // Act var navigationFailed = false; - target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; }); + target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Success == false; }); // Verify view1Mock.VerifyAll(); @@ -564,7 +565,7 @@ public void WhenRequestNavigateAwayOnDataContextAcceptsThroughCallback_ThenNavig // Act var navigationSucceeded = false; - target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Result == true; }); + target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Success == true; }); // Verify view1DataContextMock.VerifyAll(); @@ -611,7 +612,7 @@ public void WhenRequestNavigateAwayOnDataContextRejectsThroughCallback_ThenNavig // Act var navigationFailed = false; - target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; }); + target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Success == false; }); // Verify view1DataContextMock.VerifyAll(); @@ -659,8 +660,8 @@ public void WhenViewAcceptsNavigationOutAfterNewIncomingRequestIsReceived_ThenOr bool firstNavigation = false; bool secondNavigation = false; - target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Result.Value); - target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Result.Value); + target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Success); + target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Success); Assert.Equal(2, confirmationRequests.Count); @@ -714,8 +715,8 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T bool firstNavigation = false; bool secondNavigation = false; - target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Result.Value); - target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Result.Value); + target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Success); + target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Success); Assert.Equal(2, confirmationRequests.Count); @@ -729,6 +730,7 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T [Fact] public void BeforeNavigating_NavigatingEventIsRaised() { + ContainerLocator.SetContainerExtension(Mock.Of()); // Prepare object view = new object(); Uri viewUri = new Uri(view.GetType().Name, UriKind.Relative); @@ -763,7 +765,7 @@ public void BeforeNavigating_NavigatingEventIsRaised() // Act bool isNavigationSuccessful = false; - target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); + target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true); // Verify Assert.True(isNavigationSuccessful); @@ -807,7 +809,7 @@ public void WhenNavigationSucceeds_NavigatedIsRaised() // Act bool isNavigationSuccessful = false; - target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); + target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true); // Verify Assert.True(isNavigationSuccessful); @@ -847,7 +849,7 @@ public void WhenTargetViewCreationThrowsWithAsyncConfirmation_ThenExceptionIsPro navigationCallback(true); Assert.NotNull(result); - Assert.Same(targetException, result.Error); + Assert.Same(targetException, result.Exception); } [Fact] @@ -999,7 +1001,7 @@ public void WhenNavigatingWithNoRegionSet_ThenMarshallExceptionToCallback() RegionNavigationService target = new RegionNavigationService(container, contentLoader, journal); Exception error = null; - target.RequestNavigate(navigationUri, nr => error = nr.Error); + target.RequestNavigate(navigationUri, nr => error = nr.Exception); Assert.NotNull(error); Assert.IsType(error); @@ -1018,7 +1020,7 @@ public void WhenNavigatingWithNullUri_ThenMarshallExceptionToCallback() }; Exception error = null; - target.RequestNavigate(null, nr => error = nr.Error); + target.RequestNavigate(null, nr => error = nr.Exception); Assert.NotNull(error); Assert.IsType(error); @@ -1058,7 +1060,7 @@ public void WhenNavigationFailsBecauseTheContentViewCannotBeRetrieved_ThenNaviga // Act bool? isNavigationSuccessful = null; - target.RequestNavigate(new Uri("invalid", UriKind.Relative), nr => isNavigationSuccessful = nr.Result); + target.RequestNavigate(new Uri("invalid", UriKind.Relative), nr => isNavigationSuccessful = nr.Success); // Verify Assert.False(isNavigationSuccessful.Value); @@ -1117,7 +1119,7 @@ public void WhenNavigationFailsBecauseActiveViewRejectsIt_ThenNavigationFailedIs // Act bool? isNavigationSuccessful = null; - target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Result); + target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Success); // Verify view1Mock.VerifyAll(); @@ -1179,7 +1181,7 @@ public void WhenNavigationFailsBecauseDataContextForActiveViewRejectsIt_ThenNavi // Act bool? isNavigationSuccessful = null; - target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Result); + target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Success); // Verify viewModel1Mock.VerifyAll(); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionViewRegistryFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionViewRegistryFixture.cs index db28b89..2cd1e3e 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionViewRegistryFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/RegionViewRegistryFixture.cs @@ -1,60 +1,17 @@ using Avalonia.Controls; -using Avalonia.Markup.Xaml; using Moq; -using Prism.Avalonia.Tests.Mocks.Views; using Prism.Avalonia.Tests.Mvvm; -using Prism.Ioc; -using Prism.Navigation.Regions; using Xunit; namespace Prism.Avalonia.Tests.Regions { public class RegionViewRegistryFixture { - [Fact] - public void CanNotRegisterWhenMissingDataTemplateDataType() - { - // Created for Avalonia v11.0.0-pre4 - // See, https://github.com/AvaloniaUI/Avalonia/pull/8221 - var xaml = GenerateUserControlWithListView(useCompileBindings: false, useDataTemplateDataType: false); - var userCtrl = (MockBindingsView)AvaloniaRuntimeXamlLoader.Load(xaml); - - var containerMock = new Mock(); - containerMock.Setup(c => c.Resolve(typeof(MockBindingsView))).Returns(userCtrl); - var registry = new RegionViewRegistry(containerMock.Object); - - registry.RegisterViewWithRegion("MyRegion", typeof(MockBindingsView)); - var result = registry.GetContents("MyRegion"); - - Assert.NotNull(result); - Assert.Single(result); - Assert.IsType(result.ElementAt(0)); - } - - [Fact] - public void CanRegisterWhenDataTemplateDataTypeIsProvided() - { - // Created for Avalonia v11.0.0-pre4 - // See, https://github.com/AvaloniaUI/Avalonia/pull/8221 - var xaml = GenerateUserControlWithListView(useDataTemplateDataType: true); - var userCtrl = (MockBindingsView)AvaloniaRuntimeXamlLoader.Load(xaml); - - var containerMock = new Mock(); - containerMock.Setup(c => c.Resolve(typeof(MockBindingsView))).Returns(userCtrl); - var registry = new RegionViewRegistry(containerMock.Object); - - registry.RegisterViewWithRegion("MyRegion", typeof(MockBindingsView)); - var result = registry.GetContents("MyRegion"); - - Assert.NotNull(result); - Assert.Single(result); - Assert.IsType(result.ElementAt(0)); - } - [Fact] public void CanRegisterContentAndRetrieveIt() { var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(MockContentObject))).Returns(new MockContentObject()); var registry = new RegionViewRegistry(containerMock.Object); @@ -90,6 +47,7 @@ public void ShouldRaiseEventWhenAddingContent() [Fact] public void CanRegisterContentAsDelegateAndRetrieveIt() { + ContainerLocator.SetContainerExtension(Mock.Of()); var registry = new RegionViewRegistry(null); var content = new MockContentObject(); @@ -132,7 +90,7 @@ public void OnRegisterErrorShouldGiveClearException() { Assert.Contains("Dont do this", ex.Message); Assert.Contains("R1", ex.Message); - Assert.Equal("Dont do this", ex.InnerException?.Message); + Assert.Equal("Dont do this", ex.InnerException.Message); } catch (Exception) { @@ -159,13 +117,13 @@ public void RegisterViewWithRegion_ShouldHaveViewModel_ByDefault() ViewModelLocatorFixture.ResetViewModelLocationProvider(); var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(Mocks.Views.Mock))).Returns(new Mocks.Views.Mock()); containerMock.Setup(c => c.Resolve(typeof(Mocks.ViewModels.MockViewModel))).Returns(new Mocks.ViewModels.MockViewModel()); var registry = new RegionViewRegistry(containerMock.Object); registry.RegisterViewWithRegion("MyRegion", typeof(Mocks.Views.Mock)); - // TODO: AutowireViewModel is not kicking off. var result = registry.GetContents("MyRegion"); Assert.NotNull(result); Assert.Single(result); @@ -182,6 +140,7 @@ public void RegisterViewWithRegion_ShouldNotHaveViewModel_OnOptOut() ViewModelLocatorFixture.ResetViewModelLocationProvider(); var containerMock = new Mock(); + ContainerLocator.SetContainerExtension(containerMock.Object); containerMock.Setup(c => c.Resolve(typeof(Mocks.Views.MockOptOut))).Returns(new Mocks.Views.MockOptOut()); containerMock.Setup(c => c.Resolve(typeof(Mocks.ViewModels.MockOptOutViewModel))).Returns(new Mocks.ViewModels.MockOptOutViewModel()); var registry = new RegionViewRegistry(containerMock.Object); @@ -197,49 +156,6 @@ public void RegisterViewWithRegion_ShouldNotHaveViewModel_OnOptOut() Assert.Null(view.DataContext); } - private string GenerateUserControlWithListView(bool useCompileBindings = true, bool useDataTemplateDataType = true) - { - var xaml = @" - - - - "; - - if (useDataTemplateDataType) - xaml += @" - "; - else - xaml += @" - "; - - xaml += @" - - - - - -"; - return xaml; - } - private void FailWithFrameworkException(object sender, ViewRegisteredEventArgs e) { try @@ -264,7 +180,6 @@ private class MockContentObject private class MySubscriberClass { public ViewRegisteredEventArgs onViewRegisteredArguments; - public void OnContentRegistered(object sender, ViewRegisteredEventArgs e) { onViewRegisteredArguments = e; @@ -276,6 +191,7 @@ private class FrameworkException : Exception public FrameworkException(Exception innerException) : base("", innerException) { + } } } diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/SelectorRegionAdapterFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/SelectorRegionAdapterFixture.cs index 27b2f12..d6b38fd 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/SelectorRegionAdapterFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/SelectorRegionAdapterFixture.cs @@ -3,6 +3,7 @@ /* using System; using Avalonia.Controls; +using Moq; using Prism.Navigation.Regions; using Prism.Navigation.Regions.Behaviors; using Xunit; @@ -14,6 +15,7 @@ public class SelectorRegionAdapterFixture [StaFact] public void AdapterAddsSelectorItemsSourceSyncBehavior() { + ContainerLocator.SetContainerExtension(Mock.Of()); var control = new ListBox(); IRegionAdapter adapter = new TestableSelectorRegionAdapter(); @@ -26,6 +28,7 @@ public void AdapterAddsSelectorItemsSourceSyncBehavior() [StaFact] public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected() { + ContainerLocator.SetContainerExtension(Mock.Of()); var selector = new ListBox(); object model = new object(); IRegionAdapter adapter = new SelectorRegionAdapter(null); @@ -33,14 +36,14 @@ public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected() var region = adapter.Initialize(selector, "Region1"); region.Add(model); - WeakReference regionWeakReference = new WeakReference(region); - WeakReference controlWeakReference = new WeakReference(selector); + var regionWeakReference = new WeakReference(region); + var controlWeakReference = new WeakReference(selector); Assert.True(regionWeakReference.IsAlive); Assert.True(controlWeakReference.IsAlive); region = null; selector = null; - await Task.delay(50); + await Task.Delay(50); GC.Collect(); GC.Collect(); @@ -51,6 +54,7 @@ public async Task AdapterDoesNotPreventRegionFromBeingGarbageCollected() [StaFact] public void ActivatingTheViewShouldUpdateTheSelectedItem() { + ContainerLocator.SetContainerExtension(Mock.Of()); var selector = new ListBox(); var view1 = new object(); var view2 = new object(); @@ -75,6 +79,7 @@ public void ActivatingTheViewShouldUpdateTheSelectedItem() [StaFact] public void DeactivatingTheSelectedViewShouldUpdateTheSelectedItem() { + ContainerLocator.SetContainerExtension(Mock.Of()); var selector = new ListBox(); var view1 = new object(); IRegionAdapter adapter = new SelectorRegionAdapter(null); @@ -97,6 +102,7 @@ public TestableSelectorRegionAdapter() { } + protected override IRegion CreateRegion() { return new Region(); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/SingleActiveRegionFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/SingleActiveRegionFixture.cs index 8a5d410..2df2817 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/SingleActiveRegionFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/SingleActiveRegionFixture.cs @@ -1,4 +1,5 @@ -using Prism.Navigation.Regions; +using Moq; +using Prism.Ioc; using Xunit; namespace Prism.Avalonia.Tests.Regions @@ -8,6 +9,7 @@ public class SingleActiveRegionFixture [Fact] public void ActivatingNewViewDeactivatesCurrent() { + ContainerLocator.SetContainerExtension(Mock.Of()); IRegion region = new SingleActiveRegion(); var view = new object(); region.Add(view); diff --git a/tests/Avalonia/Prism.Avalonia.Tests/Regions/ViewsCollectionFixture.cs b/tests/Avalonia/Prism.Avalonia.Tests/Regions/ViewsCollectionFixture.cs index 2391649..ea3c51d 100644 --- a/tests/Avalonia/Prism.Avalonia.Tests/Regions/ViewsCollectionFixture.cs +++ b/tests/Avalonia/Prism.Avalonia.Tests/Regions/ViewsCollectionFixture.cs @@ -1,7 +1,9 @@ -// NOTE: +// NOTE: // Avalonia.Data.CollectionViewSource control does not exist in Avalonia. // This feature was apart of a legacy build: // https://github.com/grokys/Avalonia/blob/master/Avalonia/Data/CollectionViewSource.cs +// Avalonia PR #14729 in draft as of 2024-04-11 +// https://github.com/AvaloniaUI/Avalonia/pull/14729 using System.Collections; using System.Collections.ObjectModel; using System.Collections.Specialized; @@ -114,7 +116,7 @@ public void CollectionChangedPassesWrappedItemInArgumentsWhenAdding() originalCollection.Remove(filteredInObject); Assert.NotNull(oldItemsPassed); - Assert.Equal(1, oldItemsPassed.Count); + Assert.Single(oldItemsPassed); Assert.Same(filteredInObject.Item, oldItemsPassed[0]); } @@ -130,7 +132,7 @@ public void CollectionChangedPassesWrappedItemInArgumentsWhenRemoving() originalCollection.Add(filteredInObject); Assert.NotNull(newItemsPassed); - Assert.Equal(1, newItemsPassed.Count); + Assert.Single(newItemsPassed); Assert.Same(filteredInObject.Item, newItemsPassed[0]); } @@ -268,6 +270,7 @@ public void OnRemoveOfFilterMatchingItemThenViewCollectionRelativeIndexProvided( Assert.Equal(1, removeEvent.OldStartingIndex); } + //// NOTE: Avalonia.Data.CollectionViewSource control does not exist in Avalonia. ////[Fact] ////public void RemovingFromFilteredCollectionDoesNotThrow() ////{