public void TestRefreshCommandSucceeded()
        {
            var studentAssignmentToReturn = new StudentAssignment();

            var dialogShown        = false;
            var stubIDialogService = new StubIDialogService();

            stubIDialogService.ShowAsync(async message => dialogShown = true);

            var refreshRequested    = false;
            var stubIStudentService = new StubIStudentAssignmentService();

            stubIStudentService.GetAsync(async id => {
                refreshRequested = true;
                return(new ServiceResult <StudentAssignment> {
                    Status = ServiceResultStatus.OK,
                    Result = studentAssignmentToReturn
                });
            });

            var studentAssignmentViewModel =
                new StudentAssignmentViewModel(stubIDialogService,
                                               stubIStudentService, null, null);

            studentAssignmentViewModel.RefreshCommand.Execute(null);

            Assert.IsFalse(dialogShown);
            Assert.IsTrue(refreshRequested);
            Assert.AreSame(studentAssignmentToReturn,
                           studentAssignmentViewModel.StudentAssignment);
        }
        public void TestSubmitCommandOther()
        {
            var studentAssignmentToSubmit = new StudentAssignment {
                HomeworkID = -1, Solution = "http://www.bing.com/",
                Homework   = new Homework {
                    Deadline = DateTime.MaxValue
                }
            };
            var messageToShow = "Error Message";

            var dialogShown        = false;
            var messageShown       = "";
            var stubIDialogService = new StubIDialogService();

            stubIDialogService.ShowAsync(async message => {
                dialogShown  = true;
                messageShown = message;
            });

            StudentAssignment studentAssignmentSubmitted = null;
            var submitRequested = false;
            var stubIStudentAssignmentService =
                new StubIStudentAssignmentService();

            stubIStudentAssignmentService.SubmitAsync(async groupAssignment => {
                submitRequested = true;
                return(new ServiceResult {
                    Status = ServiceResultStatus.NotFound,
                    Message = messageToShow
                });
            });

            var studentAssignmentViewModel =
                new StudentAssignmentViewModel(stubIDialogService,
                                               stubIStudentAssignmentService, null, null);

            studentAssignmentViewModel.StudentAssignment =
                studentAssignmentToSubmit;
            studentAssignmentViewModel.StudentAssignmentId =
                studentAssignmentToSubmit.HomeworkID;
            studentAssignmentViewModel.SubmitCommand.Execute(null);

            Assert.IsTrue(dialogShown);
            Assert.AreEqual(
                UvpClient.App.HttpClientErrorMessage + messageToShow,
                messageShown);
            Assert.IsTrue(submitRequested);
        }
        public void TestSubmitCommandUnauthorized()
        {
            var studentAssignmentToSubmit = new StudentAssignment {
                HomeworkID = -1, Solution = "http://www.bing.com/",
                Homework   = new Homework {
                    Deadline = DateTime.MaxValue
                }
            };

            var dialogShown        = false;
            var stubIDialogService = new StubIDialogService();

            stubIDialogService.ShowAsync(async message => dialogShown = true);

            var submitRequested = false;
            var stubIStudentAssignmentService =
                new StubIStudentAssignmentService();

            stubIStudentAssignmentService.SubmitAsync(async groupAssignment => {
                submitRequested = true;
                return(new ServiceResult
                {
                    Status = ServiceResultStatus.Unauthorized
                });
            });

            var studentAssignmentViewModel =
                new StudentAssignmentViewModel(stubIDialogService,
                                               stubIStudentAssignmentService, null, null);

            studentAssignmentViewModel.StudentAssignment =
                studentAssignmentToSubmit;
            studentAssignmentViewModel.StudentAssignmentId =
                studentAssignmentToSubmit.HomeworkID;
            studentAssignmentViewModel.SubmitCommand.Execute(null);

            Assert.IsFalse(dialogShown);
            Assert.IsTrue(submitRequested);
        }
        public void TestRefreshCommandOther()
        {
            var messageToShow = "Error Message";

            var messageShown       = "";
            var dialogShown        = false;
            var stubIDialogService = new StubIDialogService();

            stubIDialogService.ShowAsync(async message => {
                dialogShown  = true;
                messageShown = message;
            });

            var refreshRequested = false;
            var stubIStudentAssignmentService =
                new StubIStudentAssignmentService();

            stubIStudentAssignmentService.GetAsync(async id => {
                refreshRequested = true;
                return(new ServiceResult <StudentAssignment> {
                    Status = ServiceResultStatus.Exception,
                    Message = messageToShow
                });
            });

            var studentAssignmentViewModel =
                new StudentAssignmentViewModel(stubIDialogService,
                                               stubIStudentAssignmentService, null, null);

            studentAssignmentViewModel.RefreshCommand.Execute(null);

            Assert.IsTrue(dialogShown);
            Assert.AreEqual(
                UvpClient.App.HttpClientErrorMessage + messageToShow,
                messageShown);
            Assert.IsTrue(refreshRequested);
        }
        public void TestSubmitCommand()
        {
            var studentAssignmentToSubmit = new StudentAssignment {
                HomeworkID = -1, Solution = "http://www.bing.com/",
                Homework   = new Homework {
                    Deadline = DateTime.MaxValue
                }
            };

            var dialogShown        = false;
            var messageShown       = "";
            var stubIDialogService = new StubIDialogService();

            stubIDialogService.ShowAsync(async message => {
                dialogShown  = true;
                messageShown = message;
            });

            StudentAssignment studentAssignmentSubmitted = null;
            var submitRequested = false;
            var stubIStudentAssignmentService =
                new StubIStudentAssignmentService();

            stubIStudentAssignmentService.SubmitAsync(async groupAssignment => {
                submitRequested            = true;
                studentAssignmentSubmitted = groupAssignment;
                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 studentAssignmentViewModel = new StudentAssignmentViewModel(
                stubIDialogService, stubIStudentAssignmentService,
                stubIRootNavigationService, stubITileService);

            studentAssignmentViewModel.StudentAssignment =
                studentAssignmentToSubmit;
            studentAssignmentViewModel.StudentAssignmentId =
                studentAssignmentToSubmit.HomeworkID;
            studentAssignmentViewModel.SubmitCommand.Execute(null);

            Assert.IsTrue(dialogShown);
            Assert.AreSame(UvpClient.App.SolutionSubmittedMessage,
                           messageShown);
            Assert.IsTrue(submitRequested);
            Assert.AreSame(studentAssignmentToSubmit,
                           studentAssignmentSubmitted);
            Assert.IsTrue(backNavigated);
            Assert.IsTrue(updateRequested);
        }