예제 #1
0
        public async Task <IActionResult> GetTestCategoryQuestionsByIdAsync([FromRoute] int testId, [FromRoute] int categoryId)
        {
            var applicationUser = await _userManager.FindByEmailAsync(User.Identity.Name);

            return(Ok(await _testRepository.GetAllQuestionsByIdAsync(testId, categoryId, applicationUser.Id)));
        }
예제 #2
0
        public async Task GetAllTestCategoryQuestionsByIdAsync()
        {
            var category1 = CreateCategory("category1");
            await _categoryRepository.AddCategoryAsync(category1);

            var category2 = CreateCategory("category2");
            await _categoryRepository.AddCategoryAsync(category2);

            var testCategoryAC = new List <TestCategoryAC>
            {
                new TestCategoryAC()
                {
                    IsSelect   = true,
                    CategoryId = category1.Id
                },
                new TestCategoryAC()
                {
                    IsSelect   = false,
                    CategoryId = category2.Id
                }
            };
            string userName = "******";
            //Configuring Application User
            ApplicationUser user = new ApplicationUser()
            {
                Email = userName, UserName = userName
            };
            await _userManager.CreateAsync(user);

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

            //Creating questions
            var question1 = CreateQuestionAc(true, "This is in Category 1", category1.Id, 0);
            var question2 = CreateQuestionAc(true, "This is in Category 2", category2.Id, 0);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question1, applicationUser.Id);

            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question2, applicationUser.Id);

            var allQuestions = await _questionRepository.GetAllQuestionsAsync(user.Id, 0, 0, "All", null);

            var test = CreateTest("Maths");
            await _testRepository.CreateTestAsync(test, applicationUser.Id);

            //Adding categories to test
            await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC);

            var questionListAc     = new List <TestQuestionAC>();
            var questionDetailList = Mapper.Map <List <Question>, List <QuestionDetailAC> >(allQuestions.ToList());

            foreach (var question in questionDetailList)
            {
                var questionAc = new TestQuestionAC();
                questionAc.IsSelect = true;
                questionAc.Id       = question.Id;
                questionListAc.Add(questionAc);
            }
            await _testRepository.AddTestQuestionsAsync(questionListAc, test.Id);

            var questionAcList = await _testRepository.GetAllQuestionsByIdAsync(test.Id, category1.Id, applicationUser.Id);

            Assert.Equal(1, questionAcList.Count);
            Assert.Equal(2, _trappistDbContext.TestQuestion.Count());
            Assert.True(questionAcList[0].Question.IsSelect);
        }