public void TestCheckCommandUnauthorized() { var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => dialogShown = true); var getRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.GetStudentByStudentIdAsync(async studentId => { getRequested = true; return(new ServiceResult <Student> { Status = ServiceResultStatus.Unauthorized }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.CheckCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsFalse(dialogShown); Assert.IsTrue(getRequested); }
public void TestCheckCommandSucceeded() { var studentIdToRequest = "Student ID"; var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => dialogShown = true); var studentIdRequested = ""; var checkRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.GetStudentByStudentIdAsync(async studentId => { checkRequested = true; studentIdRequested = studentId; return(new ServiceResult <Student> { Status = ServiceResultStatus.OK, Result = new Student { StudentId = studentIdToRequest } }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.StudentId = studentIdToRequest; bindingViewModel.CheckCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsFalse(dialogShown); Assert.IsTrue(checkRequested); Assert.AreEqual(studentIdToRequest, studentIdRequested); Assert.AreEqual(studentIdToRequest, bindingViewModel.Student.StudentId); }
public void TestCheckCommandOther() { var messageToShow = "Error Message"; var rootFrameNavigated = false; var stubIRootNavigationService = new StubIRootNavigationService(); stubIRootNavigationService.Navigate( (sourcePageType, parameter, navigationTransition) => rootFrameNavigated = true); var messageShown = ""; var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => { dialogShown = true; messageShown = message; }); var bindRequested = false; var stubIStudentService = new StubIStudentService(); stubIStudentService.GetStudentByStudentIdAsync(async studentId => { bindRequested = true; return(new ServiceResult <Student> { Status = ServiceResultStatus.Exception, Message = messageToShow }); }); var bindingViewModel = new BindingViewModel( stubIRootNavigationService, stubIDialogService, stubIStudentService); bindingViewModel.CheckCommand.Execute(null); Assert.IsFalse(rootFrameNavigated); Assert.IsTrue(dialogShown); Assert.AreEqual( UvpClient.App.HttpClientErrorMessage + messageToShow, messageShown); Assert.IsTrue(bindRequested); }