Example #1
0
        public async Task GetTestQuestionsTest()
        {
            string userName = "******";
            //Configuring Application User
            ApplicationUser user = new ApplicationUser()
            {
                Email = userName, UserName = userName
            };
            await _userManager.CreateAsync(user);

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


            var test = CreateTest("Mathematics");
            await _testRepository.CreateTestAsync(test, "4");

            var category          = CreateCategory("Maths");
            var questionToCreate1 = "Question1";
            var question1         = CreateQuestionAc(true, questionToCreate1, category.Id, 1, QuestionType.Single);
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question1, applicationUser.Id);

            var testCategoryObject = new TestCategory()
            {
                CategoryId = category.Id,
                Test       = test,
                TestId     = test.Id,
                Category   = category
            };

            _trappistDbContext.TestCategory.Add(testCategoryObject);
            await _trappistDbContext.SaveChangesAsync();

            var testQuestionObject1 = new TestQuestion()
            {
                QuestionId = question1.Question.Id,
                TestId     = test.Id,
                Test       = test,
            };
            var testQuestionList = new List <TestQuestion>();

            testQuestionList.Add(testQuestionObject1);
            await _trappistDbContext.TestQuestion.AddRangeAsync(testQuestionList);

            await _trappistDbContext.SaveChangesAsync();

            var testQuestions = await _reportRepository.GetTestQuestions(test.Id);

            Assert.Equal(1, testQuestions.Count());
        }
Example #2
0
        public async Task <IActionResult> AddQuestionAsync([FromBody] QuestionAC questionAC)
        {
            if (questionAC == null || !ModelState.IsValid || questionAC.Question.CategoryID == 0)
            {
                return(BadRequest());
            }

            var applicationUser = await _userManager.FindByEmailAsync(User.Identity.Name);

            try
            {
                if (questionAC.Question.QuestionType == QuestionType.Programming)
                {
                    //Check for default testcase before saving question
                    if (questionAC.CodeSnippetQuestion.CodeSnippetQuestionTestCases.Any(x => x.TestCaseType == TestCaseType.Default))
                    {
                        await _questionsRepository.AddCodeSnippetQuestionAsync(questionAC, applicationUser.Id);
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    await _questionsRepository.AddSingleMultipleAnswerQuestionAsync(questionAC, applicationUser.Id);
                }
            }
            catch (InvalidOperationException)
            {
                return(BadRequest());
            }

            return(Ok(questionAC));
        }
Example #3
0
        public async Task AddSingleAnswerQuestionAsyncTest()
        {
            var singleAnswerQuestion = await CreateSingleAnswerQuestion();

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

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

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

            Assert.True(_trappistDbContext.Question.Count() == 1);
            Assert.True(_trappistDbContext.SingleMultipleAnswerQuestion.Count() == 1);
            Assert.True(_trappistDbContext.SingleMultipleAnswerQuestionOption.Count() == 4);
        }
Example #4
0
        /// <summary>
        /// Creating single answer Question
        /// </summary>
        /// <returns>Object of single answer Question</returns>
        private async Task <QuestionAC> CreateSingleAnswerQuestionAsync(int categoryId, string userId)
        {
            var singleAnswerQuestion = new QuestionAC
            {
                Question = new QuestionDetailAC()
                {
                    QuestionDetail  = "what is git?",
                    CategoryID      = categoryId,
                    DifficultyLevel = DifficultyLevel.Hard,
                    QuestionType    = QuestionType.Single
                },
                SingleMultipleAnswerQuestion = new SingleMultipleAnswerQuestionAC()
                {
                    SingleMultipleAnswerQuestion       = new SingleMultipleAnswerQuestion(),
                    SingleMultipleAnswerQuestionOption = new List <SingleMultipleAnswerQuestionOption>()
                    {
                        new SingleMultipleAnswerQuestionOption()
                        {
                            IsAnswer = true,
                            Option   = "Distributed version control system",
                        },
                        new SingleMultipleAnswerQuestionOption()
                        {
                            IsAnswer = false,
                            Option   = "Continuous integration service",
                        },
                        new SingleMultipleAnswerQuestionOption()
                        {
                            IsAnswer = false,
                            Option   = "Collaborations system",
                        }
                    }
                }
            };
            await _questionRepository.AddSingleMultipleAnswerQuestionAsync(singleAnswerQuestion, userId);

            return(singleAnswerQuestion);
        }
        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);
        }
Example #6
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());
        }