Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake NavigationManager #117

Closed
egil opened this issue May 2, 2020 · 3 comments · Fixed by #345
Closed

Fake NavigationManager #117

egil opened this issue May 2, 2020 · 3 comments · Fixed by #345
Labels
enhancement New feature or request help wanted Extra attention is needed input needed When an issue requires input or suggestions
Milestone

Comments

@egil
Copy link
Member

egil commented May 2, 2020

It should be possible to create a fake NavigationManager which automatically hooks into click event handlers triggers and raise the OnNavigate events for listeners, exactly as the real NavigationManager does.

Related

@egil egil added enhancement New feature or request input needed When an issue requires input or suggestions help wanted Extra attention is needed labels May 2, 2020
@vertonghenb
Copy link

I'll try to have a go at it this week.

@egil
Copy link
Member Author

egil commented May 5, 2020

Awesome. Please start by posting your design thoughts before you start so we can have a quick review and make sure our thoughts are aligned.

Also, until #119 is done, just focus on mock itself and the kind of events you need to subscribe to in the DOM to make it work. Then we can hash out the needed DOM access services afterwords..

Note to self... I really need to make a basic contributor's guide :-)

@egil egil modified the milestones: beta-7, beta-8 May 6, 2020
@egil egil changed the title NavigationManager mock Fake NavigationManager Jul 29, 2020
@egil egil modified the milestones: beta-8, v1.0.0 Jul 29, 2020
@egil
Copy link
Member Author

egil commented Mar 18, 2021

It turns out it is rather simple to create a fake navigation manager. Here is a sample:

using Bunit.Rendering;
using Microsoft.AspNetCore.Components;

namespace Bunit
{
    public class FakeNavigationManager : NavigationManager
    {
        private readonly ITestRenderer renderer;

        public FakeNavigationManager(ITestRenderer renderer)
        {
            this.renderer = renderer;            
            Initialize("http://localhost/", "http://localhost/");
        }

        protected override void NavigateToCore(string uri, bool forceLoad)
        {
            Uri = ToAbsoluteUri(uri).ToString();

            renderer.Dispatcher.InvokeAsync(
                () => NotifyLocationChanged(isInterceptedLink: false));
        }
    }
}

This could easily be included in bunit and registered by default.

@egil egil closed this as completed Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed input needed When an issue requires input or suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants