public async Task ValidateAssignmentAsync_ChangedExistingQuestionId_ReturnsFalseWithCorrectError() { var database = GetDatabase().Build(); var modelErrors = new MockErrorCollection(); var assignment = database.Context .Assignments .Include(a => a.DueDates) .Include(a => a.Questions) .First(); int newQuestionId = database.Context .Questions .First(q => q.Id != assignment.Questions[0].QuestionId) .Id; assignment.Questions[0].QuestionId = newQuestionId; database.Reload(); var assignmentValidator = new AssignmentValidator(database.Context); var result = await assignmentValidator.ValidateAssignmentAsync ( assignment, modelErrors ); Assert.False(result); Assert.True(modelErrors.VerifyErrors("Questions")); }
public async Task ValidateAssignmentAsync_DuplicateDueDates_ReturnsFalseWithCorrectError() { var database = GetDatabase().Build(); var modelErrors = new MockErrorCollection(); var sectionId = database.Context.Sections.First().Id; var assignment = database.Context .Assignments .Include(a => a.DueDates) .Include(a => a.Questions) .First(); assignment.DueDates.Add ( new AssignmentDueDate() { SectionId = sectionId, DueDate = DateTime.MaxValue } ); database.Reload(); var assignmentValidator = new AssignmentValidator(database.Context); var result = await assignmentValidator.ValidateAssignmentAsync ( assignment, modelErrors ); Assert.False(result); Assert.True(modelErrors.VerifyErrors("DueDates")); }
public async Task ValidateAssignmentAsync_OnlyShowCombinedScore_ReturnsFalseIfSeparateSubmissions( bool combinedSubmissions) { var database = GetDatabase().Build(); var modelErrors = new MockErrorCollection(); var assignment = database.Context .Assignments .Include(a => a.DueDates) .Include(a => a.Questions) .First(); assignment.OnlyShowCombinedScore = true; assignment.CombinedSubmissions = combinedSubmissions; database.Reload(); var assignmentValidator = new AssignmentValidator(database.Context); var result = await assignmentValidator.ValidateAssignmentAsync ( assignment, modelErrors ); Assert.Equal(combinedSubmissions, result); if (!combinedSubmissions) { Assert.True(modelErrors.VerifyErrors("OnlyShowCombinedScore")); } }
public async Task ValidateAssignmentAsync_ValidAssignment_ReturnsTrueWithNoErrors() { var database = GetDatabase().Build(); var modelErrors = new MockErrorCollection(); var assignment = database.Context.Assignments.First(); var assignmentValidator = new AssignmentValidator(database.Context); var result = await assignmentValidator.ValidateAssignmentAsync ( assignment, modelErrors ); Assert.True(result); Assert.False(modelErrors.HasErrors); }
public async Task ValidateAssignmentAsync_ContainsInteractiveOnlyQuestion_ReturnsFalseIfCombinedSubmissions( bool combinedSubmissions) { var database = GetDatabase().Build(); var modelErrors = new MockErrorCollection(); var assignment = database.Context .Assignments .Include(a => a.DueDates) .Include(a => a.Questions) .First(); var codeQuestionId = database.Context .Questions .First(q => q is CodeQuestion) .Id; assignment.CombinedSubmissions = combinedSubmissions; assignment.Questions.Add ( new AssignmentQuestion() { QuestionId = codeQuestionId, Name = "Code Question 1" } ); database.Reload(); var assignmentValidator = new AssignmentValidator(database.Context); var result = await assignmentValidator.ValidateAssignmentAsync ( assignment, modelErrors ); Assert.Equal(!combinedSubmissions, result); if (combinedSubmissions) { Assert.True(modelErrors.VerifyErrors("Questions")); } }