private ManagedCompilationResult Compile(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) { var compiler = _factory.CreateCompiler(sandbox, metadataProvider); var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray(); var assemblyName = metadataProvider.GetAssemblyName(); var references = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory); var resources = sandbox.ResourceFiles.ToArray(); var inputAssemblyPath = compiler.CompileTestIn(sandbox.InputDirectory, assemblyName, sourceFiles, references, null, resources); references = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory); var expectationsAssemblyPath = compiler.CompileTestIn(sandbox.ExpectationsDirectory, assemblyName, sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }, resources); return(new ManagedCompilationResult(inputAssemblyPath, expectationsAssemblyPath)); }
private ManagedCompilationResult Compile(TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider) { var inputCompiler = _factory.CreateCompiler(sandbox, metadataProvider); var expectationsCompiler = _factory.CreateCompiler(sandbox, metadataProvider); var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray(); var assemblyName = metadataProvider.GetAssemblyName(); var commonReferences = metadataProvider.GetCommonReferencedAssemblies(sandbox.InputDirectory).ToArray(); var mainAssemblyReferences = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory).ToArray(); var resources = sandbox.ResourceFiles.ToArray(); var additionalArguments = metadataProvider.GetSetupCompilerArguments().ToArray(); var expectationsCommonReferences = metadataProvider.GetCommonReferencedAssemblies(sandbox.ExpectationsDirectory).ToArray(); var expectationsMainAssemblyReferences = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory).ToArray(); var inputTask = Task.Run(() => inputCompiler.CompileTestIn(sandbox.InputDirectory, assemblyName, sourceFiles, commonReferences, mainAssemblyReferences, null, resources, additionalArguments)); var expectationsTask = Task.Run(() => expectationsCompiler.CompileTestIn(sandbox.ExpectationsDirectory, assemblyName, sourceFiles, expectationsCommonReferences, expectationsMainAssemblyReferences, new[] { "INCLUDE_EXPECTATIONS" }, resources, additionalArguments)); NPath inputAssemblyPath = null; NPath expectationsAssemblyPath = null; try { inputAssemblyPath = GetResultOfTaskThatMakesNUnitAssertions(inputTask); expectationsAssemblyPath = GetResultOfTaskThatMakesNUnitAssertions(expectationsTask); } catch (Exception) { // If completing the input assembly task threw, we need to wait for the expectations task to complete before continuing // otherwise we could set the next test up for a race condition with the expectations compilation over access to the sandbox directory if (inputAssemblyPath == null && expectationsAssemblyPath == null) { try { expectationsTask.Wait(); } catch (Exception) { // Don't care, we want to throw the first exception } } throw; } return(new ManagedCompilationResult(inputAssemblyPath, expectationsAssemblyPath)); }