public async Task <CodeResponse> ExecuteCustomInputAsync(int attendeeId, TestAnswerAC testAnswer) { var result = new Result(); if (testAnswer.Code.Input != null) { result = await ExecuteCodeAsync(testAnswer.Code); } var codeResponse = new CodeResponse() { ErrorOccurred = result.ExitCode != 0, Error = result.Output, Message = null, Output = result.Output, TimeConsumed = result.RunTime, MemoryConsumed = result.MemoryConsumed, TotalTestCasePassed = 0, TotalTestCases = 0 }; testAnswer.Code.CodeResponse = codeResponse; await AddAnswerAsync(attendeeId, testAnswer, 0.0); return(codeResponse); }
public async Task AddAnswersAsyncTest() { var testAttendee = InitializeTestAttendeeParameters(); await CreateTestAsync(); 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>() { 1, 2, 3 } }; await _testConductRepository.AddAnswerAsync(attendeeId, answer, 0.0); var attendeeAnswer = await _trappistDbContext.AttendeeAnswers.FindAsync(attendeeId); Assert.True(attendeeAnswer.Answers != null); var newAnswer = new TestAnswerAC() { OptionChoice = new List <int>() { 4, 5 } }; await _testConductRepository.AddAnswerAsync(attendeeId, newAnswer, 0.0); Assert.True(attendeeAnswer.Answers != null); }
private TestAnswerAC CreateAnswerAc(int id) { TestAnswerAC testAnswerAC = new TestAnswerAC() { QuestionId = id, OptionChoice = new List <int>() { 34, 36 }, QuestionStatus = QuestionStatus.answered }; return(testAnswerAC); }
/// <summary> /// This method is used to add the created answer to database /// </summary> /// <param name="answer">Object of TestAnswerAC type</param> /// <param name="testConductId">Test conduct id</param> private void AddTestAnswer(TestAnswerAC answer, int testConductId) { if (answer.OptionChoice.Count() > 0) { foreach (var option in answer.OptionChoice) { TestAnswers testAnswers = new TestAnswers() { AnsweredOption = option, TestConductId = testConductId }; _trappistDbContext.TestAnswers.Add(testAnswers); _trappistDbContext.SaveChanges(); } } }
public async Task AddAnswerAsync(int attendeeId, TestAnswerAC answer, double seconds) { var attendeeAnswer = await _dbContext.AttendeeAnswers.Where(x => x.Id == attendeeId).FirstOrDefaultAsync(); if (attendeeAnswer != null) { var deserializedAnswer = new List <TestAnswerAC>(); if (attendeeAnswer.Answers != null) { deserializedAnswer = JsonConvert.DeserializeObject <TestAnswerAC[]>(attendeeAnswer.Answers).ToList(); } //Remove answer if already exist var answerToUpdate = deserializedAnswer.SingleOrDefault(x => x.QuestionId == answer.QuestionId); if (answerToUpdate != null) { deserializedAnswer.Remove(answerToUpdate); } //Add answer deserializedAnswer.Add(answer); var serializedAnswer = JsonConvert.SerializeObject(deserializedAnswer); attendeeAnswer.Answers = serializedAnswer; _dbContext.AttendeeAnswers.Update(attendeeAnswer); } else { attendeeAnswer = new AttendeeAnswers(); attendeeAnswer.Id = attendeeId; if (seconds != 0.0) { attendeeAnswer.TimeElapsed = (seconds / 60d); } if (answer != null) { var testAnswerArray = new List <TestAnswerAC>(); testAnswerArray.Add(answer); attendeeAnswer.Answers = JsonConvert.SerializeObject(testAnswerArray); } await _dbContext.AddAsync(attendeeAnswer); } await _dbContext.SaveChangesAsync(); }
public async Task <IActionResult> AddAnswerAsync([FromRoute] int attendeeId, [FromBody] TestAnswerAC answer) { if (!ModelState.IsValid) { return(BadRequest()); } if (!await IsAttendeeValid(attendeeId)) { return(NotFound()); } //If the Attendee has completed the Test var attendeeTestStatus = await _testConductRepository.GetAttendeeTestStatusAsync(attendeeId); if (attendeeTestStatus != TestStatus.AllCandidates) { return(BadRequest()); } await _testConductRepository.AddAnswerAsync(attendeeId, answer, 0.0); return(Ok(answer)); }
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); }
public async Task TransformationTest() { var testAttendee = InitializeTestAttendeeParameters(); // Creating test var test = await CreateTestAsync(); var category1 = CreateCategory("Mathematics"); await _categoryRepository.AddCategoryAsync(category1); var testCategroyAC = new List <TestCategoryAC> { new TestCategoryAC() { IsSelect = true, CategoryId = category1.Id } }; await _testRepository.AddTestCategoriesAsync(test.Id, testCategroyAC); var question1 = CreateQuestionAC(true, "Category1 type question 1", category1.Id, 1); await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question1, ""); var question2 = CreateQuestionAC(true, "Category1 type question 2", category1.Id, 2); await _questionRepository.AddSingleMultipleAnswerQuestionAsync(question2, ""); //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 answer = new TestAnswerAC() { OptionChoice = new List <int>() { question1.SingleMultipleAnswerQuestion.SingleMultipleAnswerQuestionOption[0].Id }, QuestionId = 1, QuestionStatus = QuestionStatus.answered }; await _testConductRepository.AddAnswerAsync(attendeeId, answer, 0.0); answer = 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, answer, 0.0); //Setting Attendee TestStatus await _testConductRepository.SetAttendeeTestStatusAsync(attendeeId, TestStatus.CompletedTest); var testStatus = await _trappistDbContext.TestConduct.Where(x => x.TestAttendeeId == attendeeId).ToListAsync(); Assert.NotNull(testStatus); }
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); }
public async Task <CodeResponse> ExecuteCodeSnippetAsync(int attendeeId, bool runOnlyDefault, TestAnswerAC testAnswer) { var allTestCasePassed = true; var countPassedTest = 0; var errorEncounter = false; var errorMessage = ""; var score = 0d; var code = testAnswer.Code; var codeResponse = new CodeResponse(); var testCases = new List <CodeSnippetQuestionTestCases>(); var results = new List <Result>(); var testCaseResults = new List <TestCaseResult>(); var testCaseChecks = await _dbContext.CodeSnippetQuestion.SingleOrDefaultAsync(x => x.Id == testAnswer.QuestionId); var completeTestCases = await _dbContext.CodeSnippetQuestionTestCases.Where(x => x.CodeSnippetQuestionId == testAnswer.QuestionId).ToListAsync(); //Filter Test Cases testCases.AddRange(completeTestCases.Where(x => x.TestCaseType == TestCaseType.Default).ToList()); if (testCaseChecks.RunBasicTestCase && !runOnlyDefault) { testCases.AddRange(completeTestCases.Where(x => x.TestCaseType == TestCaseType.Basic).ToList()); } if (testCaseChecks.RunCornerTestCase && !runOnlyDefault) { testCases.AddRange(completeTestCases.Where(x => x.TestCaseType == TestCaseType.Corner).ToList()); } if (testCaseChecks.RunNecessaryTestCase && !runOnlyDefault) { testCases.AddRange(completeTestCases.Where(x => x.TestCaseType == TestCaseType.Necessary).ToList()); } //End of filter foreach (var testCase in testCases) { code.Input = testCase.TestCaseInput; var result = await ExecuteCodeAsync(code); if (result.ExitCode != 0) { errorEncounter = true; errorMessage = result.Output; } //Trim newline character result.Output = result.Output.TrimEnd(new char[] { '\r', '\n' }); if (result.Output != testCase.TestCaseOutput) { allTestCasePassed = false; } else { countPassedTest++; //Calculate score score += testCase.TestCaseMarks; } var testCaseResult = new TestCaseResult() { Memory = result.MemoryConsumed, Output = result.Output, CodeSnippetQuestionTestCasesId = testCase.Id, Processing = result.RunTime }; testCaseResults.Add(testCaseResult); } //Add score to the TestCodeSolution table //Final score is calculated using the following formula: //Total score of this question = Sum(1st test case marks + 2nd test case marks .....) / Sum of total marks of all test cases var totalTestCaseScore = testCases.Sum(x => x.TestCaseMarks); var codeSolution = new TestCodeSolution() { TestAttendeeId = attendeeId, QuestionId = testAnswer.QuestionId, Solution = testAnswer.Code.Source, Language = testAnswer.Code.Language, Score = score / totalTestCaseScore }; await _dbContext.TestCodeSolution.AddAsync(codeSolution); await _dbContext.SaveChangesAsync(); //Add result to TestCaseResult Table foreach (var testCaseResult in testCaseResults) { testCaseResult.TestCodeSolution = codeSolution; } await _dbContext.TestCaseResult.AddRangeAsync(testCaseResults); await _dbContext.SaveChangesAsync(); codeResponse.ErrorOccurred = false; if (allTestCasePassed && !errorEncounter) { codeResponse.Message = runOnlyDefault ? _stringConstants.DefaultTestCasePassed : _stringConstants.AllTestCasePassed; } else if (!errorEncounter) { if (countPassedTest > 0) { codeResponse.Message = runOnlyDefault ? _stringConstants.DefaultTestCaseFailed : _stringConstants.SomeTestCasePassed; } else { codeResponse.Message = runOnlyDefault ? _stringConstants.DefaultTestCaseFailed : _stringConstants.NoTestCasePassed; } } else { codeResponse.ErrorOccurred = true; codeResponse.Error = errorMessage; } //Add answer to the database testAnswer.Code.CodeResponse = codeResponse; codeResponse.TotalTestCases = testCases.Count(); codeResponse.TotalTestCasePassed = countPassedTest; await AddAnswerAsync(attendeeId, testAnswer, 0.0); return(codeResponse); }
public async Task GetTestCodeSolutionDetailsAsyncTest() { var test = CreateTest("Coding Test"); await _testRepository.CreateTestAsync(test, "5"); var testAttendee = CreateTestAttendee(test.Id); await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); //create category var category = CreateCategory("programming"); await _categoryRepository.AddCategoryAsync(category); //create coding question var question = CreateCodingQuestionAc(true, category.Id, 2, QuestionType.Programming); await _questionRepository.AddCodeSnippetQuestionAsync(question, test.CreatedByUserId); var questionId = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == question.Question.QuestionDetail)).Id; var answer = new TestAnswerAC() { OptionChoice = new List <int>(), QuestionId = questionId, Code = new Code() { Input = "input", Source = "source", Language = ProgrammingLanguage.C }, QuestionStatus = QuestionStatus.answered }; await _testConductRepository.AddAnswerAsync(testAttendee.Id, answer, 0.0); //add test code solution var codeSolution1 = new TestCodeSolution() { Id = 1, TestAttendeeId = testAttendee.Id, QuestionId = questionId, Solution = answer.Code.Source, Language = answer.Code.Language, Score = 1 }; var codeSolution2 = new TestCodeSolution() { Id = 2, TestAttendeeId = testAttendee.Id, QuestionId = questionId, Solution = answer.Code.Source, Language = answer.Code.Language, Score = 0 }; await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution1); await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution2); await _trappistDbContext.SaveChangesAsync(); var codeSolutionObject = await _reportRepository.GetTestCodeSolutionDetailsAsync(testAttendee.Id, 3); var codeSolutionAcObject = await _reportRepository.GetTestCodeSolutionDetailsAsync(testAttendee.Id, questionId); Assert.Equal(null, codeSolutionObject); Assert.Equal(answer.Code.Language, codeSolutionAcObject.Language); Assert.Equal(answer.Code.Source, codeSolutionAcObject.CodeSolution); Assert.Equal(1, codeSolutionAcObject.NumberOfSuccessfulAttempts); Assert.Equal(2, codeSolutionAcObject.TotalNumberOfAttempts); }
public async Task GetTotalMarksOfCodeSnippetQuestionAsyncTest() { var test = CreateTest("Programming"); await _testRepository.CreateTestAsync(test, "5"); var testAttendee = CreateTestAttendee(test.Id); await _testConductRepository.RegisterTestAttendeesAsync(testAttendee); //create category var category = CreateCategory("programming"); await _categoryRepository.AddCategoryAsync(category); //create coding question var question = CreateCodingQuestionAc(true, category.Id, 2, QuestionType.Programming); await _questionRepository.AddCodeSnippetQuestionAsync(question, test.CreatedByUserId); var questionId = (await _trappistDbContext.Question.SingleAsync(x => x.QuestionDetail == question.Question.QuestionDetail)).Id; var answer = new TestAnswerAC() { OptionChoice = new List <int>(), QuestionId = questionId, Code = new Code() { Input = "input", Source = "source", Language = ProgrammingLanguage.C }, QuestionStatus = QuestionStatus.answered, IsAnswered = true }; var list = new List <TestCodeSolution>(); await _testConductRepository.AddAnswerAsync(testAttendee.Id, answer, 0.0); //add test code solution var codeSolution1 = new TestCodeSolution() { Id = 1, TestAttendeeId = testAttendee.Id, QuestionId = questionId, Solution = answer.Code.Source, Language = answer.Code.Language, Score = 1, }; await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution1); await _trappistDbContext.SaveChangesAsync(); var codeSolution2 = new TestCodeSolution() { Id = 2, TestAttendeeId = testAttendee.Id, QuestionId = questionId, Solution = answer.Code.Source, Language = answer.Code.Language, Score = 0, }; await Task.Delay(500); await _trappistDbContext.TestCodeSolution.AddAsync(codeSolution2); await _trappistDbContext.SaveChangesAsync(); var marksScoredInCodeSnippetQuestion = await _reportRepository.GetTotalMarksOfCodeSnippetQuestionAsync(testAttendee.Id, questionId); var marksScoredWhenQuestionIdAbsent = await _reportRepository.GetTotalMarksOfCodeSnippetQuestionAsync(testAttendee.Id, 3); Assert.Equal(0, marksScoredInCodeSnippetQuestion); Assert.Equal(-1, marksScoredWhenQuestionIdAbsent); }
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); }
public async Task <IActionResult> EvaluateCodeSnippet([FromRoute] int attendeeId, [FromRoute] bool runOnlyDefault, [FromBody] TestAnswerAC testAnswer) { if (!ModelState.IsValid) { return(BadRequest()); } if (testAnswer.Code == null || testAnswer.Code.Source == "") { return(BadRequest()); } var codeResponse = testAnswer.Code.Input == null ? await _testConductRepository.ExecuteCodeSnippetAsync(attendeeId, runOnlyDefault, testAnswer) : await _testConductRepository.ExecuteCustomInputAsync(attendeeId, testAnswer); return(Ok(codeResponse)); }