Esempio n. 1
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.");
        }
Esempio n. 2
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.");
        }
Esempio n. 3
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.");
        }