public async Task UpdateQuestionAsync_NewQuestion_CreatesChoicesCategory() { var database = GetDatabase().Build(); var classroom = database.Context.Classrooms.First(); var questionCategoryId = database.Context .QuestionCategories .First() .Id; var errors = new MockErrorCollection(); var newQuestion = new RandomlySelectedQuestion() { Name = "Random Question", QuestionCategoryId = questionCategoryId }; var updater = new RandomlySelectedQuestionUpdater ( database.Context, newQuestion, errors ); await updater.UpdateQuestionAsync(); Assert.False(errors.HasErrors); Assert.NotNull(newQuestion.ChoicesCategory); Assert.Equal(classroom.Id, newQuestion.ChoicesCategory.ClassroomId); Assert.Equal("Category1: Random Question", newQuestion.ChoicesCategory.Name); }
/// <summary> /// Creates a question loader for a randomly selected question. /// </summary> IQuestionResolver IQuestionResultVisitor <IQuestionResolver, UserQuestionData> .Visit( RandomlySelectedQuestion question, UserQuestionData userQuestionData) { return(new RandomlySelectedQuestionResolver ( userQuestionData, _dbContext, _questionLoaderFactory )); }
/// <summary> /// Creates a new UserQuestionData object. /// </summary> private UserQuestionData CreateUserQuestionData( RandomlySelectedQuestion randomlySelectedQuestion, int?previousQuestionId = null) { return(new UserQuestionData() { NumAttempts = 1, LastQuestionSubmission = "LastQuestionSubmission", Seed = previousQuestionId, AssignmentQuestion = new AssignmentQuestion() { Question = randomlySelectedQuestion } }); }
/// <summary> /// Verifies that the given randomly selected question was /// correctly duplicated. /// </summary> private void VerifyRandomlySelectedQuestion( DatabaseContext dbContext, RandomlySelectedQuestion oldQuestion, RandomlySelectedQuestion newQuestion) { VerifyReferenceDuplicated ( dbContext, oldQuestion, newQuestion, q => q.ChoicesCategory, q => q.Id, q => q.Name, VerifyQuestionCategory ); }
/// <summary> /// Creates a question loader for a randomly selected question. /// </summary> IQuestionLoader IQuestionResultVisitor <IQuestionLoader> .Visit(RandomlySelectedQuestion question) { return(new RandomlySelectedQuestionLoader(_dbContext, question)); }
/// <summary> /// Creates a question updater for a randomly selected question. /// </summary> IQuestionUpdater IQuestionResultVisitor <IQuestionUpdater, IModelErrorCollection> .Visit( RandomlySelectedQuestion question, IModelErrorCollection errors) { return(new RandomlySelectedQuestionUpdater(_dbContext, question, errors)); }
/// <summary> /// Creates a question loader for a randomly selected question. /// </summary> IUserQuestionDataUpdater IQuestionResultVisitor <IUserQuestionDataUpdater> .Visit( RandomlySelectedQuestion question) { return(_randomlySelectedUserQuestionDataUpdater); }
/// <summary> /// Creates a question duplicator for a randomly selected question. /// </summary> IQuestionDuplicator IQuestionResultVisitor <IQuestionDuplicator> .Visit(RandomlySelectedQuestion question) { throw new InvalidOperationException("Randomly selected questions cannot be duplicated."); }
/// <summary> /// Creates a question loader for a randomly selected question. /// </summary> IQuestionGrader IQuestionResultVisitor <IQuestionGrader> .Visit(RandomlySelectedQuestion question) { throw new InvalidOperationException("Randomly-selected questions cannot be graded directly. Instead, grade actual question selected."); }