diff --git a/src/Forms/Prism.Forms.Regions/Regions/Adapters/IRegionAdapter.cs b/src/Forms/Prism.Forms.Regions/Regions/Adapters/IRegionAdapter.cs deleted file mode 100644 index 70387f7918..0000000000 --- a/src/Forms/Prism.Forms.Regions/Regions/Adapters/IRegionAdapter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Xamarin.Forms; - -namespace Prism.Regions.Adapters -{ - /// - /// Defines an interfaces to adapt an object and bind it to a new . - /// - public interface IRegionAdapter - { - /// - /// Adapts an object and binds it to a new . - /// - /// The object to adapt. - /// The name of the region to be created. - /// The new instance of that the is bound to. - IRegion Initialize(VisualElement regionTarget, string regionName); - } -} diff --git a/src/Forms/Prism.Forms.Regions/Regions/Adapters/RegionAdapterBase.cs b/src/Forms/Prism.Forms.Regions/Regions/Adapters/RegionAdapterBase.cs index 750194d9f1..7ca851c3df 100644 --- a/src/Forms/Prism.Forms.Regions/Regions/Adapters/RegionAdapterBase.cs +++ b/src/Forms/Prism.Forms.Regions/Regions/Adapters/RegionAdapterBase.cs @@ -55,7 +55,7 @@ public IRegion Initialize(T regionTarget, string regionName) /// is of type . /// When is . /// When is not of type . - IRegion IRegionAdapter.Initialize(VisualElement regionTarget, string regionName) + IRegion IRegionAdapter.Initialize(object regionTarget, string regionName) { return Initialize(GetCastedObject(regionTarget), regionName); } diff --git a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Regions/RegionFixture.cs b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Regions/RegionFixture.cs index 9377d62edc..a0a9fe6c19 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Regions/RegionFixture.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Regions/RegionFixture.cs @@ -31,7 +31,7 @@ public async Task RegionWorksWhenContentViewIsTopChild() var vm = _app.MainPage.BindingContext as Issue2415PageViewModel; Assert.NotNull(vm.Result); - Assert.True(vm.Result.Result); + Assert.True(vm.Result.Success); } void IPlatformInitializer.RegisterTypes(IContainerRegistry containerRegistry) diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/Issue2415PageViewModel.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/Issue2415PageViewModel.cs index c026bfae9b..8bd37abb2a 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/Issue2415PageViewModel.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/Issue2415PageViewModel.cs @@ -18,14 +18,14 @@ public Issue2415PageViewModel(IRegionManager regionManager) _regionManager = regionManager; } - public IRegionNavigationResult Result { get; private set; } + public NavigationResult Result { get; private set; } public void Initialize(INavigationParameters parameters) { _regionManager.RequestNavigate("ContentRegion", "Issue2415RegionView", NavigationCallback); } - private void NavigationCallback(IRegionNavigationResult result) + private void NavigationCallback(NavigationResult result) { Result = result; } diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockPresentationRegion.cs b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockPresentationRegion.cs index b27a74baf5..f9d068c32c 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockPresentationRegion.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockPresentationRegion.cs @@ -17,35 +17,35 @@ public MockPresentationRegion() { Behaviors = new MockRegionBehaviorCollection(); } - public IRegionManager Add(VisualElement view) + public IRegionManager Add(object view) { MockViews.Items.Add(view); return null; } - public void Remove(VisualElement view) + public void Remove(object view) { MockViews.Items.Remove(view); MockActiveViews.Items.Remove(view); } - public void Activate(VisualElement view) + public void Activate(object view) { MockActiveViews.Items.Add(view); } - public IRegionManager Add(VisualElement view, string viewName) + public IRegionManager Add(object view, string viewName) { throw new NotImplementedException(); } - public IRegionManager Add(VisualElement view, string viewName, bool createRegionManagerScope) + public IRegionManager Add(object view, string viewName, bool createRegionManagerScope) { throw new NotImplementedException(); } - public VisualElement GetView(string viewName) + public object GetView(string viewName) { throw new NotImplementedException(); } @@ -103,12 +103,12 @@ public bool Navigate(Uri source) throw new NotImplementedException(); } - public void RequestNavigate(Uri target, Action navigationCallback) + public void RequestNavigate(Uri target, Action navigationCallback) { throw new NotImplementedException(); } - public void RequestNavigate(Uri target, Action navigationCallback, INavigationParameters navigationParameters) + public void RequestNavigate(Uri target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } @@ -118,6 +118,11 @@ public void RemoveAll() throw new NotImplementedException(); } + public void Deactivate(object view) + { + throw new NotImplementedException(); + } + public IRegionNavigationService NavigationService { get => throw new NotImplementedException(); @@ -125,7 +130,7 @@ public IRegionNavigationService NavigationService } - public Comparison SortComparison + public Comparison SortComparison { get => throw new NotImplementedException(); set => throw new NotImplementedException(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegion.cs b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegion.cs index ae6208a840..4dd6d763f4 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegion.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegion.cs @@ -11,7 +11,7 @@ namespace Prism.Forms.Regions.Mocks internal class MockRegion : IRegion { public event PropertyChangedEventHandler PropertyChanged; - public Func GetViewStringDelegate { get; set; } + public Func GetViewStringDelegate { get; set; } private MockViewsCollection _views = new MockViewsCollection(); @@ -33,38 +33,38 @@ public NavigationParameters NavigationParameters public string Name { get; set; } - public IRegionManager Add(VisualElement view) + public IRegionManager Add(object view) { _views.Add(view); return null; } - public IRegionManager Add(VisualElement view, string viewName) + public IRegionManager Add(object view, string viewName) { return Add(view); } - public IRegionManager Add(VisualElement view, string viewName, bool createRegionManagerScope) + public IRegionManager Add(object view, string viewName, bool createRegionManagerScope) { throw new NotImplementedException(); } - public void Remove(VisualElement view) + public void Remove(object view) { throw new NotImplementedException(); } - public void Activate(VisualElement view) + public void Activate(object view) { throw new NotImplementedException(); } - public void Deactivate(VisualElement view) + public void Deactivate(object view) { throw new NotImplementedException(); } - public VisualElement GetView(string viewName) + public object GetView(string viewName) { return GetViewStringDelegate(viewName); } @@ -82,12 +82,12 @@ public bool Navigate(Uri source) } - public void RequestNavigate(Uri target, Action navigationCallback) + public void RequestNavigate(Uri target, Action navigationCallback) { throw new NotImplementedException(); } - public void RequestNavigate(Uri target, Action navigationCallback, INavigationParameters navigationParameters) + public void RequestNavigate(Uri target, Action navigationCallback, INavigationParameters navigationParameters) { throw new NotImplementedException(); } @@ -104,7 +104,7 @@ public IRegionNavigationService NavigationService } - public Comparison SortComparison + public Comparison SortComparison { get => throw new NotImplementedException(); set => throw new NotImplementedException(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionAdapter.cs b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionAdapter.cs index 2454fdcfbd..bb9cc19e50 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionAdapter.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionAdapter.cs @@ -11,14 +11,15 @@ internal class MockRegionAdapter : IRegionAdapter public MockRegionManagerAccessor Accessor; - public IRegion Initialize(VisualElement regionTarget, string regionName) + public IRegion Initialize(object regionTarget, string regionName) { CreatedRegions.Add(regionName); var region = new MockPresentationRegion(); - Prism.Regions.Xaml.RegionManager.GetObservableRegion(regionTarget).Value = region; + if (regionTarget is VisualElement element) + Prism.Regions.Xaml.RegionManager.GetObservableRegion(element).Value = region; - // Fire update regions again. This also happens if a region is created and added to the regionmanager + // Fire update regions again. This also happens if a region is created and added to the RegionManager if (Accessor != null) Accessor.UpdateRegions(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionBehaviorCollection.cs b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionBehaviorCollection.cs index 13b12aee7f..15b1c88a25 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionBehaviorCollection.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegionBehaviorCollection.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Collections.Generic; -using Prism.Regions.Behaviors; +using Prism.Regions; namespace Prism.Forms.Regions.Mocks { diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockViewsCollection.cs b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockViewsCollection.cs index a72e409bde..cb44f68569 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockViewsCollection.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockViewsCollection.cs @@ -9,19 +9,19 @@ namespace Prism.Forms.Regions.Mocks { internal class MockViewsCollection : IViewsCollection { - public ObservableCollection Items = new ObservableCollection(); + public ObservableCollection Items = new ObservableCollection(); - public void Add(VisualElement view) + public void Add(object view) { Items.Add(view); } - public bool Contains(VisualElement value) + public bool Contains(object value) { return Items.Contains(value); } - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { return Items.GetEnumerator(); } diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/LocatorNavigationTargetHandlerFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/LocatorNavigationTargetHandlerFixture.cs index 9018e75a5e..a83b9808db 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/LocatorNavigationTargetHandlerFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/LocatorNavigationTargetHandlerFixture.cs @@ -124,7 +124,7 @@ public void WhenViewExistsAndImplementsIRegionAware_ThenViewIsQueriedForNavigati var viewMock = new Mock(); viewMock .As() - .Setup(v => v.IsNavigationTarget(It.IsAny())) + .Setup(v => v.IsNavigationTarget(It.IsAny())) .Returns(true) .Verifiable(); @@ -157,7 +157,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsIRegionAware_ThenDataCo var bindingContextMock = new Mock(); bindingContextMock - .Setup(v => v.IsNavigationTarget(It.IsAny())) + .Setup(v => v.IsNavigationTarget(It.IsAny())) .Returns(true) .Verifiable(); var viewMock = new Mock(); @@ -226,7 +226,7 @@ public void WhenViewExistsAndImplementsIRegionAware_ThenViewIsQueriedForNavigati var viewMock = new Mock(); viewMock .As() - .Setup(v => v.IsNavigationTarget(It.IsAny())) + .Setup(v => v.IsNavigationTarget(It.IsAny())) .Returns(false) .Verifiable(); @@ -265,7 +265,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsIRegionAware_ThenDataCo var bindingContextMock = new Mock(); bindingContextMock - .Setup(v => v.IsNavigationTarget(It.IsAny())) + .Setup(v => v.IsNavigationTarget(It.IsAny())) .Returns(false) .Verifiable(); var viewMock = new Mock(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/NavigationAsyncExtensionsFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/NavigationAsyncExtensionsFixture.cs index c042d82290..dfadb836bb 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/NavigationAsyncExtensionsFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/NavigationAsyncExtensionsFixture.cs @@ -2,7 +2,8 @@ using System.Collections.Generic; using System.Text; using Moq; -using Prism.Regions.Navigation; +using Prism.Navigation; +using Prism.Regions; using Xunit; namespace Prism.Forms.Regions.Tests @@ -43,7 +44,7 @@ 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))) .Verifiable(); string target = "relative"; @@ -61,7 +62,7 @@ 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))) .Verifiable(); string target = "http://test/path"; @@ -94,7 +95,7 @@ public void WhenNavigatingWithAUri_ThenNavigatesToUriWithCallback() .Setup(nv => nv.RequestNavigate( target, - It.Is>(c => c != null))) + It.Is>(c => c != null))) .Verifiable(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorCollectionFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorCollectionFixture.cs index 637d4e8537..4823622cae 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorCollectionFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorCollectionFixture.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; using Prism.Forms.Regions.Mocks; -using Prism.Regions.Behaviors; +using Prism.Regions; using Xunit; namespace Prism.Forms.Regions.Tests diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFactoryFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFactoryFixture.cs index f68520deb2..d5ac28bb02 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFactoryFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFactoryFixture.cs @@ -4,7 +4,7 @@ using Moq; using Prism.Forms.Regions.Mocks; using Prism.Ioc; -using Prism.Regions.Behaviors; +using Prism.Regions; using Xunit; namespace Prism.Forms.Regions.Tests diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFixture.cs index 653cc0dbc5..1dad26097c 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionBehaviorFixture.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using Prism.Forms.Regions.Mocks; +using Prism.Regions; using Prism.Regions.Behaviors; using Xunit; diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs index 437ec89585..e67c294150 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionFixture.cs @@ -484,7 +484,7 @@ public void NavigateDelegatesToIRegionNavigationService() region.Add(view); var uri = new Uri(view.GetType().Name, UriKind.Relative); - Action navigationCallback = nr => { }; + Action navigationCallback = nr => { }; var navigationParameters = new NavigationParameters(); var mockRegionNavigationService = new Mock(); diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs index 5876236876..70095001c8 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerFixture.cs @@ -479,19 +479,24 @@ public FrameworkException(Exception 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/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerRequestNavigateFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerRequestNavigateFixture.cs index 1ca5791d87..925519d853 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerRequestNavigateFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionManagerRequestNavigateFixture.cs @@ -17,7 +17,7 @@ public class RegionManagerRequestNavigateFixture private static Uri sourceUri = new Uri(source, UriKind.RelativeOrAbsolute); private static INavigationParameters parameters = new NavigationParameters(); - private static Action callback = (_) => { }; + private static Action callback = (_) => { }; private static Mock mockRegion; private static Mock mockNavigation; @@ -53,51 +53,51 @@ public void DoesNotThrowWhenNavigationCallbackIsNull() [Fact] public void WhenNonExistentRegion_ReturnNavigationResultFalse() { - IRegionNavigationResult result; + NavigationResult result; 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); - mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), null)); + mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), null)); } [Fact] public void DelegatesCallToRegion_RegionTarget() { regionManager.RequestNavigate(region, sourceUri); - mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), null)); + mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny>(), null)); } [Fact] public void DelegatesCallToRegion_RegionSourceParameters() { regionManager.RequestNavigate(region, source, parameters); - mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny>(), parameters)); + mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny>(), parameters)); } [Fact] public void DelegatesCallToRegion_RegionSourceUriParameters() { regionManager.RequestNavigate(region, sourceUri, parameters); - mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny>(), parameters)); + mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny>(), parameters)); } [Fact] diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationJournalFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationJournalFixture.cs index c500b8792f..a444489dd7 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationJournalFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationJournalFixture.cs @@ -3,6 +3,7 @@ using System.Text; using Moq; using Prism.Navigation; +using Prism.Regions; using Prism.Regions.Navigation; using Xunit; @@ -134,14 +135,14 @@ public void GoBackNavigatesBack() mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); // Act target.GoBack(); @@ -151,9 +152,9 @@ public void GoBackNavigatesBack() Assert.True(target.CanGoForward); Assert.Same(entry2, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); } [Fact] @@ -180,14 +181,14 @@ public void GoBackDoesNotChangeStateWhenNavigationFails() mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, false))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, false))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); // Act target.GoBack(); @@ -197,9 +198,9 @@ public void GoBackDoesNotChangeStateWhenNavigationFails() Assert.False(target.CanGoForward); Assert.Same(entry3, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); } [Fact] @@ -226,14 +227,14 @@ public void GoBackMultipleTimesNavigatesBack() mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); // Act target.GoBack(); @@ -244,9 +245,9 @@ public void GoBackMultipleTimesNavigatesBack() Assert.True(target.CanGoForward); Assert.Same(entry1, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); } [Fact] @@ -272,14 +273,14 @@ public void GoForwardNavigatesForward() target.RecordNavigation(entry3, true); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); target.GoBack(); target.GoBack(); @@ -292,9 +293,9 @@ public void GoForwardNavigatesForward() Assert.True(target.CanGoForward); Assert.Same(entry2, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Exactly(2)); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Exactly(2)); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); } [Fact] @@ -320,14 +321,14 @@ public void GoForwardDoesNotChangeStateWhenNavigationFails() target.RecordNavigation(entry3, true); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, false))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, false))); target.GoBack(); @@ -339,9 +340,9 @@ public void GoForwardDoesNotChangeStateWhenNavigationFails() Assert.True(target.CanGoForward); Assert.Same(entry2, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Once()); } [Fact] @@ -367,14 +368,14 @@ public void GoForwardMultipleTimesNavigatesForward() target.RecordNavigation(entry3, true); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); target.GoBack(); target.GoBack(); @@ -388,9 +389,9 @@ public void GoForwardMultipleTimesNavigatesForward() Assert.False(target.CanGoForward); Assert.Same(entry3, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Exactly(2)); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Exactly(2)); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Once()); } [Fact] @@ -418,14 +419,14 @@ public void WhenNavigationToNewUri_ThenCanNoLongerNavigateForward() target.RecordNavigation(entry2, true); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); target.GoBack(); @@ -466,17 +467,17 @@ public void WhenSavePreviousFalseDoNotRecordEntry() target.RecordNavigation(entry4, true); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri1, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri2, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri3, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); mockNavigationTarget - .Setup(x => x.RequestNavigate(uri4, It.IsAny>(), null)) - .Callback, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true))); + .Setup(x => x.RequestNavigate(uri4, It.IsAny>(), null)) + .Callback, INavigationParameters>((u, c, n) => c(new NavigationResult(null, true))); Assert.Equal(entry4, target.CurrentEntry); @@ -486,10 +487,10 @@ public void WhenSavePreviousFalseDoNotRecordEntry() Assert.True(target.CanGoForward); Assert.Same(entry2, target.CurrentEntry); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); - mockNavigationTarget.Verify(x => x.RequestNavigate(uri4, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny>(), null), Times.Once()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny>(), null), Times.Never()); + mockNavigationTarget.Verify(x => x.RequestNavigate(uri4, It.IsAny>(), null), Times.Never()); } } } diff --git a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationServiceFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationServiceFixture.cs index d9ed454828..afdcaea510 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationServiceFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionNavigationServiceFixture.cs @@ -3,6 +3,7 @@ using System.Linq; using Moq; using Prism.Ioc; +using Prism.Navigation; using Prism.Regions; using Prism.Regions.Navigation; using Xamarin.Forms; @@ -41,7 +42,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); @@ -77,7 +78,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); @@ -102,7 +103,7 @@ public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError() IContainerExtension container = containerMock.Object; var targetHandlerMock = new Mock(); - targetHandlerMock.Setup(th => th.LoadContent(It.IsAny(), It.IsAny())).Throws(); + targetHandlerMock.Setup(th => th.LoadContent(It.IsAny(), It.IsAny())).Throws(); IRegionNavigationJournal journal = Mock.Of(); @@ -117,7 +118,7 @@ public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError() new Uri(otherType.GetType().Name, UriKind.Relative), nr => { - error = nr.Error; + error = nr.Exception; }); // Verify @@ -145,13 +146,13 @@ public void WhenNavigatingWithNullUri_Throws() }; // Act - IRegionNavigationResult navigationResult = null; + NavigationResult navigationResult = null; 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] @@ -163,7 +164,7 @@ public void WhenNavigatingAndViewImplementsIRegionAware_ThenNavigatedIsInvokedOn var viewMock = new Mock(); viewMock .As() - .Setup(ina => ina.IsNavigationTarget(It.IsAny())) + .Setup(ina => ina.IsNavigationTarget(It.IsAny())) .Returns(true); var view = viewMock.Object; region.Add(view); @@ -188,7 +189,7 @@ public void WhenNavigatingAndViewImplementsIRegionAware_ThenNavigatedIsInvokedOn // Verify viewMock .As() - .Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri && nc.NavigationService == target))); + .Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri && nc.NavigationService == target))); } [Fact] @@ -200,7 +201,7 @@ public void WhenNavigatingAndBindingContextImplementsIRegionAware_ThenNavigatedI var mockView = new Mock(); var mockIRegionAwareBindingContext = new Mock(); mockIRegionAwareBindingContext - .Setup(ina => ina.IsNavigationTarget(It.IsAny())) + .Setup(ina => ina.IsNavigationTarget(It.IsAny())) .Returns(true); mockView.Object.BindingContext = mockIRegionAwareBindingContext.Object; @@ -225,7 +226,7 @@ public void WhenNavigatingAndBindingContextImplementsIRegionAware_ThenNavigatedI target.RequestNavigate(navigationUri, nr => { }); // Verify - mockIRegionAwareBindingContext.Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri))); + mockIRegionAwareBindingContext.Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri))); } [Fact] @@ -237,11 +238,11 @@ public void WhenNavigatingAndBothViewAndBindingContextImplementIRegionAware_Then var mockView = new Mock(); var mockIRegionAwareView = mockView.As(); mockIRegionAwareView - .Setup(ina => ina.IsNavigationTarget(It.IsAny())) + .Setup(ina => ina.IsNavigationTarget(It.IsAny())) .Returns(true); var mockIRegionAwareBindingContext = new Mock(); - mockIRegionAwareBindingContext.Setup(ina => ina.IsNavigationTarget(It.IsAny())).Returns(true); + mockIRegionAwareBindingContext.Setup(ina => ina.IsNavigationTarget(It.IsAny())).Returns(true); mockView.Object.BindingContext = mockIRegionAwareBindingContext.Object; var view = mockView.Object; @@ -265,8 +266,8 @@ public void WhenNavigatingAndBothViewAndBindingContextImplementIRegionAware_Then target.RequestNavigate(navigationUri, nr => { }); // Verify - mockIRegionAwareView.Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri))); - mockIRegionAwareBindingContext.Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri))); + mockIRegionAwareView.Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri))); + mockIRegionAwareBindingContext.Verify(v => v.OnNavigatedTo(It.Is(nc => nc.Uri == navigationUri))); } [Fact] @@ -319,8 +320,8 @@ public void WhenNavigatingAndCurrentlyActiveViewImplementsINavigateWithVeto_Then var viewMock = new Mock(); viewMock - .As() - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .As() + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) .Verifiable(); var view = viewMock.Object; @@ -356,9 +357,9 @@ public void WhenNavigating_ThenNavigationRequestQueriesForVetoOnAllActiveViewsIf var view1Mock = new Mock(); view1Mock - .As() - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(true)) + .As() + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(true)) .Verifiable(); var view1 = view1Mock.Object; @@ -366,7 +367,7 @@ public void WhenNavigating_ThenNavigationRequestQueriesForVetoOnAllActiveViewsIf region.Activate(view1); var view2Mock = new Mock(); - view2Mock.As(); + view2Mock.As(); var view2 = view2Mock.Object; region.Add(view2); @@ -380,9 +381,9 @@ public void WhenNavigating_ThenNavigationRequestQueriesForVetoOnAllActiveViewsIf var view4Mock = new Mock(); view4Mock - .As() - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(true)) + .As() + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(true)) .Verifiable(); var view4 = view4Mock.Object; @@ -409,8 +410,8 @@ public void WhenNavigating_ThenNavigationRequestQueriesForVetoOnAllActiveViewsIf // Verify view1Mock.VerifyAll(); view2Mock - .As() - .Verify(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>()), Times.Never()); + .As() + .Verify(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>()), Times.Never()); view3Mock.VerifyAll(); view4Mock.VerifyAll(); } @@ -423,9 +424,9 @@ public void WhenRequestNavigateAwayAcceptsThroughCallback_ThenNavigationProceeds var view1Mock = new Mock(); view1Mock - .As() - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(true)) + .As() + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(true)) .Verifiable(); var view1 = view1Mock.Object; @@ -453,7 +454,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(); @@ -469,9 +470,9 @@ public void WhenRequestNavigateAwayRejectsThroughCallback_ThenNavigationDoesNotP var view1Mock = new Mock(); view1Mock - .As() - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(false)) + .As() + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(false)) .Verifiable(); var view1 = view1Mock.Object; @@ -499,7 +500,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(); @@ -513,9 +514,9 @@ public void WhenNavigatingAndBindingContextOnCurrentlyActiveViewImplementsINavig // Prepare var region = new Region(); - var viewModelMock = new Mock(); + var viewModelMock = new Mock(); viewModelMock - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) .Verifiable(); var viewMock = new Mock(); @@ -553,10 +554,10 @@ public void WhenRequestNavigateAwayOnBindingContextAcceptsThroughCallback_ThenNa // Prepare var region = new Region(); - var view1BindingContextMock = new Mock(); + var view1BindingContextMock = new Mock(); view1BindingContextMock - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(true)) + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(true)) .Verifiable(); var view1Mock = new Mock(); @@ -586,7 +587,7 @@ public void WhenRequestNavigateAwayOnBindingContextAcceptsThroughCallback_ThenNa // Act var navigationSucceeded = false; - target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Result == true; }); + target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Success == true; }); // Verify view1BindingContextMock.VerifyAll(); @@ -600,10 +601,10 @@ public void WhenRequestNavigateAwayOnBindingContextRejectsThroughCallback_ThenNa // Prepare var region = new Region(); - var view1BindingContextMock = new Mock(); + var view1BindingContextMock = new Mock(); view1BindingContextMock - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(false)) + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(false)) .Verifiable(); var view1Mock = new Mock(); @@ -633,7 +634,7 @@ public void WhenRequestNavigateAwayOnBindingContextRejectsThroughCallback_ThenNa // Act var navigationFailed = false; - target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; }); + target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Success == false; }); // Verify view1BindingContextMock.VerifyAll(); @@ -651,9 +652,9 @@ public void WhenViewAcceptsNavigationOutAfterNewIncomingRequestIsReceived_ThenOr var confirmationRequests = new List>(); viewMock - .As() - .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => { confirmationRequests.Add(c); }); + .As() + .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => { confirmationRequests.Add(c); }); var view = viewMock.Object; region.Add(view); @@ -668,7 +669,7 @@ public void WhenViewAcceptsNavigationOutAfterNewIncomingRequestIsReceived_ThenOr var contentLoaderMock = new Mock(); contentLoaderMock - .Setup(cl => cl.LoadContent(region, It.IsAny())) + .Setup(cl => cl.LoadContent(region, It.IsAny())) .Returns(view); var container = containerMock.Object; @@ -682,8 +683,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); @@ -699,7 +700,7 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T { var region = new Region(); - var viewModelMock = new Mock(); + var viewModelMock = new Mock(); var viewMock = new Mock(); var view = viewMock.Object; @@ -708,8 +709,8 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T var confirmationRequests = new List>(); viewModelMock - .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => { confirmationRequests.Add(c); }); + .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => { confirmationRequests.Add(c); }); region.Add(view); region.Activate(view); @@ -723,7 +724,7 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T var contentLoaderMock = new Mock(); contentLoaderMock - .Setup(cl => cl.LoadContent(region, It.IsAny())) + .Setup(cl => cl.LoadContent(region, It.IsAny())) .Returns(view); var container = containerMock.Object; @@ -735,8 +736,8 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T Region = region }; - IRegionNavigationResult firstNavigation = null; - IRegionNavigationResult secondNavigation = null; + NavigationResult firstNavigation = null; + NavigationResult secondNavigation = null; target.RequestNavigate(navigationUri, nr => firstNavigation = nr); target.RequestNavigate(navigationUri, nr => secondNavigation = nr); @@ -745,8 +746,8 @@ public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_T confirmationRequests[0](true); confirmationRequests[1](true); - Assert.False(firstNavigation.Result); - Assert.True(secondNavigation.Result.Value); + Assert.False(firstNavigation.Success); + Assert.True(secondNavigation.Success); } [Fact] @@ -786,7 +787,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); @@ -830,7 +831,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); @@ -845,7 +846,7 @@ public void WhenTargetViewCreationThrowsWithAsyncConfirmation_ThenExceptionIsPro var targetException = new Exception(); var targetHandlerMock = new Mock(); targetHandlerMock - .Setup(th => th.LoadContent(It.IsAny(), It.IsAny())) + .Setup(th => th.LoadContent(It.IsAny(), It.IsAny())) .Throws(targetException); var journalMock = new Mock(); @@ -853,9 +854,9 @@ public void WhenTargetViewCreationThrowsWithAsyncConfirmation_ThenExceptionIsPro Action navigationCallback = null; var viewMock = new Mock(); viewMock - .As() - .Setup(v => v.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => { navigationCallback = c; }); + .As() + .Setup(v => v.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => { navigationCallback = c; }); var region = new Region(); region.Add(viewMock.Object); @@ -866,12 +867,12 @@ public void WhenTargetViewCreationThrowsWithAsyncConfirmation_ThenExceptionIsPro Region = region }; - IRegionNavigationResult result = null; + NavigationResult result = null; target.RequestNavigate(new Uri("", UriKind.Relative), nr => result = nr); navigationCallback(true); Assert.NotNull(result); - Assert.Same(targetException, result.Error); + Assert.Same(targetException, result.Exception); } [Fact] @@ -908,7 +909,7 @@ public void WhenNavigatingFromViewThatIsNavigationAware_ThenNotifiesActiveViewNa // Verify viewMock.As() - .Verify(v => v.OnNavigatedFrom(It.Is(ctx => ctx.Uri == navigationUri && ctx.Parameters.Count() == 0))); + .Verify(v => v.OnNavigatedFrom(It.Is(ctx => ctx.Uri == navigationUri && ctx.Parameters.Count() == 0))); } [Fact] @@ -923,7 +924,7 @@ public void WhenNavigationFromViewThatIsNavigationAware_OnlyNotifiesOnNavigateFr var viewMock = new Mock(); viewMock .As() - .Setup(x => x.OnNavigatedFrom(It.IsAny())).Callback(() => navigationFromInvoked = true); + .Setup(x => x.OnNavigatedFrom(It.IsAny())).Callback(() => navigationFromInvoked = true); var view = viewMock.Object; region.Add(view); @@ -958,7 +959,7 @@ public void WhenNavigationFromViewThatIsNavigationAware_OnlyNotifiesOnNavigateFr } [Fact] - public void WhenNavigatingFromActiveViewWithNavigatinAwareDataConext_NotifiesContextOfNavigatingFrom() + public void WhenNavigatingFromActiveViewWithNavigationAwareDataContext_NotifiesContextOfNavigatingFrom() { // Arrange var region = new Region(); @@ -993,7 +994,7 @@ public void WhenNavigatingFromActiveViewWithNavigatinAwareDataConext_NotifiesCon target.RequestNavigate(navigationUri, nr => { }); // Verify - mockBindingContext.Verify(v => v.OnNavigatedFrom(It.Is(ctx => ctx.Uri == navigationUri && ctx.Parameters.Count() == 0))); + mockBindingContext.Verify(v => v.OnNavigatedFrom(It.Is(ctx => ctx.Uri == navigationUri && ctx.Parameters.Count() == 0))); } [Fact] @@ -1014,7 +1015,7 @@ public void WhenNavigatingWithNullCallback_ThenThrows() ExceptionAssert.Throws( () => { - target.RequestNavigate(navigationUri, null); + target.RequestNavigate(navigationUri); }); } @@ -1029,7 +1030,7 @@ public void WhenNavigatingWithNoRegionSet_ThenMarshallExceptionToCallback() var 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); @@ -1048,7 +1049,7 @@ public void WhenNavigatingWithNullUri_ThenMarshallExceptionToCallback() }; Exception error = null; - target.RequestNavigate(null, nr => error = nr.Error); + target.RequestNavigate("", nr => error = nr.Exception); Assert.NotNull(error); Assert.IsType(error); @@ -1066,7 +1067,7 @@ public void WhenNavigationFailsBecauseTheContentViewCannotBeRetrieved_ThenNaviga var contentLoaderMock = new Mock(); contentLoaderMock - .Setup(cl => cl.LoadContent(region, It.IsAny())) + .Setup(cl => cl.LoadContent(region, It.IsAny())) .Throws(); var container = containerMock.Object; @@ -1089,7 +1090,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); @@ -1105,9 +1106,9 @@ public void WhenNavigationFailsBecauseActiveViewRejectsIt_ThenNavigationFailedIs var view1Mock = new Mock(); view1Mock - .As() - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(false)) + .As() + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(false)) .Verifiable(); var view1 = view1Mock.Object; @@ -1126,7 +1127,7 @@ public void WhenNavigationFailsBecauseActiveViewRejectsIt_ThenNavigationFailedIs var contentLoaderMock = new Mock(); contentLoaderMock - .Setup(cl => cl.LoadContent(region, It.IsAny())) + .Setup(cl => cl.LoadContent(region, It.IsAny())) .Returns(view2); var container = containerMock.Object; @@ -1149,7 +1150,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(); @@ -1164,10 +1165,10 @@ public void WhenNavigationFailsBecauseBindingContextForActiveViewRejectsIt_ThenN // Prepare var region = new Region { Name = "RegionName" }; - var viewModel1Mock = new Mock(); + var viewModel1Mock = new Mock(); viewModel1Mock - .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) - .Callback>((nc, c) => c(false)) + .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny(), It.IsAny>())) + .Callback>((nc, c) => c(false)) .Verifiable(); var view1Mock = new Mock(); @@ -1188,7 +1189,7 @@ public void WhenNavigationFailsBecauseBindingContextForActiveViewRejectsIt_ThenN var contentLoaderMock = new Mock(); contentLoaderMock - .Setup(cl => cl.LoadContent(region, It.IsAny())) + .Setup(cl => cl.LoadContent(region, It.IsAny())) .Returns(view2); var container = containerMock.Object; @@ -1211,7 +1212,7 @@ public void WhenNavigationFailsBecauseBindingContextForActiveViewRejectsIt_ThenN // 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/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs index e89ccc82a0..29042e43b8 100644 --- a/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs +++ b/tests/Forms/Prism.Forms.Regions.Tests/Tests/RegionViewRegistryFixture.cs @@ -44,7 +44,7 @@ public void ShouldRaiseEventWhenAddingContent() Assert.NotNull(listener.onViewRegisteredArguments); Assert.NotNull(listener.onViewRegisteredArguments.GetView); - var result = listener.onViewRegisteredArguments.GetView(); + var result = listener.onViewRegisteredArguments.GetView(containerMock.Object); Assert.NotNull(result); Assert.IsType(result); } diff --git a/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Regions/RegionFixture.cs b/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Regions/RegionFixture.cs index c3c39dbd0d..83e8131804 100644 --- a/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Regions/RegionFixture.cs +++ b/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Regions/RegionFixture.cs @@ -101,7 +101,8 @@ public void RegionViewModel_HasPageAccessor_WithCorrectPage() var region = regionManager.Regions.First(x => x.Name == "ContentRegion"); var activeView = region.ActiveViews.First(); Assert.IsType(activeView); - var viewModel = activeView.BindingContext as MockRegionViewAViewModel; + var activeViewAsMockRegionViewA = activeView as MockRegionViewA; + var viewModel = activeViewAsMockRegionViewA.BindingContext as MockRegionViewAViewModel; Assert.NotNull(viewModel); Assert.NotNull(viewModel.Page); diff --git a/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockRegionViewAViewModel.cs b/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockRegionViewAViewModel.cs index 740ac9bca5..a668082357 100644 --- a/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockRegionViewAViewModel.cs +++ b/tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/MockRegionViewAViewModel.cs @@ -29,17 +29,17 @@ public void Initialize(INavigationParameters parameters) Message = message; } - public bool IsNavigationTarget(INavigationContext navigationContext) + public bool IsNavigationTarget(NavigationContext navigationContext) { return navigationContext.NavigatedName() == "MockRegionViewA"; } - public void OnNavigatedFrom(INavigationContext navigationContext) + public void OnNavigatedFrom(NavigationContext navigationContext) { } - public void OnNavigatedTo(INavigationContext navigationContext) + public void OnNavigatedTo(NavigationContext navigationContext) { } diff --git a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/MockRegionManager.cs b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/MockRegionManager.cs index 22a1eac798..b31f8cf7b2 100644 --- a/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/MockRegionManager.cs +++ b/tests/Wpf/Prism.IocContainer.Wpf.Tests.Support/Mocks/MockRegionManager.cs @@ -1,4 +1,5 @@ using System; +using Prism.Ioc; using Prism.Navigation; using Prism.Regions; @@ -89,5 +90,10 @@ public IRegionManager RegisterViewWithRegion(string regionName, string viewName) { throw new NotImplementedException(); } + + public IRegionManager RegisterViewWithRegion(string regionName, Func getContentDelegate) + { + throw new NotImplementedException(); + } } } diff --git a/tests/Wpf/Prism.Wpf.Tests/Mocks/MockRegionManager.cs b/tests/Wpf/Prism.Wpf.Tests/Mocks/MockRegionManager.cs index 49642ab471..838445b505 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Mocks/MockRegionManager.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Mocks/MockRegionManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using Prism.Ioc; using Prism.Navigation; using Prism.Regions; @@ -37,7 +38,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(); } diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs index 4c4b5a13ba..a0903376ec 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/AutoPopulateRegionBehaviorFixture.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using Prism.Ioc; using Prism.Regions; using Prism.Regions.Behaviors; using Prism.Wpf.Tests.Mocks; @@ -94,7 +95,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; @@ -103,7 +104,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) @@ -111,7 +112,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/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionManagerRegistrationBehaviorFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionManagerRegistrationBehaviorFixture.cs index 326948ef33..6635b65cc0 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionManagerRegistrationBehaviorFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionManagerRegistrationBehaviorFixture.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Controls; +using Prism.Ioc; using Prism.Navigation; using Prism.Regions; using Prism.Regions.Behaviors; @@ -242,7 +243,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(); } diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs index 2b9c178346..dcdcc71a88 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/NavigationAsyncExtensionsFixture.cs @@ -2,6 +2,7 @@ using System; using Moq; +using Prism.Navigation; using Prism.Regions; using Xunit; diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs index 3ff8bfbbc3..a3f01dc1a6 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionFixture.cs @@ -471,7 +471,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(); } diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs index 458ced8231..0c67c26307 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerFixture.cs @@ -408,9 +408,9 @@ 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; @@ -474,19 +474,24 @@ public FrameworkException(Exception 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/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs index fc04ce9f10..7c86855dfb 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionManagerRequestNavigateFixture.cs @@ -56,19 +56,19 @@ 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] diff --git a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs index b8a49110c0..862a09dcd2 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionNavigationServiceFixture.new.cs @@ -4,6 +4,7 @@ using System.Windows; using Moq; using Prism.Ioc; +using Prism.Navigation; using Prism.Regions; using Xunit; @@ -40,7 +41,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); @@ -76,7 +77,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); @@ -116,7 +117,7 @@ public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError() new Uri(otherType.GetType().Name, UriKind.Relative), nr => { - error = nr.Error; + error = nr.Exception; }); // Verify @@ -148,9 +149,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] @@ -435,7 +436,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(); @@ -480,7 +481,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(); @@ -567,7 +568,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(); @@ -614,7 +615,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(); @@ -662,8 +663,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); @@ -717,8 +718,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); @@ -766,7 +767,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); @@ -810,7 +811,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); @@ -850,7 +851,7 @@ public void WhenTargetViewCreationThrowsWithAsyncConfirmation_ThenExceptionIsPro navigationCallback(true); Assert.NotNull(result); - Assert.Same(targetException, result.Error); + Assert.Same(targetException, result.Exception); } [Fact] @@ -1002,7 +1003,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); @@ -1021,7 +1022,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); @@ -1062,7 +1063,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); @@ -1121,7 +1122,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(); @@ -1183,7 +1184,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/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs index 2157a53d63..925e45b258 100644 --- a/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs +++ b/tests/Wpf/Prism.Wpf.Tests/Regions/RegionViewRegistryFixture.cs @@ -44,7 +44,7 @@ public void ShouldRaiseEventWhenAddingContent() Assert.NotNull(listener.onViewRegisteredArguments); Assert.NotNull(listener.onViewRegisteredArguments.GetView); - var result = listener.onViewRegisteredArguments.GetView(); + var result = listener.onViewRegisteredArguments.GetView(containerMock.Object); Assert.NotNull(result); Assert.IsType(result); }