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 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."); }
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 async Task AddProperty_WithInvalidProperty_ShouldNotAddToShowPropertiesList(string propertyName = null) { // Arrange var actionSheetTitle = "Voeg nieuw veld toe"; var actionSheetCancelButton = "Annuleer"; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayActionSheetAsync(actionSheetTitle, actionSheetCancelButton, null, HiddenPropertiesNl)).Returns(Task.Run(() => propertyName)); // Act EditRecipePageViewModel.Recipe = SelectedRecipe; await EditRecipePageViewModel.AddProperty(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayActionSheetAsync(actionSheetTitle, actionSheetCancelButton, null, HiddenPropertiesNl), Times.Once, "Action Sheet to select which property to add was not called."); Assert.IsEmpty(EditRecipePageViewModel.ShowProperties, "A property was added to attribute EditRecipePageViewModel.ShowProperties."); }
public async Task AddProperty_WhenPropertySelected_ShouldAddToShowPropertiesList(string propertyName) { // Arrange var actionSheetTitle = "Voeg nieuw veld toe"; var actionSheetCancelButton = "Annuleer"; var propertyNl = SelectedRecipe.EnToNlTranslation(propertyName); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayActionSheetAsync(actionSheetTitle, actionSheetCancelButton, null, HiddenPropertiesNl)).Returns(Task.Run(() => propertyNl)); // Act EditRecipePageViewModel.Recipe = SelectedRecipe; await EditRecipePageViewModel.AddProperty(); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayActionSheetAsync(actionSheetTitle, actionSheetCancelButton, null, HiddenPropertiesNl), Times.Once, "Action Sheet to select which property to add was not called."); Assert.Contains(propertyName, EditRecipePageViewModel.ShowProperties, $"Property {propertyName} not added to attribute EditRecipePageViewModel.ShowProperties."); }
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 LoginUserAsync_WhenRefusingLoginWithInternetConnection_ShouldDoNothing() { // Arrange var alertTitle = "Geen internet connectie"; var alertMessage = "Het is niet mogelijk om in te loggen. Controleer uw internet connectie en probeer opnieuw."; var alertCancelButton = "Ok"; AuthServiceMock.Setup(authService => authService.LoginAsync()).Returns(Task.Run(() => GoogleActionStatus.Canceled)); AuthServiceMock.Setup(authService => authService.GetUser()).Returns(() => null); PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton)).Verifiable(); // Act await AccountSettingsPageViewModel.LoginUserAsync(); // Assert AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Once, "Function AuthenticationService.LoginAsync not called exactly once."); AuthServiceMock.Verify(authService => authService.GetUser(), Times.Never, "Function AuthenticationService.GetUser called atleast once."); PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Alert for no internet connection called atleast once."); Assert.IsNull(AccountSettingsPageViewModel.User, "Attribute AccountSettingsPageViewModel.User is not null."); }
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 async Task OnRemovePropertyCommand_WhenConfirmed_ShouldRemoveProperty(string propertyName) { // Arrange var propertyNl = SelectedRecipe.EnToNlTranslation(propertyName); var alertTitle = "Pas op!"; var alertMessage = $"Weet u zeker dat u het veld {propertyNl} wilt verwijderen?"; var alertAcceptButton = "Ja"; var alertCancelButton = "Nee"; PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton)).Returns(Task.Run(() => true)); // Act EditRecipePageViewModel.Recipe = SelectedRecipe; EditRecipePageViewModel.ShowProperties.Add(propertyName); Assert.Contains(propertyName, EditRecipePageViewModel.ShowProperties, $"Property {propertyName} not added to attribute EditRecipePageViewModel.ShowProperties prior to the test"); await EditRecipePageViewModel.RemoveProperty(propertyName); // Assert PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertAcceptButton, alertCancelButton), Times.Once, "Alert for confirmation of removing property not called exactly once."); Assert.That(!EditRecipePageViewModel.ShowProperties.Contains(propertyName), $"Property {propertyName} not removed from attribute EditRecipePageViewModel.ShowProperties."); }
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 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."); }