Пример #1
0
        public async Task <List <TestAttendees> > GenerateReportForUnfinishedTestAsync(List <int> attendeeIdList)
        {
            foreach (var id in attendeeIdList)
            {
                await _testConductRepository.SetAttendeeTestStatusAsync(id, TestStatus.UnfinishedTest);
            }

            return(await _dbContext.TestAttendees.Where(x => attendeeIdList.Any(id => id == x.Id)).Include(x => x.Report).ToListAsync());
        }
Пример #2
0
        public async Task <IActionResult> SetTestStatusAsync([FromRoute] int attendeeId, [FromBody] TestStatus testStatus)
        {
            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());
            }
            var attendee = await _testConductRepository.SetAttendeeTestStatusAsync(attendeeId, testStatus);

            return(Ok(attendee));
        }
Пример #3
0
        public async Task GetSetAttendeeTestStatusAsyncTest()
        {
            var testAttendee = InitializeTestAttendeeParameters();
            // Creating test
            var test = await CreateTestAsync();

            //Creating test category
            var category1 = CreateCategory("Mathematics");
            var category2 = CreateCategory("History");
            await _categoryRepository.AddCategoryAsync(category1);

            var testCategoryAC = new List <TestCategoryAC>
            {
                new TestCategoryAC()
                {
                    IsSelect   = true,
                    CategoryId = category1.Id
                }
            };

            await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC);

            var question1 = CreateQuestionAC(true, "Category1 type question 1", category1.Id, 1);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question1, "");

            var question2 = CreateQuestionAC(true, "Category1 type question 1", category1.Id, 2);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question2, "");

            var question3 = CreateQuestionAC(true, "Who was the father of Akbar ?", category2.Id, 3);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question3, "");

            var question4 = CreateQuestionAC(true, "When was the first battle of Panipat fought ?", category2.Id, 4);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question4, "");

            var question5 = CreateQuestionAc(true, "When were the battles of Terrain fought ?", category2.Id, 5);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question5, "");

            var question6 = CreateQuestionAc(true, "Mention the years of two important battles fought by Prithviraj Chauhan ?", category2.Id, 6);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question6, "");

            //Creating test questions
            var questionList = new List <TestQuestionAC>
            {
                new TestQuestionAC()
                {
                    Id         = question1.Question.Id,
                    IsSelect   = question1.Question.IsSelect,
                    CategoryID = question1.Question.CategoryID
                },
                new TestQuestionAC()
                {
                    Id         = question2.Question.Id,
                    IsSelect   = question2.Question.IsSelect,
                    CategoryID = question2.Question.CategoryID
                }
            };
            await _testRepository.AddTestQuestionsAsync(questionList, test.Id);

            testAttendee.Test = test;
            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 answer1 = new TestAnswerAC()
            {
                OptionChoice = new List <int>()
                {
                    question1.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[0].Id
                },
                QuestionId     = 1,
                QuestionStatus = QuestionStatus.answered
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer1, 0.0);

            var answer2 = new TestAnswerAC()
            {
                OptionChoice = new List <int>(),
                QuestionId   = 2,
                Code         = new Code()
                {
                    Input    = "input",
                    Source   = "source",
                    Language = ProgrammingLanguage.C,
                },
                QuestionStatus = QuestionStatus.unanswered
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer2, 0.0);

            var answer3 = new TestAnswerAC()
            {
                OptionChoice   = new List <int>(),
                QuestionId     = 3,
                QuestionStatus = QuestionStatus.review
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer3, 0.0);

            var answer4 = new TestAnswerAC()
            {
                OptionChoice = new List <int>()
                {
                    question4.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[1].Id
                },
                QuestionId     = 4,
                QuestionStatus = QuestionStatus.review
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer4, 0.0);

            var answer5 = new TestAnswerAC()
            {
                OptionChoice = new List <int>()
                {
                    question5.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[0].Id,
                    question5.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[1].Id
                },
                QuestionId     = 5,
                QuestionStatus = QuestionStatus.answered
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer5, 0.0);

            var answer6 = new TestAnswerAC()
            {
                OptionChoice = new List <int>()
                {
                    question6.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[1].Id,
                    question6.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[2].Id
                },
                QuestionId     = 6,
                QuestionStatus = QuestionStatus.review
            };
            await _testConductRepository.AddAnswerAsync(attendeeId, answer6, 0.0);

            //Setting Attendee TestStatus
            await _testConductRepository.SetElapsedTimeAsync(attendeeId, 60, false);

            await _testConductRepository.SetAttendeeTestStatusAsync(attendeeId, TestStatus.CompletedTest);

            var testStatus = await _testConductRepository.GetAttendeeTestStatusAsync(attendeeId);

            Assert.True(testStatus == TestStatus.CompletedTest);
            Assert.True(testAttendee.TestLogs.FinishTest != default(DateTime));
            Assert.True(testAttendee.Report.TimeTakenByAttendee != 0);
            Assert.True(testAttendee.Report.TotalMarksScored == 6);
        }