public void TestSubmitCommand() { var voteToSubmit = new Vote { Questionnaire = new Questionnaire { Deadline = DateTime.MaxValue }, AnswerCollection = new List <QuestionnaireOption> { new QuestionnaireOption() } }; var dialogShown = false; var messageShown = ""; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => { dialogShown = true; messageShown = message; }); Vote voteSubmitted = null; var submitRequested = false; var stubIVoteService = new StubIVoteService(); stubIVoteService.SubmitAsync(async vote => { submitRequested = true; voteSubmitted = vote; return(new ServiceResult { Status = ServiceResultStatus.NoContent }); }); var stubIRootNavigationService = new StubIRootNavigationService(); var backNavigated = false; stubIRootNavigationService.GoBack(() => backNavigated = true); var stubITileService = new StubITileService(); var updateRequested = false; stubITileService.ForceUpdate(() => updateRequested = true); var voteViewModel = new VoteViewModel(stubIDialogService, stubIVoteService, stubIRootNavigationService, stubITileService); voteViewModel.Vote = voteToSubmit; voteViewModel.SubmitCommand.Execute(null); Assert.IsTrue(dialogShown); Assert.AreSame(VoteViewModel.AnswerSubmittedMessage, messageShown); Assert.IsTrue(submitRequested); Assert.AreSame(voteToSubmit, voteSubmitted); Assert.IsTrue(backNavigated); Assert.IsTrue(updateRequested); }
public void TestSubmitCommandOther() { var voteToSubmit = new Vote { Questionnaire = new Questionnaire { Deadline = DateTime.MaxValue }, AnswerCollection = new List <QuestionnaireOption> { new QuestionnaireOption() } }; var messageToShow = "Error Message"; var dialogShown = false; var messageShown = ""; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => { dialogShown = true; messageShown = message; }); Vote voteSubmitted = null; var submitRequested = false; var stubIVoteService = new StubIVoteService(); stubIVoteService.SubmitAsync(async vote => { submitRequested = true; return(new ServiceResult { Status = ServiceResultStatus.NotFound, Message = messageToShow }); }); var voteViewModel = new VoteViewModel(stubIDialogService, stubIVoteService, null, null); voteViewModel.Vote = voteToSubmit; voteViewModel.SubmitCommand.Execute(null); Assert.IsTrue(dialogShown); Assert.AreEqual( UvpClient.App.HttpClientErrorMessage + messageToShow, messageShown); Assert.IsTrue(submitRequested); }
public void TestSubmitCommandUnauthorized() { var voteToSubmit = new Vote { Questionnaire = new Questionnaire { Deadline = DateTime.MaxValue }, AnswerCollection = new List <QuestionnaireOption> { new QuestionnaireOption() } }; var dialogShown = false; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => dialogShown = true); var submitRequested = false; var stubIVoteService = new StubIVoteService(); stubIVoteService.SubmitAsync(async groupAssignment => { submitRequested = true; return(new ServiceResult { Status = ServiceResultStatus.Unauthorized }); }); var voteViewModel = new VoteViewModel(stubIDialogService, stubIVoteService, null, null); voteViewModel.Vote = voteToSubmit; voteViewModel.SubmitCommand.Execute(null); Assert.IsFalse(dialogShown); Assert.IsTrue(submitRequested); }