Ejemplo n.º 1
0
        public virtual CorrectionResult CheckAnswer(Question question)
        {
            CompilerResults compiledSourceCode = _compilationService.CompileSourceCode(question.SourceCode);

            if (compiledSourceCode.Errors.HasErrors)
            {
                var correctionResult = new CorrectionResult();
                foreach (CompilerError compilationError in compiledSourceCode.Errors)
                {
                    correctionResult.Errors.Add(compilationError.ErrorText);
                }
                return(correctionResult);
            }
            return(_runnerService.RunMethod(compiledSourceCode.CompiledAssembly, question));
        }
Ejemplo n.º 2
0
        public void RunMethod_RunSourceCodeAndReturnTheResult()
        {
            const string sourceCode   = "public class stubClass{ public int stubMethod(){ return 1; }}";
            var          stubQuestion = new Question(new Definition {
                ClassName = "stubClass", MethodName = "stubMethod"
            })
            {
                SourceCode = sourceCode
            };
            var             compilationService = new CompilationService();
            CompilerResults compilerResults    = compilationService.CompileSourceCode(stubQuestion.SourceCode);

            var runnerService = new RunnerService();
            var result        = runnerService.RunMethod(compilerResults.CompiledAssembly, stubQuestion);

            Assert.AreEqual("1", result.Result);
        }