提交 6a09b9ba 编写于 作者: D Dan Siegel

chore: updating tests for namespace & type name breaks

上级 01ec1ef8
using Xamarin.Forms;
namespace Prism.Regions.Adapters
{
/// <summary>
/// Defines an interfaces to adapt an object and bind it to a new <see cref="IRegion"/>.
/// </summary>
public interface IRegionAdapter
{
/// <summary>
/// Adapts an object and binds it to a new <see cref="IRegion"/>.
/// </summary>
/// <param name="regionTarget">The object to adapt.</param>
/// <param name="regionName">The name of the region to be created.</param>
/// <returns>The new instance of <see cref="IRegion"/> that the <paramref name="regionTarget"/> is bound to.</returns>
IRegion Initialize(VisualElement regionTarget, string regionName);
}
}
...@@ -55,7 +55,7 @@ namespace Prism.Regions.Adapters ...@@ -55,7 +55,7 @@ namespace Prism.Regions.Adapters
/// is of type <typeparamref name="T"/>.</remarks> /// is of type <typeparamref name="T"/>.</remarks>
/// <exception cref="ArgumentNullException">When <paramref name="regionTarget"/> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">When <paramref name="regionTarget"/> is <see langword="null" />.</exception>
/// <exception cref="InvalidOperationException">When <paramref name="regionTarget"/> is not of type <typeparamref name="T"/>.</exception> /// <exception cref="InvalidOperationException">When <paramref name="regionTarget"/> is not of type <typeparamref name="T"/>.</exception>
IRegion IRegionAdapter.Initialize(VisualElement regionTarget, string regionName) IRegion IRegionAdapter.Initialize(object regionTarget, string regionName)
{ {
return Initialize(GetCastedObject(regionTarget), regionName); return Initialize(GetCastedObject(regionTarget), regionName);
} }
......
...@@ -31,7 +31,7 @@ namespace Prism.DI.Forms.Tests.Fixtures.Regions ...@@ -31,7 +31,7 @@ namespace Prism.DI.Forms.Tests.Fixtures.Regions
var vm = _app.MainPage.BindingContext as Issue2415PageViewModel; var vm = _app.MainPage.BindingContext as Issue2415PageViewModel;
Assert.NotNull(vm.Result); Assert.NotNull(vm.Result);
Assert.True(vm.Result.Result); Assert.True(vm.Result.Success);
} }
void IPlatformInitializer.RegisterTypes(IContainerRegistry containerRegistry) void IPlatformInitializer.RegisterTypes(IContainerRegistry containerRegistry)
......
...@@ -18,14 +18,14 @@ namespace Prism.DI.Forms.Tests.Mocks.ViewModels ...@@ -18,14 +18,14 @@ namespace Prism.DI.Forms.Tests.Mocks.ViewModels
_regionManager = regionManager; _regionManager = regionManager;
} }
public IRegionNavigationResult Result { get; private set; } public NavigationResult Result { get; private set; }
public void Initialize(INavigationParameters parameters) public void Initialize(INavigationParameters parameters)
{ {
_regionManager.RequestNavigate("ContentRegion", "Issue2415RegionView", NavigationCallback); _regionManager.RequestNavigate("ContentRegion", "Issue2415RegionView", NavigationCallback);
} }
private void NavigationCallback(IRegionNavigationResult result) private void NavigationCallback(NavigationResult result)
{ {
Result = result; Result = result;
} }
......
...@@ -17,35 +17,35 @@ namespace Prism.Forms.Regions.Mocks ...@@ -17,35 +17,35 @@ namespace Prism.Forms.Regions.Mocks
{ {
Behaviors = new MockRegionBehaviorCollection(); Behaviors = new MockRegionBehaviorCollection();
} }
public IRegionManager Add(VisualElement view) public IRegionManager Add(object view)
{ {
MockViews.Items.Add(view); MockViews.Items.Add(view);
return null; return null;
} }
public void Remove(VisualElement view) public void Remove(object view)
{ {
MockViews.Items.Remove(view); MockViews.Items.Remove(view);
MockActiveViews.Items.Remove(view); MockActiveViews.Items.Remove(view);
} }
public void Activate(VisualElement view) public void Activate(object view)
{ {
MockActiveViews.Items.Add(view); MockActiveViews.Items.Add(view);
} }
public IRegionManager Add(VisualElement view, string viewName) public IRegionManager Add(object view, string viewName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IRegionManager Add(VisualElement view, string viewName, bool createRegionManagerScope) public IRegionManager Add(object view, string viewName, bool createRegionManagerScope)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public VisualElement GetView(string viewName) public object GetView(string viewName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
...@@ -103,12 +103,12 @@ namespace Prism.Forms.Regions.Mocks ...@@ -103,12 +103,12 @@ namespace Prism.Forms.Regions.Mocks
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void RequestNavigate(Uri target, Action<IRegionNavigationResult> navigationCallback) public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void RequestNavigate(Uri target, Action<IRegionNavigationResult> navigationCallback, INavigationParameters navigationParameters) public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback, INavigationParameters navigationParameters)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
...@@ -118,6 +118,11 @@ namespace Prism.Forms.Regions.Mocks ...@@ -118,6 +118,11 @@ namespace Prism.Forms.Regions.Mocks
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void Deactivate(object view)
{
throw new NotImplementedException();
}
public IRegionNavigationService NavigationService public IRegionNavigationService NavigationService
{ {
get => throw new NotImplementedException(); get => throw new NotImplementedException();
...@@ -125,7 +130,7 @@ namespace Prism.Forms.Regions.Mocks ...@@ -125,7 +130,7 @@ namespace Prism.Forms.Regions.Mocks
} }
public Comparison<VisualElement> SortComparison public Comparison<object> SortComparison
{ {
get => throw new NotImplementedException(); get => throw new NotImplementedException();
set => throw new NotImplementedException(); set => throw new NotImplementedException();
......
...@@ -11,7 +11,7 @@ namespace Prism.Forms.Regions.Mocks ...@@ -11,7 +11,7 @@ namespace Prism.Forms.Regions.Mocks
internal class MockRegion : IRegion internal class MockRegion : IRegion
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public Func<string, VisualElement> GetViewStringDelegate { get; set; } public Func<string, object> GetViewStringDelegate { get; set; }
private MockViewsCollection _views = new MockViewsCollection(); private MockViewsCollection _views = new MockViewsCollection();
...@@ -33,38 +33,38 @@ namespace Prism.Forms.Regions.Mocks ...@@ -33,38 +33,38 @@ namespace Prism.Forms.Regions.Mocks
public string Name { get; set; } public string Name { get; set; }
public IRegionManager Add(VisualElement view) public IRegionManager Add(object view)
{ {
_views.Add(view); _views.Add(view);
return null; return null;
} }
public IRegionManager Add(VisualElement view, string viewName) public IRegionManager Add(object view, string viewName)
{ {
return Add(view); return Add(view);
} }
public IRegionManager Add(VisualElement view, string viewName, bool createRegionManagerScope) public IRegionManager Add(object view, string viewName, bool createRegionManagerScope)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void Remove(VisualElement view) public void Remove(object view)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void Activate(VisualElement view) public void Activate(object view)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void Deactivate(VisualElement view) public void Deactivate(object view)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public VisualElement GetView(string viewName) public object GetView(string viewName)
{ {
return GetViewStringDelegate(viewName); return GetViewStringDelegate(viewName);
} }
...@@ -82,12 +82,12 @@ namespace Prism.Forms.Regions.Mocks ...@@ -82,12 +82,12 @@ namespace Prism.Forms.Regions.Mocks
} }
public void RequestNavigate(Uri target, Action<IRegionNavigationResult> navigationCallback) public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void RequestNavigate(Uri target, Action<IRegionNavigationResult> navigationCallback, INavigationParameters navigationParameters) public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback, INavigationParameters navigationParameters)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
...@@ -104,7 +104,7 @@ namespace Prism.Forms.Regions.Mocks ...@@ -104,7 +104,7 @@ namespace Prism.Forms.Regions.Mocks
} }
public Comparison<VisualElement> SortComparison public Comparison<object> SortComparison
{ {
get => throw new NotImplementedException(); get => throw new NotImplementedException();
set => throw new NotImplementedException(); set => throw new NotImplementedException();
......
...@@ -11,14 +11,15 @@ namespace Prism.Forms.Regions.Mocks ...@@ -11,14 +11,15 @@ namespace Prism.Forms.Regions.Mocks
public MockRegionManagerAccessor Accessor; public MockRegionManagerAccessor Accessor;
public IRegion Initialize(VisualElement regionTarget, string regionName) public IRegion Initialize(object regionTarget, string regionName)
{ {
CreatedRegions.Add(regionName); CreatedRegions.Add(regionName);
var region = new MockPresentationRegion(); 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) if (Accessor != null)
Accessor.UpdateRegions(); Accessor.UpdateRegions();
......
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Prism.Regions.Behaviors; using Prism.Regions;
namespace Prism.Forms.Regions.Mocks namespace Prism.Forms.Regions.Mocks
{ {
......
...@@ -9,19 +9,19 @@ namespace Prism.Forms.Regions.Mocks ...@@ -9,19 +9,19 @@ namespace Prism.Forms.Regions.Mocks
{ {
internal class MockViewsCollection : IViewsCollection internal class MockViewsCollection : IViewsCollection
{ {
public ObservableCollection<VisualElement> Items = new ObservableCollection<VisualElement>(); public ObservableCollection<object> Items = new ObservableCollection<object>();
public void Add(VisualElement view) public void Add(object view)
{ {
Items.Add(view); Items.Add(view);
} }
public bool Contains(VisualElement value) public bool Contains(object value)
{ {
return Items.Contains(value); return Items.Contains(value);
} }
public IEnumerator<VisualElement> GetEnumerator() public IEnumerator<object> GetEnumerator()
{ {
return Items.GetEnumerator(); return Items.GetEnumerator();
} }
......
...@@ -124,7 +124,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -124,7 +124,7 @@ namespace Prism.Forms.Regions.Tests
var viewMock = new Mock<View>(); var viewMock = new Mock<View>();
viewMock viewMock
.As<IRegionAware>() .As<IRegionAware>()
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>())) .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(true) .Returns(true)
.Verifiable(); .Verifiable();
...@@ -157,7 +157,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -157,7 +157,7 @@ namespace Prism.Forms.Regions.Tests
var bindingContextMock = new Mock<IRegionAware>(); var bindingContextMock = new Mock<IRegionAware>();
bindingContextMock bindingContextMock
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>())) .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(true) .Returns(true)
.Verifiable(); .Verifiable();
var viewMock = new Mock<View>(); var viewMock = new Mock<View>();
...@@ -226,7 +226,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -226,7 +226,7 @@ namespace Prism.Forms.Regions.Tests
var viewMock = new Mock<View>(); var viewMock = new Mock<View>();
viewMock viewMock
.As<IRegionAware>() .As<IRegionAware>()
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>())) .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(false) .Returns(false)
.Verifiable(); .Verifiable();
...@@ -265,7 +265,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -265,7 +265,7 @@ namespace Prism.Forms.Regions.Tests
var bindingContextMock = new Mock<IRegionAware>(); var bindingContextMock = new Mock<IRegionAware>();
bindingContextMock bindingContextMock
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>())) .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(false) .Returns(false)
.Verifiable(); .Verifiable();
var viewMock = new Mock<View>(); var viewMock = new Mock<View>();
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Moq; using Moq;
using Prism.Regions.Navigation; using Prism.Navigation;
using Prism.Regions;
using Xunit; using Xunit;
namespace Prism.Forms.Regions.Tests namespace Prism.Forms.Regions.Tests
...@@ -43,7 +44,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -43,7 +44,7 @@ namespace Prism.Forms.Regions.Tests
.Setup(nv => .Setup(nv =>
nv.RequestNavigate( nv.RequestNavigate(
It.Is<Uri>(u => !u.IsAbsoluteUri && u.OriginalString == "relative"), It.Is<Uri>(u => !u.IsAbsoluteUri && u.OriginalString == "relative"),
It.Is<Action<IRegionNavigationResult>>(c => c != null))) It.Is<Action<NavigationResult>>(c => c != null)))
.Verifiable(); .Verifiable();
string target = "relative"; string target = "relative";
...@@ -61,7 +62,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -61,7 +62,7 @@ namespace Prism.Forms.Regions.Tests
.Setup(nv => .Setup(nv =>
nv.RequestNavigate( nv.RequestNavigate(
It.Is<Uri>(u => u.IsAbsoluteUri && u.Host == "test" && u.AbsolutePath == "/path"), It.Is<Uri>(u => u.IsAbsoluteUri && u.Host == "test" && u.AbsolutePath == "/path"),
It.Is<Action<IRegionNavigationResult>>(c => c != null))) It.Is<Action<NavigationResult>>(c => c != null)))
.Verifiable(); .Verifiable();
string target = "http://test/path"; string target = "http://test/path";
...@@ -94,7 +95,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -94,7 +95,7 @@ namespace Prism.Forms.Regions.Tests
.Setup(nv => .Setup(nv =>
nv.RequestNavigate( nv.RequestNavigate(
target, target,
It.Is<Action<IRegionNavigationResult>>(c => c != null))) It.Is<Action<NavigationResult>>(c => c != null)))
.Verifiable(); .Verifiable();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Prism.Forms.Regions.Mocks; using Prism.Forms.Regions.Mocks;
using Prism.Regions.Behaviors; using Prism.Regions;
using Xunit; using Xunit;
namespace Prism.Forms.Regions.Tests namespace Prism.Forms.Regions.Tests
......
...@@ -4,7 +4,7 @@ using System.Linq; ...@@ -4,7 +4,7 @@ using System.Linq;
using Moq; using Moq;
using Prism.Forms.Regions.Mocks; using Prism.Forms.Regions.Mocks;
using Prism.Ioc; using Prism.Ioc;
using Prism.Regions.Behaviors; using Prism.Regions;
using Xunit; using Xunit;
namespace Prism.Forms.Regions.Tests namespace Prism.Forms.Regions.Tests
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Prism.Forms.Regions.Mocks; using Prism.Forms.Regions.Mocks;
using Prism.Regions;
using Prism.Regions.Behaviors; using Prism.Regions.Behaviors;
using Xunit; using Xunit;
......
...@@ -484,7 +484,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -484,7 +484,7 @@ namespace Prism.Forms.Regions.Tests
region.Add(view); region.Add(view);
var uri = new Uri(view.GetType().Name, UriKind.Relative); var uri = new Uri(view.GetType().Name, UriKind.Relative);
Action<IRegionNavigationResult> navigationCallback = nr => { }; Action<NavigationResult> navigationCallback = nr => { };
var navigationParameters = new NavigationParameters(); var navigationParameters = new NavigationParameters();
var mockRegionNavigationService = new Mock<IRegionNavigationService>(); var mockRegionNavigationService = new Mock<IRegionNavigationService>();
......
...@@ -479,19 +479,24 @@ namespace Prism.Forms.Regions.Tests ...@@ -479,19 +479,24 @@ namespace Prism.Forms.Regions.Tests
internal class MockRegionContentRegistry : IRegionViewRegistry internal class MockRegionContentRegistry : IRegionViewRegistry
{ {
public Func<string, Type, object> RegisterContentWithViewType; public Func<string, Type, object> RegisterContentWithViewType;
public Func<string, Func<object>, object> RegisterContentWithDelegate; public Func<string, Func<IContainerProvider, object>, object> RegisterContentWithDelegate;
public event EventHandler<ViewRegisteredEventArgs> ContentRegistered; public event EventHandler<ViewRegisteredEventArgs> ContentRegistered;
public IEnumerable<object> GetContents(string regionName) public IEnumerable<object> GetContents(string regionName, IContainerProvider container)
{ {
return null; return null;
} }
public void RegisterViewWithRegion(string regionName, string targetName)
{
throw new NotImplementedException();
}
void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Type viewType) void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Type viewType)
{ {
RegisterContentWithViewType?.Invoke(regionName, viewType); RegisterContentWithViewType?.Invoke(regionName, viewType);
} }
void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func<object> getContentDelegate) void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{ {
RegisterContentWithDelegate?.Invoke(regionName, getContentDelegate); RegisterContentWithDelegate?.Invoke(regionName, getContentDelegate);
......
...@@ -17,7 +17,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -17,7 +17,7 @@ namespace Prism.Forms.Regions.Tests
private static Uri sourceUri = new Uri(source, UriKind.RelativeOrAbsolute); private static Uri sourceUri = new Uri(source, UriKind.RelativeOrAbsolute);
private static INavigationParameters parameters = new NavigationParameters(); private static INavigationParameters parameters = new NavigationParameters();
private static Action<IRegionNavigationResult> callback = (_) => { }; private static Action<NavigationResult> callback = (_) => { };
private static Mock<IRegion> mockRegion; private static Mock<IRegion> mockRegion;
private static Mock<IRegionNavigationService> mockNavigation; private static Mock<IRegionNavigationService> mockNavigation;
...@@ -53,51 +53,51 @@ namespace Prism.Forms.Regions.Tests ...@@ -53,51 +53,51 @@ namespace Prism.Forms.Regions.Tests
[Fact] [Fact]
public void WhenNonExistentRegion_ReturnNavigationResultFalse() public void WhenNonExistentRegion_ReturnNavigationResultFalse()
{ {
IRegionNavigationResult result; NavigationResult result;
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r, parameters); regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r, parameters);
Assert.Equal(false, result.Result); Assert.False(result.Success);
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r); regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r);
Assert.Equal(false, result.Result); Assert.False(result.Success);
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r, parameters); regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r, parameters);
Assert.Equal(false, result.Result); Assert.False(result.Success);
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r); regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r);
Assert.Equal(false, result.Result); Assert.False(result.Success);
} }
[Fact] [Fact]
public void DelegatesCallToRegion_RegionSource() public void DelegatesCallToRegion_RegionSource()
{ {
regionManager.RequestNavigate(region, source); regionManager.RequestNavigate(region, source);
mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny<Action<IRegionNavigationResult>>(), null)); mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny<Action<NavigationResult>>(), null));
} }
[Fact] [Fact]
public void DelegatesCallToRegion_RegionTarget() public void DelegatesCallToRegion_RegionTarget()
{ {
regionManager.RequestNavigate(region, sourceUri); regionManager.RequestNavigate(region, sourceUri);
mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny<Action<IRegionNavigationResult>>(), null)); mockNavigation.Verify((r) => r.RequestNavigate(sourceUri, It.IsAny<Action<NavigationResult>>(), null));
} }
[Fact] [Fact]
public void DelegatesCallToRegion_RegionSourceParameters() public void DelegatesCallToRegion_RegionSourceParameters()
{ {
regionManager.RequestNavigate(region, source, parameters); regionManager.RequestNavigate(region, source, parameters);
mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny<Action<IRegionNavigationResult>>(), parameters)); mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny<Action<NavigationResult>>(), parameters));
} }
[Fact] [Fact]
public void DelegatesCallToRegion_RegionSourceUriParameters() public void DelegatesCallToRegion_RegionSourceUriParameters()
{ {
regionManager.RequestNavigate(region, sourceUri, parameters); regionManager.RequestNavigate(region, sourceUri, parameters);
mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny<Action<IRegionNavigationResult>>(), parameters)); mockRegion.Verify((r) => r.NavigationService.RequestNavigate(sourceUri, It.IsAny<Action<NavigationResult>>(), parameters));
} }
[Fact] [Fact]
......
...@@ -44,7 +44,7 @@ namespace Prism.Forms.Regions.Tests ...@@ -44,7 +44,7 @@ namespace Prism.Forms.Regions.Tests
Assert.NotNull(listener.onViewRegisteredArguments); Assert.NotNull(listener.onViewRegisteredArguments);
Assert.NotNull(listener.onViewRegisteredArguments.GetView); Assert.NotNull(listener.onViewRegisteredArguments.GetView);
var result = listener.onViewRegisteredArguments.GetView(); var result = listener.onViewRegisteredArguments.GetView(containerMock.Object);
Assert.NotNull(result); Assert.NotNull(result);
Assert.IsType<MockContentObject>(result); Assert.IsType<MockContentObject>(result);
} }
......
...@@ -101,7 +101,8 @@ public class RegionFixture : TestBase ...@@ -101,7 +101,8 @@ public class RegionFixture : TestBase
var region = regionManager.Regions.First(x => x.Name == "ContentRegion"); var region = regionManager.Regions.First(x => x.Name == "ContentRegion");
var activeView = region.ActiveViews.First(); var activeView = region.ActiveViews.First();
Assert.IsType<MockRegionViewA>(activeView); Assert.IsType<MockRegionViewA>(activeView);
var viewModel = activeView.BindingContext as MockRegionViewAViewModel; var activeViewAsMockRegionViewA = activeView as MockRegionViewA;
var viewModel = activeViewAsMockRegionViewA.BindingContext as MockRegionViewAViewModel;
Assert.NotNull(viewModel); Assert.NotNull(viewModel);
Assert.NotNull(viewModel.Page); Assert.NotNull(viewModel.Page);
......
...@@ -29,17 +29,17 @@ public class MockRegionViewAViewModel : BindableBase, IRegionAware, IInitialize ...@@ -29,17 +29,17 @@ public class MockRegionViewAViewModel : BindableBase, IRegionAware, IInitialize
Message = message; Message = message;
} }
public bool IsNavigationTarget(INavigationContext navigationContext) public bool IsNavigationTarget(NavigationContext navigationContext)
{ {
return navigationContext.NavigatedName() == "MockRegionViewA"; return navigationContext.NavigatedName() == "MockRegionViewA";
} }
public void OnNavigatedFrom(INavigationContext navigationContext) public void OnNavigatedFrom(NavigationContext navigationContext)
{ {
} }
public void OnNavigatedTo(INavigationContext navigationContext) public void OnNavigatedTo(NavigationContext navigationContext)
{ {
} }
......
using System; using System;
using Prism.Ioc;
using Prism.Navigation; using Prism.Navigation;
using Prism.Regions; using Prism.Regions;
...@@ -89,5 +90,10 @@ namespace Prism.IocContainer.Wpf.Tests.Support.Mocks ...@@ -89,5 +90,10 @@ namespace Prism.IocContainer.Wpf.Tests.Support.Mocks
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IRegionManager RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{
throw new NotImplementedException();
}
} }
} }
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Prism.Ioc;
using Prism.Navigation; using Prism.Navigation;
using Prism.Regions; using Prism.Regions;
...@@ -37,7 +38,7 @@ namespace Prism.Wpf.Tests.Mocks ...@@ -37,7 +38,7 @@ namespace Prism.Wpf.Tests.Mocks
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IRegionManager RegisterViewWithRegion(string regionName, Func<object> getContentDelegate) public IRegionManager RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Prism.Ioc;
using Prism.Regions; using Prism.Regions;
using Prism.Regions.Behaviors; using Prism.Regions.Behaviors;
using Prism.Wpf.Tests.Mocks; using Prism.Wpf.Tests.Mocks;
...@@ -94,7 +95,7 @@ namespace Prism.Wpf.Tests.Regions.Behaviors ...@@ -94,7 +95,7 @@ namespace Prism.Wpf.Tests.Regions.Behaviors
public event EventHandler<ViewRegisteredEventArgs> ContentRegistered; public event EventHandler<ViewRegisteredEventArgs> ContentRegistered;
public IEnumerable<object> GetContents(string regionName) public IEnumerable<object> GetContents(string regionName, IContainerProvider container)
{ {
GetContentsCalled = true; GetContentsCalled = true;
this.GetContentsArgumentRegionName = regionName; this.GetContentsArgumentRegionName = regionName;
...@@ -103,7 +104,7 @@ namespace Prism.Wpf.Tests.Regions.Behaviors ...@@ -103,7 +104,7 @@ namespace Prism.Wpf.Tests.Regions.Behaviors
public void RaiseContentRegistered(string regionName, object view) 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) public void RegisterViewWithRegion(string regionName, Type viewType)
...@@ -111,7 +112,12 @@ namespace Prism.Wpf.Tests.Regions.Behaviors ...@@ -111,7 +112,12 @@ namespace Prism.Wpf.Tests.Regions.Behaviors
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void RegisterViewWithRegion(string regionName, Func<object> getContentDelegate) public void RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{
throw new NotImplementedException();
}
public void RegisterViewWithRegion(string regionName, string targetName)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
......
...@@ -3,6 +3,7 @@ using System.Collections; ...@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls; using System.Windows.Controls;
using Prism.Ioc;
using Prism.Navigation; using Prism.Navigation;
using Prism.Regions; using Prism.Regions;
using Prism.Regions.Behaviors; using Prism.Regions.Behaviors;
...@@ -242,7 +243,7 @@ namespace Prism.Wpf.Tests.Regions.Behaviors ...@@ -242,7 +243,7 @@ namespace Prism.Wpf.Tests.Regions.Behaviors
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IRegionManager RegisterViewWithRegion(string regionName, Func<object> getContentDelegate) public IRegionManager RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using Moq; using Moq;
using Prism.Navigation;
using Prism.Regions; using Prism.Regions;
using Xunit; using Xunit;
......
...@@ -471,7 +471,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -471,7 +471,7 @@ namespace Prism.Wpf.Tests.Regions
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IRegionManager RegisterViewWithRegion(string regionName, Func<object> getContentDelegate) public IRegionManager RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
......
...@@ -408,9 +408,9 @@ namespace Prism.Wpf.Tests.Regions ...@@ -408,9 +408,9 @@ namespace Prism.Wpf.Tests.Regions
var mockRegionContentRegistry = new MockRegionContentRegistry(); var mockRegionContentRegistry = new MockRegionContentRegistry();
string regionName = null; string regionName = null;
Func<object> contentDelegate = null; Func<IContainerProvider, object> contentDelegate = null;
Func<object> expectedDelegate = () => true; Func<IContainerProvider, object> expectedDelegate = _ => true;
mockRegionContentRegistry.RegisterContentWithDelegate = (name, usedDelegate) => mockRegionContentRegistry.RegisterContentWithDelegate = (name, usedDelegate) =>
{ {
regionName = name; regionName = name;
...@@ -474,19 +474,24 @@ namespace Prism.Wpf.Tests.Regions ...@@ -474,19 +474,24 @@ namespace Prism.Wpf.Tests.Regions
internal class MockRegionContentRegistry : IRegionViewRegistry internal class MockRegionContentRegistry : IRegionViewRegistry
{ {
public Func<string, Type, object> RegisterContentWithViewType; public Func<string, Type, object> RegisterContentWithViewType;
public Func<string, Func<object>, object> RegisterContentWithDelegate; public Func<string, Func<IContainerProvider, object>, object> RegisterContentWithDelegate;
public event EventHandler<ViewRegisteredEventArgs> ContentRegistered; public event EventHandler<ViewRegisteredEventArgs> ContentRegistered;
public IEnumerable<object> GetContents(string regionName) public IEnumerable<object> GetContents(string regionName, IContainerProvider container)
{ {
return null; return null;
} }
public void RegisterViewWithRegion(string regionName, string targetName)
{
throw new NotImplementedException();
}
void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Type viewType) void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Type viewType)
{ {
RegisterContentWithViewType?.Invoke(regionName, viewType); RegisterContentWithViewType?.Invoke(regionName, viewType);
} }
void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func<object> getContentDelegate) void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{ {
RegisterContentWithDelegate?.Invoke(regionName, getContentDelegate); RegisterContentWithDelegate?.Invoke(regionName, getContentDelegate);
......
...@@ -56,19 +56,19 @@ namespace Prism.Wpf.Tests.Regions ...@@ -56,19 +56,19 @@ namespace Prism.Wpf.Tests.Regions
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r, parameters); regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r, parameters);
Assert.Equal(false, result.Result); Assert.False(result.Success);
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r); regionManager.RequestNavigate(nonExistentRegion, source, (r) => result = r);
Assert.Equal(false, result.Result); Assert.False(result.Success);
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r, parameters); regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r, parameters);
Assert.Equal(false, result.Result); Assert.False(result.Success);
result = null; result = null;
regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r); regionManager.RequestNavigate(nonExistentRegion, sourceUri, (r) => result = r);
Assert.Equal(false, result.Result); Assert.False(result.Success);
} }
[Fact] [Fact]
......
...@@ -4,6 +4,7 @@ using System.Linq; ...@@ -4,6 +4,7 @@ using System.Linq;
using System.Windows; using System.Windows;
using Moq; using Moq;
using Prism.Ioc; using Prism.Ioc;
using Prism.Navigation;
using Prism.Regions; using Prism.Regions;
using Xunit; using Xunit;
...@@ -40,7 +41,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -40,7 +41,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool isNavigationSuccessful = false; bool isNavigationSuccessful = false;
target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true);
// Verify // Verify
Assert.True(isNavigationSuccessful); Assert.True(isNavigationSuccessful);
...@@ -76,7 +77,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -76,7 +77,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool isNavigationSuccessful = false; bool isNavigationSuccessful = false;
target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true);
// Verify // Verify
Assert.True(isNavigationSuccessful); Assert.True(isNavigationSuccessful);
...@@ -116,7 +117,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -116,7 +117,7 @@ namespace Prism.Wpf.Tests.Regions
new Uri(otherType.GetType().Name, UriKind.Relative), new Uri(otherType.GetType().Name, UriKind.Relative),
nr => nr =>
{ {
error = nr.Error; error = nr.Exception;
}); });
// Verify // Verify
...@@ -148,9 +149,9 @@ namespace Prism.Wpf.Tests.Regions ...@@ -148,9 +149,9 @@ namespace Prism.Wpf.Tests.Regions
target.RequestNavigate((Uri)null, nr => navigationResult = nr); target.RequestNavigate((Uri)null, nr => navigationResult = nr);
// Verify // Verify
Assert.False(navigationResult.Result.Value); Assert.False(navigationResult.Success);
Assert.NotNull(navigationResult.Error); Assert.NotNull(navigationResult.Exception);
Assert.IsType<ArgumentNullException>(navigationResult.Error); Assert.IsType<ArgumentNullException>(navigationResult.Exception);
} }
[Fact] [Fact]
...@@ -435,7 +436,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -435,7 +436,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
var navigationSucceeded = false; var navigationSucceeded = false;
target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Result == true; }); target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Success == true; });
// Verify // Verify
view1Mock.VerifyAll(); view1Mock.VerifyAll();
...@@ -480,7 +481,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -480,7 +481,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
var navigationFailed = false; var navigationFailed = false;
target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; }); target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Success == false; });
// Verify // Verify
view1Mock.VerifyAll(); view1Mock.VerifyAll();
...@@ -567,7 +568,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -567,7 +568,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
var navigationSucceeded = false; var navigationSucceeded = false;
target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Result == true; }); target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Success == true; });
// Verify // Verify
view1DataContextMock.VerifyAll(); view1DataContextMock.VerifyAll();
...@@ -614,7 +615,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -614,7 +615,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
var navigationFailed = false; var navigationFailed = false;
target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; }); target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Success == false; });
// Verify // Verify
view1DataContextMock.VerifyAll(); view1DataContextMock.VerifyAll();
...@@ -662,8 +663,8 @@ namespace Prism.Wpf.Tests.Regions ...@@ -662,8 +663,8 @@ namespace Prism.Wpf.Tests.Regions
bool firstNavigation = false; bool firstNavigation = false;
bool secondNavigation = false; bool secondNavigation = false;
target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Result.Value); target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Success);
target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Result.Value); target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Success);
Assert.Equal(2, confirmationRequests.Count); Assert.Equal(2, confirmationRequests.Count);
...@@ -717,8 +718,8 @@ namespace Prism.Wpf.Tests.Regions ...@@ -717,8 +718,8 @@ namespace Prism.Wpf.Tests.Regions
bool firstNavigation = false; bool firstNavigation = false;
bool secondNavigation = false; bool secondNavigation = false;
target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Result.Value); target.RequestNavigate(navigationUri, nr => firstNavigation = nr.Success);
target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Result.Value); target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Success);
Assert.Equal(2, confirmationRequests.Count); Assert.Equal(2, confirmationRequests.Count);
...@@ -766,7 +767,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -766,7 +767,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool isNavigationSuccessful = false; bool isNavigationSuccessful = false;
target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true);
// Verify // Verify
Assert.True(isNavigationSuccessful); Assert.True(isNavigationSuccessful);
...@@ -810,7 +811,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -810,7 +811,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool isNavigationSuccessful = false; bool isNavigationSuccessful = false;
target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true); target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Success == true);
// Verify // Verify
Assert.True(isNavigationSuccessful); Assert.True(isNavigationSuccessful);
...@@ -850,7 +851,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -850,7 +851,7 @@ namespace Prism.Wpf.Tests.Regions
navigationCallback(true); navigationCallback(true);
Assert.NotNull(result); Assert.NotNull(result);
Assert.Same(targetException, result.Error); Assert.Same(targetException, result.Exception);
} }
[Fact] [Fact]
...@@ -1002,7 +1003,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -1002,7 +1003,7 @@ namespace Prism.Wpf.Tests.Regions
RegionNavigationService target = new RegionNavigationService(container, contentLoader, journal); RegionNavigationService target = new RegionNavigationService(container, contentLoader, journal);
Exception error = null; Exception error = null;
target.RequestNavigate(navigationUri, nr => error = nr.Error); target.RequestNavigate(navigationUri, nr => error = nr.Exception);
Assert.NotNull(error); Assert.NotNull(error);
Assert.IsType<InvalidOperationException>(error); Assert.IsType<InvalidOperationException>(error);
...@@ -1021,7 +1022,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -1021,7 +1022,7 @@ namespace Prism.Wpf.Tests.Regions
}; };
Exception error = null; Exception error = null;
target.RequestNavigate(null, nr => error = nr.Error); target.RequestNavigate(null, nr => error = nr.Exception);
Assert.NotNull(error); Assert.NotNull(error);
Assert.IsType<ArgumentNullException>(error); Assert.IsType<ArgumentNullException>(error);
...@@ -1062,7 +1063,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -1062,7 +1063,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool? isNavigationSuccessful = null; 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 // Verify
Assert.False(isNavigationSuccessful.Value); Assert.False(isNavigationSuccessful.Value);
...@@ -1121,7 +1122,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -1121,7 +1122,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool? isNavigationSuccessful = null; bool? isNavigationSuccessful = null;
target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Result); target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Success);
// Verify // Verify
view1Mock.VerifyAll(); view1Mock.VerifyAll();
...@@ -1183,7 +1184,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -1183,7 +1184,7 @@ namespace Prism.Wpf.Tests.Regions
// Act // Act
bool? isNavigationSuccessful = null; bool? isNavigationSuccessful = null;
target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Result); target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Success);
// Verify // Verify
viewModel1Mock.VerifyAll(); viewModel1Mock.VerifyAll();
......
...@@ -44,7 +44,7 @@ namespace Prism.Wpf.Tests.Regions ...@@ -44,7 +44,7 @@ namespace Prism.Wpf.Tests.Regions
Assert.NotNull(listener.onViewRegisteredArguments); Assert.NotNull(listener.onViewRegisteredArguments);
Assert.NotNull(listener.onViewRegisteredArguments.GetView); Assert.NotNull(listener.onViewRegisteredArguments.GetView);
var result = listener.onViewRegisteredArguments.GetView(); var result = listener.onViewRegisteredArguments.GetView(containerMock.Object);
Assert.NotNull(result); Assert.NotNull(result);
Assert.IsType<MockContentObject>(result); Assert.IsType<MockContentObject>(result);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册