Exemplo n.º 1
0
        public async Task GetAllQuestionsAsyncTest()
        {
            string userName = "******";


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

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

            var codingQuestion = await CreateCodingQuestion();

            await _questionRepository.AddCodeSnippetQuestionAsync(codingQuestion, applicationUser.Id);

            string searchQuestion = null;
            var    result         = await _questionRepository.GetAllQuestionsAsync(applicationUser.Id, 0, 0, "All", searchQuestion);

            Assert.Equal(1, result.Count());
            var resultForCategory = await _questionRepository.GetAllQuestionsAsync(applicationUser.Id, 0, codingQuestion.Question.CategoryID, "All", searchQuestion);

            Assert.Equal(1, resultForCategory.Count());
            var resultWithDifficultyLevel = await _questionRepository.GetAllQuestionsAsync(applicationUser.Id, 0, 0, "Easy", searchQuestion);

            Assert.Equal(1, resultWithDifficultyLevel.Count());
            var resultWithSearchInput = await _questionRepository.GetAllQuestionsAsync(applicationUser.Id, 0, codingQuestion.Question.CategoryID, "All", "Write");

            Assert.Equal(1, resultWithSearchInput.Count());
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public async Task ExecuteCodeSnippetAsyncTest()
        {
            var testAttendee = InitializeTestAttendeeParameters();
            // Creating test
            var test = await CreateTestAsync();

            var categoryToCreate = CreateCategory("Coding");

            await _categoryRepository.AddCategoryAsync(categoryToCreate);

            var testCategoryAC = new List <TestCategoryAC>
            {
                new TestCategoryAC()
                {
                    IsSelect   = true,
                    CategoryId = categoryToCreate.Id
                }
            };
            await _testRepository.AddTestCategoriesAsync(test.Id, testCategoryAC);

            var codingQuestion = CreateCodingQuestion(categoryToCreate);
            await _questionRepository.AddCodeSnippetQuestionAsync(codingQuestion, testAttendee.Email);

            var questionId = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == codingQuestion.Question.QuestionDetail)).Id;
            //Creating test questions
            var questionList = new List <TestQuestionAC>
            {
                new TestQuestionAC()
                {
                    Id         = codingQuestion.Question.Id,
                    IsSelect   = codingQuestion.Question.IsSelect,
                    CategoryID = codingQuestion.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 answer = new TestAnswerAC()
            {
                OptionChoice = new List <int>(),
                QuestionId   = questionId,
                Code         = new Code()
                {
                    Input    = "input",
                    Source   = "source",
                    Language = ProgrammingLanguage.C
                },
                QuestionStatus = QuestionStatus.unanswered
            };

            //Mocking HttpRequest
            var result = new Result()
            {
                CyclicMetrics  = 0,
                ExitCode       = 0,
                MemoryConsumed = 1,
                Output         = "4",
                RunTime        = 1
            };
            var serializedResult = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            _httpService.Setup(x => x.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>())).Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(serializedResult, System.Text.Encoding.UTF8, "application/json")
            }));
            //End of Mocking

            var codeRespone = await _testConductRepository.ExecuteCodeSnippetAsync(attendeeId, false, answer);

            Assert.NotNull(codeRespone);
        }
Exemplo n.º 4
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);
        }