Skip to content

Commit

Permalink
chore: updating tests for namespace & type name breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Aug 26, 2023
1 parent ee829f5 commit 331d34b
Show file tree
Hide file tree
Showing 32 changed files with 294 additions and 275 deletions.
18 changes: 0 additions & 18 deletions src/Forms/Prism.Forms.Regions/Regions/Adapters/IRegionAdapter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IRegion Initialize(T regionTarget, string regionName)
/// is of type <typeparamref name="T"/>.</remarks>
/// <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>
IRegion IRegionAdapter.Initialize(VisualElement regionTarget, string regionName)
IRegion IRegionAdapter.Initialize(object regionTarget, string regionName)
{
return Initialize(GetCastedObject(regionTarget), regionName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -103,12 +103,12 @@ public bool Navigate(Uri source)
throw new NotImplementedException();
}

public void RequestNavigate(Uri target, Action<IRegionNavigationResult> navigationCallback)
public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback)
{
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();
}
Expand All @@ -118,14 +118,19 @@ public void RemoveAll()
throw new NotImplementedException();
}

public void Deactivate(object view)
{
throw new NotImplementedException();
}

public IRegionNavigationService NavigationService
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}


public Comparison<VisualElement> SortComparison
public Comparison<object> SortComparison
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
Expand Down
22 changes: 11 additions & 11 deletions tests/Forms/Prism.Forms.Regions.Tests/Mocks/MockRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Prism.Forms.Regions.Mocks
internal class MockRegion : IRegion
{
public event PropertyChangedEventHandler PropertyChanged;
public Func<string, VisualElement> GetViewStringDelegate { get; set; }
public Func<string, object> GetViewStringDelegate { get; set; }

private MockViewsCollection _views = new MockViewsCollection();

Expand All @@ -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);
}
Expand All @@ -82,12 +82,12 @@ public bool Navigate(Uri source)
}


public void RequestNavigate(Uri target, Action<IRegionNavigationResult> navigationCallback)
public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback)
{
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();
}
Expand All @@ -104,7 +104,7 @@ public IRegionNavigationService NavigationService
}


public Comparison<VisualElement> SortComparison
public Comparison<object> SortComparison
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using Prism.Regions.Behaviors;
using Prism.Regions;

namespace Prism.Forms.Regions.Mocks
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ namespace Prism.Forms.Regions.Mocks
{
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);
}

public bool Contains(VisualElement value)
public bool Contains(object value)
{
return Items.Contains(value);
}

public IEnumerator<VisualElement> GetEnumerator()
public IEnumerator<object> GetEnumerator()
{
return Items.GetEnumerator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void WhenViewExistsAndImplementsIRegionAware_ThenViewIsQueriedForNavigati
var viewMock = new Mock<View>();
viewMock
.As<IRegionAware>()
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>()))
.Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(true)
.Verifiable();

Expand Down Expand Up @@ -157,7 +157,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsIRegionAware_ThenDataCo

var bindingContextMock = new Mock<IRegionAware>();
bindingContextMock
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>()))
.Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(true)
.Verifiable();
var viewMock = new Mock<View>();
Expand Down Expand Up @@ -226,7 +226,7 @@ public void WhenViewExistsAndImplementsIRegionAware_ThenViewIsQueriedForNavigati
var viewMock = new Mock<View>();
viewMock
.As<IRegionAware>()
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>()))
.Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(false)
.Verifiable();

Expand Down Expand Up @@ -265,7 +265,7 @@ public void WhenViewExistsAndHasDataContextThatImplementsIRegionAware_ThenDataCo

var bindingContextMock = new Mock<IRegionAware>();
bindingContextMock
.Setup(v => v.IsNavigationTarget(It.IsAny<INavigationContext>()))
.Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
.Returns(false)
.Verifiable();
var viewMock = new Mock<View>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,7 +44,7 @@ public void WhenNavigatingWithARelativeStringTarget_ThenNavigatesToRelativeUri()
.Setup(nv =>
nv.RequestNavigate(
It.Is<Uri>(u => !u.IsAbsoluteUri && u.OriginalString == "relative"),
It.Is<Action<IRegionNavigationResult>>(c => c != null)))
It.Is<Action<NavigationResult>>(c => c != null)))
.Verifiable();

string target = "relative";
Expand All @@ -61,7 +62,7 @@ public void WhenNavigatingWithAnAbsoluteStringTarget_ThenNavigatesToAbsoluteUri(
.Setup(nv =>
nv.RequestNavigate(
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();

string target = "http://test/path";
Expand Down Expand Up @@ -94,7 +95,7 @@ public void WhenNavigatingWithAUri_ThenNavigatesToUriWithCallback()
.Setup(nv =>
nv.RequestNavigate(
target,
It.Is<Action<IRegionNavigationResult>>(c => c != null)))
It.Is<Action<NavigationResult>>(c => c != null)))
.Verifiable();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public void NavigateDelegatesToIRegionNavigationService()
region.Add(view);

var uri = new Uri(view.GetType().Name, UriKind.Relative);
Action<IRegionNavigationResult> navigationCallback = nr => { };
Action<NavigationResult> navigationCallback = nr => { };
var navigationParameters = new NavigationParameters();

var mockRegionNavigationService = new Mock<IRegionNavigationService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,24 @@ public FrameworkException(Exception inner)
internal class MockRegionContentRegistry : IRegionViewRegistry
{
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 IEnumerable<object> GetContents(string regionName)
public IEnumerable<object> 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<object> getContentDelegate)
void IRegionViewRegistry.RegisterViewWithRegion(string regionName, Func<IContainerProvider, object> getContentDelegate)
{
RegisterContentWithDelegate?.Invoke(regionName, getContentDelegate);

Expand Down
Loading

0 comments on commit 331d34b

Please sign in to comment.