public void Gets_syntax_error_hint() { using var scope = _factory.Services.CreateScope(); var controller = new SubmissionController(_factory.Services.GetRequiredService <IMapper>(), scope.ServiceProvider.GetRequiredService <ISubmissionService>()); var submission = new ChallengeSubmissionDTO { ChallengeId = 41, LearnerId = 1, SourceCode = new [] { @"public class Test { private string name; public Test() { name = test } }" } }; var actualEvaluation = ((OkObjectResult)controller.SubmitChallenge(submission).Result).Value as ChallengeEvaluationDTO; actualEvaluation.ApplicableHints.Count.ShouldBe(1); var errors = actualEvaluation.ApplicableHints[0].Content; errors.Split("\n").Length.ShouldBe(1); }
public ActionResult <ChallengeEvaluationDTO> SubmitChallenge( [FromBody] ChallengeSubmissionDTO challengeSubmission) { ChallengeEvaluation challengeEvaluation; try { challengeEvaluation = _submissionService.EvaluateChallenge(_mapper.Map <ChallengeSubmission>(challengeSubmission)); } catch (LearnerNotEnrolledInCourse e) { return(Forbid(e.Message)); } catch (InvalidOperationException e) { return(BadRequest(e.Message)); } if (challengeEvaluation == null) { return(NotFound()); } return(Ok(_mapper.Map <ChallengeEvaluationDTO>(challengeEvaluation))); }
public async Task <ChallengeEvaluationDTO> SubmitChallengeAsync(string[] sourceCode, int challengeId, int learnerId) { var payload = new ChallengeSubmissionDTO(sourceCode, challengeId, learnerId); var request = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(_baseUrl + "submissions/challenge", request); var content = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <ChallengeEvaluationDTO>(content)); }
public void Rejects_bad_challenge_submission() { using var scope = _factory.Services.CreateScope(); var controller = new SubmissionController(_factory.Services.GetRequiredService <IMapper>(), scope.ServiceProvider.GetRequiredService <ISubmissionService>()); var submission = new ChallengeSubmissionDTO { ChallengeId = 41, LearnerId = 1 }; controller.SubmitChallenge(submission).Result.ShouldBeOfType <BadRequestObjectResult>(); }
public void Accepts_challenge_submission_and_produces_correct_evaluation(ChallengeSubmissionDTO submission, ChallengeEvaluationDTO expectedEvaluation) { using var scope = _factory.Services.CreateScope(); var controller = new SubmissionController(_factory.Services.GetRequiredService <IMapper>(), scope.ServiceProvider.GetRequiredService <ISubmissionService>()); var dbContext = scope.ServiceProvider.GetRequiredService <SmartTutorContext>(); var actualEvaluation = ((OkObjectResult)controller.SubmitChallenge(submission).Result).Value as ChallengeEvaluationDTO; actualEvaluation.SolutionLO.Id.ShouldBe(expectedEvaluation.SolutionLO.Id); actualEvaluation.ChallengeId.ShouldBe(expectedEvaluation.ChallengeId); actualEvaluation.ApplicableHints.Count.ShouldBe(expectedEvaluation.ApplicableHints.Count); actualEvaluation.ApplicableHints.Select(h => h.LearningObject.Id) .All(expectedEvaluation.ApplicableHints.Select(i => i.LearningObject.Id).Contains).ShouldBeTrue(); var actualSubmission = dbContext.ChallengeSubmissions.OrderBy(s => s.TimeStamp).Last(c => c.ChallengeId == submission.ChallengeId); actualSubmission.IsCorrect.ShouldBe(expectedEvaluation.ChallengeCompleted); }