/// <summary> /// The compile and run tests in other domain. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompileAndRunResponse"/>. /// </returns> /// <exception cref="FaultException">Unhandled exception /// </exception> public CompileAndRunResponse CompileAndRunTestsInOtherDomain(CompileAndRunRequest request) { Trace.WriteLine(AppDomain.CurrentDomain.FriendlyName); var compileResponse = this.Compile(request); if (!string.IsNullOrEmpty(compileResponse.CompileResult.Error)) { return(new CompileAndRunResponse { CompileResult = compileResponse.CompileResult }); } this.CreateDomainAndUnwrapObject(compileResponse.CompileResult.LoadedStream, compileResponse.CompileResult.AssemblyFileName); // Ready to run the tests. CoreExtensions.Host.InstallBuiltins(); // run the test in safe mode so that service doesn't go in faulted state. try { var runnerResult = new InMemoryNunitTestRunner().RunTests( new TestRunRequest { TestAssembly = Assembly.Load(CsharpRulesAssemblyName) }); return(new CompileAndRunResponse { TestResult = runnerResult, CompileResult = new CompileResult() }); } catch (Exception exception) { // Throw the unhandled exception as fault throw new FaultException(exception.Message); } }
public void Run() { StringBuilder sb = new StringBuilder(); sb.Append("using CodeRank.CSharpProblems.Ruleset.Base;"); sb.Append("namespace CodeRank.CSharpProblems.Ruleset.Solution"); sb.Append("{"); sb.Append("public class SampleTestRuleSolution : ISampleTest"); sb.Append("{"); sb.Append("public int Sum(int a, int b)"); sb.Append("{"); sb.Append("return a + b;"); sb.Append("}"); sb.Append("}"); sb.Append("}"); CompilerEngine engine = new CompilerEngine(); var response = engine.Compile(new CompileArgs { SourceCode = sb.ToString() }); string pathToDlls = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); var assemblyFilePath = Path.Combine(pathToDlls, response.AssemblyFileName); Console.WriteLine(AppDomain.CurrentDomain.FriendlyName); AppDomain.CurrentDomain.Load(response.LoadedStream.ToArray()); CoreExtensions.Host.InstallBuiltins(); var runner = new InMemoryNunitTestRunner().RunTests(new TestRunRequest { TestAssembly = Assembly.Load("CodeRank.CSharpProblems.Ruleset"), SourceAssemblyStream = response.LoadedStream }); Console.WriteLine(runner); Console.Read(); }