示例#1
0
        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.");
        }
示例#2
0
        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.");
        }
示例#3
0
        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 DisplayActionSheetNoButtons_ShouldThrowException()
        {
            var service           = new PageDialogServiceMock("cancel");
            var argumentException = await Assert.ThrowsAsync <ArgumentException>(() => service.DisplayActionSheet(null, null));

            Assert.Equal(typeof(ArgumentException), argumentException.GetType());
        }
示例#5
0
        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.");
        }
示例#6
0
        public TestSearchMoviesPageViewModel()
        {
            Xamarin.Forms.Mocks.MockForms.Init();
            app = new PrismApplicationMock();
            var pageDialogService = new PageDialogServiceMock();

            viewModel = new SearchMoviesPageViewModel(app.NavigationService, pageDialogService);
        }
        public void Setup()
        {
            CurrentUser = Fixture.Create <GoogleUser>();

            // Reset any calls made to the mocks.
            NavigationServiceMock.Reset();
            PageDialogServiceMock.Reset();
            AuthServiceMock.Reset();
            DatabaseServiceMock.Reset();
        }
        public async Task DisplayActionSheet_NullButtonAndOtherButtonPressed()
        {
            var service       = new PageDialogServiceMock("other");
            var buttonPressed = false;
            var command       = new DelegateCommand(() => buttonPressed = true);
            var button        = ActionSheetButton.CreateButton("other", command);
            await service.DisplayActionSheet(null, button, null);

            Assert.True(buttonPressed);
        }
        public async Task DisplayActionSheet_CancelButtonPressed()
        {
            var service             = new PageDialogServiceMock("cancel");
            var cancelButtonPressed = false;
            var cancelCommand       = new DelegateCommand(() => cancelButtonPressed = true);
            var button = ActionSheetButton.CreateCancelButton("cancel", cancelCommand);
            await service.DisplayActionSheet(null, button);

            Assert.True(cancelButtonPressed);
        }
        public async Task DisplayActionSheet_OtherButtonPressed_UsingCommand()
        {
            var service       = new PageDialogServiceMock("other", _applicationProvider);
            var buttonPressed = false;
            var command       = new DelegateCommand(() => buttonPressed = true);
            var button        = ActionSheetButton.CreateButton("other", command);
            await service.DisplayActionSheetAsync(null, button);

            Assert.True(buttonPressed);
        }
        public async Task DisplayActionSheet_NoButtonPressed()
        {
            var service        = new PageDialogServiceMock(null);
            var buttonPressed  = false;
            var cancelCommand  = new DelegateCommand(() => buttonPressed = true);
            var button         = ActionSheetButton.CreateCancelButton("cancel", cancelCommand);
            var destroyCommand = new DelegateCommand(() => buttonPressed = true);
            var destroyButton  = ActionSheetButton.CreateDestroyButton("destroy", destroyCommand);
            await service.DisplayActionSheet(null, button, destroyButton);

            Assert.False(buttonPressed);
        }
        public async Task DisplayActionSheet_DestroyButtonPressed_UsingCommand()
        {
            var service = new PageDialogServiceMock("destroy", _applicationProvider);
            var destroyButtonPressed = false;
            var cancelCommand        = new DelegateCommand(() => destroyButtonPressed = false);
            var button         = ActionSheetButton.CreateCancelButton("cancel", cancelCommand);
            var destroyCommand = new DelegateCommand(() => destroyButtonPressed = true);
            var destroyButton  = ActionSheetButton.CreateDestroyButton("destroy", destroyCommand);
            await service.DisplayActionSheetAsync(null, button, destroyButton);

            Assert.True(destroyButtonPressed);
        }
        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);
        }
示例#15
0
        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.");
        }
示例#16
0
        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.");
        }
示例#17
0
        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 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);
        }
示例#19
0
        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 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);
        }
