Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Unit Testing for Page navigation from viewmodel is not working

$
0
0

hi all
I want write unit test for navigate to Mastedetail Page from my LoginViewModel
My case is:
Application.Current.MainPage.Navigation.PushModalAsync(new MainPage());
here my MainPage is Masterdetai Page and here if write Unit Test case like this

    [Test]
    public async Task Test1()
    {
        var lvm = new LoginViewModel();
        lvm.Username = "admin";
        lvm.Password = "admin";
        var app = new App();

        var page = new ContentPage();

        Application.Current.MainPage = new MainPage();
        await Application.Current.MainPage.Navigation.PushModalAsync(page1);
        string result = lvm.LoginResult();
        Assert.IsTrue(result == "Success", "test fail");
        Assert.Pass();
    }

its giving System.InvalidOperationException: You MUST call Xamarin.Forms.Init(); prior to using it, error at master detail page line MasterBehavior = MasterBehavior.Popover;

if any one have idea please let me know how to get Application.current.mainpage in unit test project and how to resolve this issue
Thanks In Advance


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>