/// <summary> /// Get how much time is left of an assignment in terms of days, hours, minutes or second, /// depending on how much time is left /// </summary> public string GetAssignmentTimeRemaining(StudentAssignmentViewModel assignment) { var timeRemaining = String.Empty; if (assignment.StartTime.HasValue && assignment.EndTime.HasValue) { if (0 < assignment.EndTime.Value.CompareTo(DateTime.Now)) { var remainingTimeSpan = new TimeSpan(assignment.EndTime.Value.Ticks - DateTime.Now.Ticks); if (0 < remainingTimeSpan.Days) { timeRemaining = remainingTimeSpan.Days.ToString(); timeRemaining += (remainingTimeSpan.Days == 1 ? " day left" : " days left"); } else if (0 < remainingTimeSpan.Hours) { timeRemaining = remainingTimeSpan.Hours.ToString(); timeRemaining += (remainingTimeSpan.Hours == 1 ? " hour left" : " hours left"); } else if (0 < remainingTimeSpan.Minutes) { timeRemaining = remainingTimeSpan.Minutes.ToString(); timeRemaining += (remainingTimeSpan.Minutes == 1 ? " minute left" : " minutes left"); } else if (0 < remainingTimeSpan.Seconds) { timeRemaining = remainingTimeSpan.Seconds.ToString(); timeRemaining += (remainingTimeSpan.Seconds == 1 ? " second left" : " seconds left"); } } } return(timeRemaining); }
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 TestSubmitCommandInvalidUrl() { var dialogShown = false; var messageShown = ""; var stubIDialogService = new StubIDialogService(); stubIDialogService.ShowAsync(async message => { dialogShown = true; messageShown = message; }); var studentAssignmentViewModel = new StudentAssignmentViewModel(stubIDialogService, null, null, null); studentAssignmentViewModel.StudentAssignment = new StudentAssignment { Solution = "not a url", Homework = new Homework { Deadline = DateTime.MaxValue } }; studentAssignmentViewModel.SubmitCommand.Execute(null); Assert.IsTrue(dialogShown); Assert.AreEqual(UvpClient.App.SolutionUrlErrorMessage, messageShown); }
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 ICollection <StudentAssignmentViewModel> GetStudentResults(string studentId) { var assignmentIds = this.context.AssignmentResults .Where(x => x.StudentId == studentId && x.Stage != 1) .Select(x => new StudentAssignmentViewModel() { Id = x.AssignmentId, Stage = x.Stage, Points = x.Points, MaxPoints = this.context.Assignments .Where(a => a.Id == x.AssignmentId) .Select(a => a.Points) .FirstOrDefault() }) .ToList(); var assignments = new List <StudentAssignmentViewModel>(); foreach (var assignmentId in assignmentIds) { var assignment = this.context.Assignments .FirstOrDefault(x => x.Id == assignmentId.Id); if (assignment == null) { continue; } var assignmentModel = new StudentAssignmentViewModel() { AssignmentName = assignment.AssignmentTitle, DueDate = assignment.DueDate, Id = assignment.Id, Signature = assignment.Signature, Stage = assignmentId.Stage, Points = assignmentId.Points, MaxPoints = assignment.Points }; assignments.Add(assignmentModel); } return(assignments); }
/// <summary> /// Get an assignment by it's id /// </summary> public StudentAssignmentViewModel GetStudentAssignmentById(int assignmentid, string studentid) { var group = _db.AssignmentGroups.Where(x => x.UserId == studentid && x.AssignmentId == assignmentid).SingleOrDefault(); var assignment = new StudentAssignmentViewModel(); if (group != null) { assignment = new StudentAssignmentViewModel { Id = group.Assignment.Id, Course = group.Assignment.CourseInstance.Course.Name, Name = group.Assignment.Name, Description = group.Assignment.Description, StartTime = group.Assignment.StartTime, EndTime = group.Assignment.EndTime, MaxCollaborators = group.Assignment.MaxCollaborators, AssignmentGrade = group.AssignmentGrade, Collaborators = GetCollaborators(assignmentid, studentid) }; } return(assignment); }
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); }
/// <summary> /// Check if an assignment's problems are accepted /// </summary> public bool IsAssignmentDone(StudentAssignmentViewModel assignment) { return(assignment.Problems.All(x => x.IsAccepted)); }
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); }