示例#21
0
        public async Task ToggleLogin_WhenRefusingLogin_ShouldNotDisplayAlert()
        {
            // Arrange
            var alertTitle        = "Uitgelogd!";
            var alertMessage      = "U bent succesvol uitgelogd.";
            var alertCancelButton = "Ok";

            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(CurrentUser);
            AuthServiceMock.Setup(authService => authService.LogoutAsync()).Returns(Task.Run(() => false));

            // Act
            await MainPageViewModel.ToggleLogin();

            // Assert
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.AtLeastOnce, "Function IAuthenticationService.GetUser not called atleast once.");
            AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Never, "Function IAuthenticationService.LoginAsync called atleast once.");
            AuthServiceMock.Verify(authService => authService.LogoutAsync(), Times.Once, "Function IAuthenticationService.Logout not not called exactly once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipesAsync(), Times.Never, "Function IDatabaseService.GetRecipesAsync called atleast once.");
            PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Logout alert displayed atleast 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.");
        }
        private async Task DisplayActionSheet_PressButton_UsingGenericAction(string text)
        {
            var service            = new PageDialogServiceMock(text, _applicationProvider);
            var cancelButtonModel  = new ButtonModel();
            var destroyButtonModel = new ButtonModel();
            var otherButtonModel   = new ButtonModel();
            var btns = new IActionSheetButton[]
            {
                ActionSheetButton.CreateButton("other", OnButtonPressed, otherButtonModel),
                ActionSheetButton.CreateCancelButton("cancel", OnButtonPressed, cancelButtonModel),
                ActionSheetButton.CreateDestroyButton("destroy", OnButtonPressed, destroyButtonModel)
            };
            await service.DisplayActionSheetAsync(null, btns);

            switch (text)
            {
            case "other":
                Assert.True(otherButtonModel.ButtonPressed);
                Assert.False(cancelButtonModel.ButtonPressed);
                Assert.False(destroyButtonModel.ButtonPressed);
                break;

            case "cancel":
                Assert.False(otherButtonModel.ButtonPressed);
                Assert.True(cancelButtonModel.ButtonPressed);
                Assert.False(destroyButtonModel.ButtonPressed);
                break;

            case "destroy":
                Assert.False(otherButtonModel.ButtonPressed);
                Assert.False(cancelButtonModel.ButtonPressed);
                Assert.True(destroyButtonModel.ButtonPressed);
                break;

            default:
                Assert.False(otherButtonModel.ButtonPressed);
                Assert.False(cancelButtonModel.ButtonPressed);
                Assert.False(destroyButtonModel.ButtonPressed);
                break;
            }
        }
#pragma warning restore CS0618 // Type or member is obsolete

        #endregion Obsolete ActionSheetButton using Commands

        private async Task DisplayActionSheet_PressButton_UsingAction(string text)
        {
            var  service              = new PageDialogServiceMock(text, _applicationProvider);
            bool cancelButtonPressed  = false;
            bool destroyButtonPressed = false;
            bool otherButtonPressed   = false;
            var  btns = new IActionSheetButton[]
            {
                ActionSheetButton.CreateButton("other", () => otherButtonPressed            = true),
                ActionSheetButton.CreateCancelButton("cancel", () => cancelButtonPressed    = true),
                ActionSheetButton.CreateDestroyButton("destroy", () => destroyButtonPressed = true)
            };
            await service.DisplayActionSheetAsync(null, btns);

            switch (text)
            {
            case "other":
                Assert.True(otherButtonPressed);
                Assert.False(cancelButtonPressed);
                Assert.False(destroyButtonPressed);
                break;

            case "cancel":
                Assert.False(otherButtonPressed);
                Assert.True(cancelButtonPressed);
                Assert.False(destroyButtonPressed);
                break;

            case "destroy":
                Assert.False(otherButtonPressed);
                Assert.False(cancelButtonPressed);
                Assert.True(destroyButtonPressed);
                break;

            default:
                Assert.False(otherButtonPressed);
                Assert.False(cancelButtonPressed);
                Assert.False(destroyButtonPressed);
                break;
            }
        }
示例#25
0
        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.");
        }
示例#26
0
        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.");
        }
示例#27
0
        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.");
        }
示例#28
0
        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.");
        }
示例#29
0
        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.");
        }
示例#30
0
        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.");
        }