Esempio n. 1
0
        public async Task <IActionResult> AddAnswerAsync([FromRoute] int attendeeId, [FromBody] TestAnswerAC answer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!await IsAttendeeValid(attendeeId))
            {
                return(NotFound());
            }

            //If the Attendee has completed the Test
            var attendeeTestStatus = await _testConductRepository.GetAttendeeTestStatusAsync(attendeeId);

            if (attendeeTestStatus != TestStatus.AllCandidates)
            {
                return(BadRequest());
            }

            await _testConductRepository.AddAnswerAsync(attendeeId, answer, 0.0);

            return(Ok(answer));
        }
Esempio n. 2
0
        public async Task AddAnswersAsyncTest()
        {
            var testAttendee = InitializeTestAttendeeParameters();

            await CreateTestAsync();

            await _testConductRepository.RegisterTestAttendeesAsync(testAttendee);

            var attendeeId = await _trappistDbContext.TestAttendees.OrderBy(x => x.Email).Where(x => x.Email.Equals(testAttendee.Email)).Select(x => x.Id).FirstOrDefaultAsync();

            var answer = new TestAnswerAC()
            {
                OptionChoice = new List <int>()
                {
                    1, 2, 3
                }
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer, 0.0);

            var attendeeAnswer = await _trappistDbContext.AttendeeAnswers.FindAsync(attendeeId);

            Assert.True(attendeeAnswer.Answers != null);

            var newAnswer = new TestAnswerAC()
            {
                OptionChoice = new List <int>()
                {
                    4, 5
                }
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, newAnswer, 0.0);

            Assert.True(attendeeAnswer.Answers != null);
        }
Esempio n. 3
0
        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);
        }