public async Task InitializesViewModelOnLoadFailedTest() { NavigationManagerMock navigationManagerMock = new NavigationManagerMock(); TestViewModel viewModel = new TestViewModel(navigationManagerMock); TestPage page = new TestPage { ViewModel = viewModel, NavigationManager = navigationManagerMock, }; viewModel.InitializeResult = false; await page.CallOnAfterRenderAsync(false); Assert.IsFalse(viewModel.WasInitializeCalled); Assert.IsTrue(page.IsLoading); await page.CallOnAfterRenderAsync(true); Assert.AreEqual(navigationManagerMock.NavigatedUri, "/"); Assert.IsTrue(viewModel.WasInitializeCalled); }
public async Task InitializesViewModelOnLoadSuccessTest() { Mock <TestPage> mockPage = new Mock <TestPage>(); mockPage.Protected().Setup("NotifyStateChanged").Callback(() => { }); NavigationManagerMock navigationManagerMock = new NavigationManagerMock(); TestViewModel viewModel = new TestViewModel(navigationManagerMock); TestPage page = mockPage.Object; page.ViewModel = viewModel; page.NavigationManager = navigationManagerMock; viewModel.InitializeResult = true; await page.CallOnAfterRenderAsync(false); Assert.IsFalse(viewModel.WasInitializeCalled); Assert.IsTrue(page.IsLoading); await page.CallOnAfterRenderAsync(true); Assert.IsTrue(viewModel.WasInitializeCalled); Assert.IsFalse(page.IsLoading); }