public async Task GetAttemptedQuestionsByAttendeeAsyncTest() { var test = CreateTest("General Awareness"); await _testRepository.CreateTestAsync(test, "5"); var testAttendee = CreateTestAttendee(test.Id); await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); var testConduct1 = new DomainModel.Models.TestConduct.TestConduct() { TestAttendeeId = testAttendee.Id, QuestionId = 1, QuestionStatus = QuestionStatus.answered }; var testConduct2 = new DomainModel.Models.TestConduct.TestConduct() { TestAttendeeId = testAttendee.Id, QuestionId = 1, QuestionStatus = QuestionStatus.review }; var testConduct3 = new DomainModel.Models.TestConduct.TestConduct() { TestAttendeeId = testAttendee.Id, QuestionId = 1, QuestionStatus = QuestionStatus.review }; _trappistDbContext.TestConduct.Add(testConduct1); _trappistDbContext.TestConduct.Add(testConduct2); _trappistDbContext.TestConduct.Add(testConduct3); await _trappistDbContext.SaveChangesAsync(); var testAnswer1 = new TestAnswers() { AnsweredOption = 2, TestConductId = testConduct1.Id }; var testAnswer2 = new TestAnswers() { AnsweredOption = 4, TestConductId = testConduct2.Id }; var testAnswer3 = new TestAnswers() { AnsweredOption = null, TestConductId = testConduct3.Id }; _trappistDbContext.TestAnswers.Add(testAnswer1); _trappistDbContext.TestAnswers.Add(testAnswer2); _trappistDbContext.TestAnswers.Add(testAnswer3); await _trappistDbContext.SaveChangesAsync(); var numberOfQuestionsAttemptedByAttendee = await _reportRepository.GetAttemptedQuestionsByAttendeeAsync(testAttendee.Id); Assert.Equal(2, numberOfQuestionsAttemptedByAttendee); }
public async Task GetTestAttendeeAnswersTest() { var test = CreateTest("Mathematics"); await _testRepository.CreateTestAsync(test, "5"); var testAttendee = CreateTestAttendee(test.Id); await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); var testConduct1 = new DomainModel.Models.TestConduct.TestConduct() { TestAttendeeId = testAttendee.Id, QuestionId = 1 }; var testConduct2 = new DomainModel.Models.TestConduct.TestConduct() { TestAttendeeId = testAttendee.Id, QuestionId = 1 }; _trappistDbContext.TestConduct.Add(testConduct1); _trappistDbContext.TestConduct.Add(testConduct2); await _trappistDbContext.SaveChangesAsync(); var testAnswer1 = new TestAnswers() { AnsweredOption = 2, TestConductId = testConduct1.Id }; var testAnswer2 = new TestAnswers() { AnsweredOption = 4, TestConductId = testConduct2.Id }; _trappistDbContext.TestAnswers.Add(testAnswer1); _trappistDbContext.TestAnswers.Add(testAnswer2); await _trappistDbContext.SaveChangesAsync(); var testAnswersList = await _reportRepository.GetTestAttendeeAnswers(testAttendee.Id); Assert.Equal(2, testAnswersList.Count()); }
/// <summary> /// Transform Attendee's JSON formatted Answer stored in AttendeeAnswers table /// to reliable TestAnswer and TestConduct tables. /// </summary> /// <param name="attendeeId">Id of Test Attendee</param> private async Task TransformAttendeeAnswer(int attendeeId) { var attendeeAnswer = await _dbContext.AttendeeAnswers.AsNoTracking().SingleOrDefaultAsync(x => x.Id == attendeeId); var testAnswersList = new List <TestAnswers>(); var testConductList = new List <DomainModel.Models.TestConduct.TestConduct>(); if (attendeeAnswer != null) { if (attendeeAnswer.Answers != null) { var deserializedAnswer = JsonConvert.DeserializeObject <TestAnswerAC[]>(attendeeAnswer.Answers).ToList(); //Remove existing transformation var testConductExist = await _dbContext.TestConduct.AnyAsync(x => x.TestAttendeeId == attendeeId); if (testConductExist) { var testConductListToRemove = await _dbContext.TestConduct.Where(x => x.TestAttendeeId == attendeeId).ToListAsync(); _dbContext.TestConduct.RemoveRange(testConductListToRemove); await _dbContext.SaveChangesAsync(); } foreach (var answer in deserializedAnswer) { var testAnswers = new TestAnswers(); var testConduct = new DomainModel.Models.TestConduct.TestConduct(); //Adding attempted Question to TestConduct table testConduct = new DomainModel.Models.TestConduct.TestConduct() { QuestionId = answer.QuestionId, QuestionStatus = answer.QuestionStatus, TestAttendeeId = attendeeId, IsAnswered = answer.IsAnswered }; testConductList.Add(testConduct); //Adding answer to TestAnswer Table if (answer.OptionChoice.Count() > 0) { //A question can have multiple answer foreach (var option in answer.OptionChoice) { testAnswers = new TestAnswers() { AnsweredOption = option, TestConduct = testConduct }; testAnswersList.Add(testAnswers); } } else { //Save answer for code snippet question if (answer.Code != null) { testAnswers.AnsweredCodeSnippet = answer.Code.Source; } testAnswers.TestConduct = testConduct; testAnswersList.Add(testAnswers); } } await _dbContext.TestAnswers.AddRangeAsync(testAnswersList); await _dbContext.TestConduct.AddRangeAsync(testConductList); await _dbContext.SaveChangesAsync(); } } }
public async Task GetAllAttendeeMarksDetailsAsyncTest() { //create test var createTest = await CreateTestAsync(); //create category var category = CreateCategory("History"); await _categoryRepository.AddCategoryAsync(category); //create question var question1 = CreateQuestionAc(true, "first Question", category.Id, 1, QuestionType.Multiple); var question2 = CreateCodingQuestionAc(true, category.Id, 2, QuestionType.Programming); await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question1, createTest.CreatedByUserId); await _questionRepository.AddCodeSnippetQuestionAsync(question2, createTest.CreatedByUserId); var questionId1 = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == question1.Question.QuestionDetail)).Id; var questionId2 = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == question2.Question.QuestionDetail)).Id; //add test category var categoryList = new List <DomainModel.Models.Category.Category>(); categoryList.Add(category); var testCategoryList = new List <TestCategoryAC> { new TestCategoryAC { CategoryId = category.Id, IsSelect = true, } }; await _testRepository.AddTestCategoriesAsync(createTest.Id, testCategoryList); //add test Question var questionList = new List <TestQuestionAC> { new TestQuestionAC() { Id = question1.Question.Id, CategoryID = question1.Question.CategoryID, IsSelect = question1.Question.IsSelect }, new TestQuestionAC() { Id = question2.Question.Id, IsSelect = question2.Question.IsSelect, CategoryID = question2.Question.CategoryID } }; await _testRepository.AddTestQuestionsAsync(questionList, createTest.Id); //create test attednee var testAttendee = CreateTestAttendee(createTest.Id); await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); //AddTestAnswer var answer1 = CreateAnswerAc(questionId1); await _testConductRepository.AddAnswerAsync(testAttendee.Id, answer1, 0.0); var answer2 = new TestAnswerAC() { OptionChoice = new List <int>(), QuestionId = questionId2, Code = new Code() { Input = "input", Source = "source", Language = ProgrammingLanguage.C }, QuestionStatus = QuestionStatus.answered }; await _testConductRepository.AddAnswerAsync(testAttendee.Id, answer2, 0.0); //create test conduct var testConduct1 = new DomainModel.Models.TestConduct.TestConduct() { Id = 1, QuestionId = answer1.QuestionId, QuestionStatus = answer1.QuestionStatus, TestAttendeeId = testAttendee.Id }; var testConduct2 = new DomainModel.Models.TestConduct.TestConduct() { Id = 2, QuestionId = answer2.QuestionId, QuestionStatus = answer2.QuestionStatus, TestAttendeeId = testAttendee.Id }; await _trappistDbContext.TestConduct.AddAsync(testConduct1); await _trappistDbContext.TestConduct.AddAsync(testConduct2); await _trappistDbContext.SaveChangesAsync(); AddTestAnswer(answer1, testConduct1.Id); AddTestAnswer(answer2, testConduct2.Id); //add test code solution var codeSolution1 = new TestCodeSolution() { TestAttendeeId = testAttendee.Id, QuestionId = questionId2, Solution = answer2.Code.Source, Language = answer2.Code.Language, Score = 1 }; var codeSolution2 = new TestCodeSolution() { TestAttendeeId = testAttendee.Id, QuestionId = questionId2, Solution = answer2.Code.Source, Language = answer2.Code.Language, Score = 0 }; await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution1); await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution2); await _trappistDbContext.SaveChangesAsync(); var allAttendeeMarksDetails = await _reportRepository.GetAllAttendeeMarksDetailsAsync(createTest.Id); var totalQuestionAttempted = allAttendeeMarksDetails.First().NoOfQuestionAttempted; var easyQuestionAttempted = allAttendeeMarksDetails.First().EasyQuestionAttempted; Assert.Equal(2, easyQuestionAttempted); Assert.Equal(2, totalQuestionAttempted); }