public async Task GetTestInstructionsAsyncTest() { //Creating test var test = await CreateTestAsync(); //Creating test category var category1 = CreateCategory("Mathematics"); await _categoryRepository.AddCategoryAsync(category1); var category2 = CreateCategory("Computer"); await _categoryRepository.AddCategoryAsync(category2); var category3 = CreateCategory("History"); await _categoryRepository.AddCategoryAsync(category3); var testCategoryAC = new List <TestCategoryAC> { new TestCategoryAC() { CategoryId = category1.Id, IsSelect = true }, new TestCategoryAC() { CategoryId = category1.Id, IsSelect = false }, new TestCategoryAC() { CategoryId = category2.Id, IsSelect = true } }; await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC); //Creating test questions var questionList = new List <QuestionAC> { CreateQuestionAC(true, "Category1 type question", category1.Id, 1), CreateQuestionAC(false, "Category1 type question", category1.Id, 2), CreateQuestionAC(true, "Category3 type question", category3.Id, 3), CreateQuestionAC(true, "Category3 type question", category3.Id, 4), }; var testQuestionList = new List <TestQuestionAC>(); questionList.ForEach(x => { var testQuestion = new TestQuestionAC(); testQuestion.CategoryID = x.Question.CategoryID; testQuestion.Id = x.Question.Id; testQuestion.IsSelect = x.Question.IsSelect; testQuestionList.Add(testQuestion); }); await _testRepository.AddTestQuestionsAsync(testQuestionList, test.Id); var testInstruction = await _testConductRepository.GetTestInstructionsAsync(_stringConstants.MagicString); Assert.NotNull(testInstruction); }
public async Task <IActionResult> AddTestQuestionsAsync([FromBody] List <TestQuestionAC> questionToAdd, [FromRoute] int testId) { if (!ModelState.IsValid && await _testRepository.IsTestAttendeeExistAsync(testId)) { return(BadRequest(ModelState)); } else { var message = await _testRepository.AddTestQuestionsAsync(questionToAdd, testId); return(Ok(new { message = message })); } }
public async Task IsQuestionExistInTestTest() { var questionList = new List <TestQuestionAC>(); string userName = "******"; ApplicationUser user = new ApplicationUser() { Email = userName, UserName = userName }; await _userManager.CreateAsync(user); var applicationUser = await _userManager.FindByEmailAsync(user.Email); //create code-snippetQuestion var codingQuestion = await CreateCodingQuestion(); await _questionRepository.AddCodeSnippetQuestionAsync(codingQuestion, applicationUser.Id); //create single-multipleQuestion var multipleAnswerQuestion = await CreateMultipleAnswerQuestion(); await _questionRepository.AddSingleMultipleAnswerQuestionAsync(multipleAnswerQuestion, applicationUser.Id); var testCodingQuestion = new TestQuestionAC(); var codeSnippetquestion = await _trappistDbContext.Question.FirstOrDefaultAsync(x => x.QuestionDetail == codingQuestion.Question.QuestionDetail); testCodingQuestion.Id = codeSnippetquestion.Id; testCodingQuestion.CategoryID = codeSnippetquestion.CategoryID; testCodingQuestion.IsSelect = true; var singleMultipleQuestion = await _trappistDbContext.Question.FirstOrDefaultAsync(x => x.QuestionDetail == multipleAnswerQuestion.Question.QuestionDetail); multipleAnswerQuestion.Question.Id = singleMultipleQuestion.Id; questionList.Add(testCodingQuestion); //create Test var test = CreateTest("DemoTest"); await _testRepository.CreateTestAsync(test, applicationUser.Id); await _testRepository.AddTestQuestionsAsync(questionList, test.Id); Assert.True(await _questionRepository.IsQuestionExistInTestAsync(codeSnippetquestion.Id)); //If Question doesnot exist in test Assert.False(await _questionRepository.IsQuestionExistInTestAsync(multipleAnswerQuestion.Question.Id)); }
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); }
public async Task DeselectCategory() { //Created application user string userName = "******"; ApplicationUser user = new ApplicationUser() { Email = userName, UserName = userName }; await _userManager.CreateAsync(user); var categoryObj = CreateCategory("category1"); await _categoryRepository.AddCategoryAsync(categoryObj); var categoryObject = CreateCategory("category2"); await _categoryRepository.AddCategoryAsync(categoryObject); var testCategoryAC = new List <TestCategoryAC> { new TestCategoryAC() { IsSelect = true, CategoryId = categoryObj.Id }, new TestCategoryAC() { IsSelect = true, CategoryId = categoryObject.Id } }; var test = CreateTest("Maths"); await _testRepository.CreateTestAsync(test, user.Id); var testCategoryList = new List <TestCategory>(); var testCategory = new TestCategory(); testCategory.TestId = test.Id; testCategory.CategoryId = categoryObj.Id; testCategoryList.Add(testCategory); var testCategoryObj = new TestCategory(); testCategoryObj.TestId = test.Id; testCategoryObj.CategoryId = categoryObject.Id; testCategoryList.Add(testCategoryObj); await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC); //creating new question under categoryObj var questionAc = CreateQuestionAc(true, "Question in Category", categoryObj.Id, 1); var questionAcList = new List <TestQuestionAC> { new TestQuestionAC() { Id = questionAc.Question.Id, IsSelect = true, CategoryID = questionAc.Question.CategoryID } }; var applicationUser = await _userManager.FindByEmailAsync(user.Email); await _questionRepository.AddSingleMultipleAnswerQuestionAsync(questionAc, applicationUser.Id); var testQuestion = new TestQuestion(); testQuestion.QuestionId = questionAc.Question.Id; testQuestion.TestId = test.Id; await _testRepository.AddTestQuestionsAsync(questionAcList, test.Id); //to check if question from a category is added to test it should return true var isExists = await _testRepository.DeselectCategoryAync(categoryObj.Id, test.Id); Assert.True(isExists); //to check if question from a category is not added to test it should return false var isQuestionExists = await _testRepository.DeselectCategoryAync(categoryObject.Id, test.Id); Assert.False(isQuestionExists); //To remove deselected category from TestCategory await _testRepository.RemoveCategoryAndQuestionAsync(testCategory); Assert.Equal(1, _trappistDbContext.TestCategory.Count()); Assert.Equal(0, _trappistDbContext.TestQuestion.Count()); }