Beispiel #1
0
        public async Task <ActionResult> RemoveCategoryAndQuestionAsync([FromBody] TestCategory testCategory)
        {
            await _testRepository.RemoveCategoryAndQuestionAsync(testCategory);

            return(Ok(testCategory));
        }
Beispiel #2
0
        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());
        }