public async Task ReportIssue_WhenIssueIsValid_ShouldReportTheIssue() { // Arrange var issue = Fixture.Create <Issue>(); var alertErrorTitle = "Let op!"; var alertErrorMessage = "Het emailadres of de beschrijving is niet ingevuld!"; var alertErrorCancelButton = "Ok"; var alertConfirmationTitle = "Bedankt!"; var alertConfirmationMessage = "Bedankt voor het melden van het probleem!"; var alertConfirmationCancelButton = "Geen probleem"; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertErrorTitle, alertErrorMessage, alertErrorCancelButton)).Verifiable(); ReportingServiceMock.Setup(reportingService => reportingService.ReportIssue(issue)).Returns(Task.Run(() => true)); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertConfirmationTitle, alertConfirmationMessage, alertConfirmationCancelButton)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act ReportIssueSettingsPageViewModel.Issue = issue; await ReportIssueSettingsPageViewModel.ReportIssue(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertErrorTitle, alertErrorMessage, alertErrorCancelButton), Times.Never, "Alert for invalid issue called atleast once."); ReportingServiceMock.Verify(reportingService => reportingService.ReportIssue(issue), Times.Once, "Function ReportingService.ReportIssue not called exactly once."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertConfirmationTitle, alertConfirmationMessage, alertConfirmationCancelButton), Times.Once, "Alert for succesfully reporting an issue not called exactly once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Once, "Function INavigationService.OnCancelPressed not called exactly once."); }
public void OnCancelCommand_Response(bool confirmAlert) { // Arrange var alertTitle = "Pas op!"; var alertMessage = "Niet opgeslagen gegevens worden verwijderd! Weer u zeker dat u terug wilt gaan?"; var alertAcceptButton = "Ja"; var alertCancelButton = "Nee"; var expectedParameters = new NavigationParameters() { { "SelectedRecipe", SelectedRecipe.Id } }; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton)).Returns(Task.Run(() => confirmAlert)); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act EditRecipePageViewModel.Recipe = SelectedRecipe; EditRecipePageViewModel.OnCancelCommand?.Execute(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton), Times.Once, "Confirmation alert for cancelling editting the recipe not called exactly once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Never, "Function INavigationService.GoBackAsync called atleast once."); if (confirmAlert) { NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync($"../../{nameof(DisplayRecipePage)}", expectedParameters), Times.Once, "Function to navigate to display recipe page with recipe id not called exactly once."); } else { NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync($"../../{nameof(DisplayRecipePage)}", expectedParameters), Times.Never, "Function to navigate to display recipe page with recipe id called atleast once."); } }
public async Task SaveRecipe_NotInCreateModeWhenCanceled_ShouldDoNothing() { // Arrange var alertTitle = "Pas op!"; var alertMessage = "Deze actie kan niet ongedaan worden."; var alertAcceptButton = "Opslaan"; var alertCancelButton = "Annuleer"; var displayRecipePageName = $"../{nameof(DisplayRecipePage)}"; var expectedParameters = new NavigationParameters { { "SelectedRecipe", SelectedRecipe.Id } }; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton)).Returns(Task.Run(() => false)); DatabaseServiceMock.Setup(databaseService => databaseService.SaveRecipeAsync(SelectedRecipe)).Returns(Task.Run(() => true)); NavigationServiceMock.Setup(navigationService => navigationService.NavigateAsync(displayRecipePageName, expectedParameters)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act EditRecipePageViewModel.CreateMode = false; EditRecipePageViewModel.Recipe = SelectedRecipe; await EditRecipePageViewModel.SaveRecipe(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton), Times.Once, "Confirmation alert for editting existing recipe not called exactly once."); DatabaseServiceMock.Verify(databaseService => databaseService.SaveRecipeAsync(SelectedRecipe), Times.Never, "Function IDatabaseService.SaveRecipeAsync called atleast once."); NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync(displayRecipePageName, expectedParameters), Times.Never, "Function to navigate to display recipe page for the created recipe called atleast once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Never, "Function INavigationService.GoBackAsync called atleast once."); }
public void OnNavigatedTo_WithIncorrectId_ShouldReturnToPreviousPage() { // Arrange var alertTitle = "Niet gevonden!"; var alertMessage = "Het recept kan niet geladen worden."; var alertCancelButton = "Ok"; var incorrectId = Guid.NewGuid(); var parameters = new NavigationParameters { { "SelectedRecipe", incorrectId } }; DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipeAsync(SelectedRecipe.Id)).Returns(Task.Run(() => SelectedRecipe)); DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipeAsync(incorrectId)).Returns(() => null); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act DisplayRecipePageViewModel.OnNavigatedTo(parameters); // Assert DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipeAsync(SelectedRecipe.Id), Times.Never, "Function IDatabaseService.GetRecipeAsync for selected recipe called atleast once."); DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipeAsync(incorrectId), Times.Once, "Function IDatabaseService.GetRecipeAsync for non-existant recipe not called exactly once."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Once, "Alert for failed retrieving of recipe not called exactly once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Once, "Function INavigationService.GoBackAsync not called exactly once."); }
protected override void OnInit() { ThreadManager.ImmediateInvokeAsync = true; ThreadManager.ImmediateInvokeOnUiThread = true; ThreadManager.ImmediateInvokeOnUiThreadAsync = true; base.OnInit(); NavigationService = new NavigationServiceMock(); ViewPageMappingProvider = new ViewPageMappingProviderMock(); NavigationProvider = new NavigationProvider(NavigationService, ThreadManager, ViewPageMappingProvider, ViewManager, ViewModelProvider, NavigationDispatcher, new EventAggregator()); }
public void Setup() { CurrentUser = Fixture.Create <GoogleUser>(); // Reset any calls made to the mocks. NavigationServiceMock.Reset(); PageDialogServiceMock.Reset(); AuthServiceMock.Reset(); DatabaseServiceMock.Reset(); }
protected override void OnInit() { ThreadManager.ImmediateInvokeAsync = true; ThreadManager.ImmediateInvokeOnUiThread = true; ThreadManager.ImmediateInvokeOnUiThreadAsync = true; base.OnInit(); NavigationService = new NavigationServiceMock(); ViewPageMappingProvider = new ViewPageMappingProviderMock(); NavigationProvider = new NavigationProvider(NavigationService, ThreadManager, ViewPageMappingProvider, ViewManager, ViewModelProvider, OperationCallbackManager); }
public void OnCancelPressedCommand_ShouldNavigateToPreviousPage() { // Arrange NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act ReportIssueSettingsPageViewModel.OnCancelPressedCommand?.Execute(); // Assert NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Once, "Function INavigationService.OnCancelPressed not called exactly once."); }
public void OnSelectionChanged_WithoutSelectedItem_ShouldDoNothing(string selectedItem) { // Arrange NavigationServiceMock.Setup(navigationService => navigationService.NavigateAsync($"{selectedItem}SettingsPage")).Verifiable(); // Act SettingsPageViewModel.SelectedItem = selectedItem; SettingsPageViewModel.OnSelectionChanged(); // Assert NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync($"{selectedItem}SettingsPage"), Times.Never, $"Method OnSelectionChanged navigated user to {selectedItem}SettingsPage."); }
public void OnSelectionChanged_WithSelectedItem_ShouldNavigateToSelectedPage(string selectedItem, string expectedPageName) { // Arrange NavigationServiceMock.Setup(navigationService => navigationService.NavigateAsync(expectedPageName)).Verifiable(); // Act SettingsPageViewModel.SelectedItem = selectedItem; SettingsPageViewModel.OnSelectionChanged(); // Assert NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync(expectedPageName), Times.Once, $"Method OnSelectionChanged did not navigate user to {selectedItem}SettingsPage."); Assert.IsNull(SettingsPageViewModel.SelectedItem, "Attribute SettingsPageViewModel.SelectedItem was not reset upon navigating."); }
public async Task ValidNavigation_DoesNotUsePageDialogService() { var navService = new NavigationServiceMock(); var dialogService = new PageDialogServiceMock(); var logger = new XunitLogger(TestOutputHelper); var vm = new ReactiveMockViewModel(navService, dialogService, logger); // Assert.True(vm.NavigateCommand.CanExecute("good")); await vm.NavigateCommand.Execute("good"); Assert.Null(dialogService.Title); Assert.Null(dialogService.Message); }
public async Task ValidNavigation_DoesNotUsePageDialogService() { var navService = new NavigationServiceMock(); var dialogService = new PageDialogServiceMock(); var logger = new XunitLogger(TestOutputHelper); var baseServices = new BaseServices(navService, Mock.Of <IDialogService>(), dialogService, logger, Mock.Of <IEventAggregator>(), Mock.Of <IDeviceService>(), new ResxLocalize()); var vm = new ReactiveMockViewModel(baseServices); // Assert.True(vm.NavigateCommand.CanExecute("good")); await vm.NavigateCommand.Execute("good"); Assert.Null(dialogService.Title); Assert.Null(dialogService.Message); }
public void OnRecipeSelectedCommand_WithNullValue_ShouldDisplayAlert() { // Arrange var alertTitle = "Incorrecte recept!"; var alertMessage = "Dit recept bestaat niet."; var alertCancelButton = "Ok"; NavigationServiceMock.Setup(navigationService => navigationService.NavigateAsync(nameof(DisplayRecipePage))); // Act MainPageViewModel.OnRecipeSelectedCommand?.Execute(null); //Assert NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync(nameof(DisplayRecipePage)), Times.Never, "Command OnRecipeSelected navigated user to DisplayRecipePage."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Once, "Incorrect recipe alert not displayed exactly once."); }
public async Task InvalidNavigation_UsesPageDialogService() { var navService = new NavigationServiceMock(); var dialogService = new PageDialogServiceMock(); var logger = new XunitLogger(TestOutputHelper); var vm = new ReactiveMockViewModel(navService, dialogService, logger); // Assert.True(vm.NavigateCommand.CanExecute("bad")); await vm.NavigateCommand.Execute("bad"); Assert.Equal(ToolkitResources.Error, dialogService.Title); var errorMessage = new Exception("bad").ToErrorMessage(); var dialogMessage = string.Format(ToolkitResources.AlertErrorMessageTemplate, errorMessage, vm.CorrelationId); Assert.NotNull(vm.CorrelationId); Assert.Contains(dialogMessage, dialogService.Message); }
public async Task ValidNavigation_DoesNotUsePageDialogService() { var navService = new NavigationServiceMock(); var dialogService = new PageDialogServiceMock(); var logger = new XunitLogger(TestOutputHelper); var vm = new ViewModelMock(navService, dialogService, logger); Assert.True(vm.NavigateCommand.CanExecute("good")); vm.NavigateCommand.Execute("good"); await Task.Run(() => { while (vm.IsBusy) { } }); Assert.Null(dialogService.Title); Assert.Null(dialogService.Message); }
public void OnNavigatedTo_WithoutParametersWhenRecipeIsNull_ShouldReturnToPreviousPage() { // Arrange var alertTitle = "Niet gevonden!"; var alertMessage = "Het recept kan niet geladen worden."; var alertCancelButton = "Ok"; DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipeAsync(SelectedRecipe.Id)).Returns(() => null); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act DisplayRecipePageViewModel.OnNavigatedTo(null); // Assert DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipeAsync(SelectedRecipe.Id), Times.Never, "Function IDatabaseService.GetRecipeAsync for selected recipe called atleast once."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Once, "Alert for failed retrieving of recipe not called exactly once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Once, "Function INavigationService.GoBackAsync not called exactly once."); }
public async Task DeleteRecipeAsync_WhenCanceled_ShouldNotDeleteRecipe() { // Arrange var alertTitle = "Waarschuwing!"; var alertMessage = "U staat op het punt dit recept te verwijderen. Dit kan niet terug gedraaid worden."; var alertAcceptButton = "Verwijder"; var alertCancelButton = "Annuleer"; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton)).Returns(Task.Run(() => false)); DatabaseServiceMock.Setup(databaseService => databaseService.DeleteRecipeAsync(SelectedRecipe.Id)).Returns(Task.Run(() => false)); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act DisplayRecipePageViewModel.Recipe = SelectedRecipe; await DisplayRecipePageViewModel.DeleteRecipeAsync(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton), Times.Once, "Alert for deleting a recipe from Firebase not called exactly once."); DatabaseServiceMock.Verify(databaseService => databaseService.DeleteRecipeAsync(SelectedRecipe.Id), Times.Never, "Function IDatabaseService.DeleteRecipeAsync for the selected recipe called atleast once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Never, "Function INavigationService.GoBackAsync called atleast once."); }
public void OnEditRecipeCommand_WithRecipe_ShouldNavigateToPageWithParameters() { // Arrange var alertTitle = "Waarschuwing!"; var alertMessage = "Niet mogelijk om dit recept aan te passen."; var alertCancelButton = "Ok"; var expectedPageName = nameof(EditRecipePage); var expectedParameters = new NavigationParameters { { "SelectedRecipe", SelectedRecipe.Id } }; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.NavigateAsync(expectedPageName, expectedParameters)).Verifiable(); // Act DisplayRecipePageViewModel.Recipe = SelectedRecipe; DisplayRecipePageViewModel.OnEditRecipeCommand?.Execute(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Alert for failed navigation called atleast once."); NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync(expectedPageName, expectedParameters), Times.Once, $"Function INavigationService.NavigateAsync to {expectedPageName} with correct parameters not called exactly once."); }
public void OnRecipeSelectedCommand_WithValidRecipe_ShouldNavigateToDisplayRecipePage() { // Arange var alertTitle = "Incorrecte recept!"; var alertMessage = "Dit recept bestaat niet."; var alertCancelButton = "Ok"; var selectedRecipe = new Recipe { Id = Guid.NewGuid() }; var expectedNavigationParams = new NavigationParameters { { "SelectedRecipe", selectedRecipe.Id } }; NavigationServiceMock.Setup(navigationService => navigationService.NavigateAsync(nameof(DisplayRecipePage))).Verifiable(); // Act MainPageViewModel.OnRecipeSelectedCommand?.Execute(selectedRecipe); // Assert NavigationServiceMock.Verify(navigationService => navigationService.NavigateAsync(nameof(DisplayRecipePage), expectedNavigationParams), Times.Once, "Command OnRecipeSelected did not navigate user to DisplayRecipePage with correct parameters."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Incorrect recipe alert displayed atleast once."); }
public async Task ReportIssue_WhenIssueIsInvalid_ShouldDisplayAlert(string user, string description, bool issueIsNull = false) { // Arrange Issue issue = null; if (!issueIsNull) { issue = new Issue { User = user, Description = description }; } var alertErrorTitle = "Let op!"; var alertErrorMessage = "Het emailadres of de beschrijving is niet ingevuld!"; var alertErrorCancelButton = "Ok"; var alertConfirmationTitle = "Bedankt!"; var alertConfirmationMessage = "Bedankt voor het melden van het probleem!"; var alertConfirmationCancelButton = "Geen probleem"; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertErrorTitle, alertErrorMessage, alertErrorCancelButton)).Verifiable(); ReportingServiceMock.Setup(reportingService => reportingService.ReportIssue(issue)).Returns(Task.Run(() => false)); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertConfirmationTitle, alertConfirmationMessage, alertConfirmationCancelButton)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act ReportIssueSettingsPageViewModel.Issue = null; await ReportIssueSettingsPageViewModel.ReportIssue(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertErrorTitle, alertErrorMessage, alertErrorCancelButton), Times.Once, "Alert for invalid issue not called exactly once."); ReportingServiceMock.Verify(reportingService => reportingService.ReportIssue(issue), Times.Never, "Function ReportingService.ReportIssue called atleast once."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertConfirmationTitle, alertConfirmationMessage, alertConfirmationCancelButton), Times.Never, "Alert for succesfully reporting an issue called atleast once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Never, "Function INavigationService.OnCancelPressed called atleast once."); }
public void OnNavigatedTo_WithCorrectParameters_ShouldSetSelectedRecipe() { // Arrange var alertTitle = "Niet gevonden!"; var alertMessage = "Het recept kan niet geladen worden."; var alertCancelButton = "Ok"; var parameters = new NavigationParameters { { "SelectedRecipe", SelectedRecipe.Id } }; DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipeAsync(SelectedRecipe.Id)).Returns(Task.Run(() => SelectedRecipe)); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton)).Verifiable(); NavigationServiceMock.Setup(navigationService => navigationService.GoBackAsync()).Verifiable(); // Act DisplayRecipePageViewModel.OnNavigatedTo(parameters); // Assert DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipeAsync(SelectedRecipe.Id), Times.Once, "Function IDatabaseService.GetRecipeAsync for selected recipe not called exactly once."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Alert for failed retrieving of recipe called atleast once."); NavigationServiceMock.Verify(navigationService => navigationService.GoBackAsync(), Times.Never, "Function INavigationService.GoBackAsync called atleast once."); Assert.AreEqual(SelectedRecipe, DisplayRecipePageViewModel.Recipe, "Attribute DisplayRecipePageViewModel.Recipe is not the expected value."); }