public void CheckAnswer_CompileSourceCode() { var mockCompilationService = MockRepository.GenerateMock<CompilationService>(); mockCompilationService.Stub(s => s.CompileSourceCode(Arg<string>.Is.Anything)).Return( MockRepository.GenerateStub<CompilerResults>(new TempFileCollection())); var stubTestsRunnerService = MockRepository.GenerateStub<RunnerService>(); var stubQuestion = MockRepository.GenerateStub<Question>(); stubQuestion.SourceCode = "answerSourceCode"; var correctionProcess = new CorrectionProcess(mockCompilationService, stubTestsRunnerService); correctionProcess.CheckAnswer(stubQuestion); mockCompilationService.AssertWasCalled(m => m.CompileSourceCode(stubQuestion.SourceCode)); }
public void CheckAnswer_WhenExistsCompilationErrors_SetsErrorList() { var stubCompilationService = new CompilationService(); CompilerResults compilerResults = stubCompilationService.CompileSourceCode("NotCompilingSourceCode"); var stubTestsRunnerService = MockRepository.GenerateStub<RunnerService>(); var correctionProcess = new CorrectionProcess(stubCompilationService, stubTestsRunnerService); CorrectionResult correctionResult = correctionProcess.CheckAnswer(new Question {SourceCode = "NotCompilingSourceCode"}); Assert.AreEqual(compilerResults.Errors.Count, correctionResult.Errors.Count); Assert.AreEqual(compilerResults.Errors[0].ErrorText, correctionResult.Errors[0]); Assert.AreEqual(compilerResults.Errors[compilerResults.Errors.Count - 1].ErrorText, correctionResult.Errors[correctionResult.Errors.Count - 1]); }
public void CheckAnswer_RunSourceCode() { var mockRunnerService = MockRepository.GenerateMock<RunnerService>(); var stubQuestion = MockRepository.GenerateStub<Question>(); var stubCompilationService = MockRepository.GenerateMock<CompilationService>(); var stubAssembly = Assembly.GetCallingAssembly(); var stubCompilerResults = MockRepository.GenerateStub<CompilerResults>(new TempFileCollection()); stubCompilerResults.CompiledAssembly = stubAssembly; stubCompilationService.Stub(s => s.CompileSourceCode(stubQuestion.SourceCode)).Return( stubCompilerResults); var correctionProcess = new CorrectionProcess(stubCompilationService, mockRunnerService); correctionProcess.CheckAnswer(stubQuestion); mockRunnerService.AssertWasCalled(m => m.RunMethod(stubAssembly, stubQuestion)); }
public void CheckAnswer_WhenExistsCompilationErrors_SetsErrorList() { var stubCompilationService = new CompilationService(); CompilerResults compilerResults = stubCompilationService.CompileSourceCode("NotCompilingSourceCode"); var stubTestsRunnerService = MockRepository.GenerateStub <RunnerService>(); var correctionProcess = new CorrectionProcess(stubCompilationService, stubTestsRunnerService); CorrectionResult correctionResult = correctionProcess.CheckAnswer(new Question { SourceCode = "NotCompilingSourceCode" }); Assert.AreEqual(compilerResults.Errors.Count, correctionResult.Errors.Count); Assert.AreEqual(compilerResults.Errors[0].ErrorText, correctionResult.Errors[0]); Assert.AreEqual(compilerResults.Errors[compilerResults.Errors.Count - 1].ErrorText, correctionResult.Errors[correctionResult.Errors.Count - 1]); }
public void CheckAnswer_CompileSourceCode() { var mockCompilationService = MockRepository.GenerateMock <CompilationService>(); mockCompilationService.Stub(s => s.CompileSourceCode(Arg <string> .Is.Anything)).Return( MockRepository.GenerateStub <CompilerResults>(new TempFileCollection())); var stubTestsRunnerService = MockRepository.GenerateStub <RunnerService>(); var stubQuestion = MockRepository.GenerateStub <Question>(); stubQuestion.SourceCode = "answerSourceCode"; var correctionProcess = new CorrectionProcess(mockCompilationService, stubTestsRunnerService); correctionProcess.CheckAnswer(stubQuestion); mockCompilationService.AssertWasCalled(m => m.CompileSourceCode(stubQuestion.SourceCode)); }
public void CheckAnswer_RunSourceCode() { var mockRunnerService = MockRepository.GenerateMock <RunnerService>(); var stubQuestion = MockRepository.GenerateStub <Question>(); var stubCompilationService = MockRepository.GenerateMock <CompilationService>(); var stubAssembly = Assembly.GetCallingAssembly(); var stubCompilerResults = MockRepository.GenerateStub <CompilerResults>(new TempFileCollection()); stubCompilerResults.CompiledAssembly = stubAssembly; stubCompilationService.Stub(s => s.CompileSourceCode(stubQuestion.SourceCode)).Return( stubCompilerResults); var correctionProcess = new CorrectionProcess(stubCompilationService, mockRunnerService); correctionProcess.CheckAnswer(stubQuestion); mockRunnerService.AssertWasCalled(m => m.RunMethod(stubAssembly, stubQuestion)); }
public ActionResult Resolve(ViewQuestion viewQuestion) { Question questionWithAnswer = _viewQuestionMapper.GetQuestion(viewQuestion); var correctionResult = _correctionProcess.CheckAnswer(questionWithAnswer); if (correctionResult.HasErrors()) { foreach (var error in correctionResult.Errors) { ModelState.AddModelError("", error); } } else { return(RedirectToAction("Result")); } return(View(viewQuestion)); }