Пример #1
0
        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);
        }
Пример #2
0
        public async Task AddTestCategory()
        {
            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   = false,
                    CategoryId = categoryObject.Id
                }
            };

            var             test     = CreateTest("Final");
            string          userName = "******";
            ApplicationUser user     = new ApplicationUser()
            {
                Email = userName, UserName = userName
            };
            await _userManager.CreateAsync(user);

            var applicationUser = await _userManager.FindByEmailAsync(user.Email);

            await _testRepository.CreateTestAsync(test, applicationUser.Id);

            var testCategoryList = new List <TestCategory>();
            var testCategory     = new TestCategory();

            testCategory.TestId     = test.Id;
            testCategory.CategoryId = categoryObject.Id;
            testCategoryList.Add(testCategory);
            await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC);

            Assert.True(_trappistDbContext.TestCategory.Count() == 1);
            testCategoryAC[0].IsSelect = false;
            await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC);

            Assert.True(_trappistDbContext.TestCategory.Count() == 0);
        }
Пример #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);
        }
Пример #4
0
        public async Task <ActionResult> AddTestCategoriesAsync([FromRoute] int testId, [FromBody] List <TestCategoryAC> categoryAcList)
        {
            await _testRepository.AddTestCategoriesAsync(testId, categoryAcList);

            return(Ok(true));
        }