public static TestRun Run(string directory, string slug = "Fake") { var testSolution = new TestSolution(slug, directory); RunTestRunner(testSolution); return(CreateTestRun(testSolution)); }
private static TestRun CreateTestRun(TestSolution solution) { var actualTestRunResult = TestRunResultReader.ReadActual(solution); var expectedTestRunResult = TestRunResultReader.ReadExpected(solution); return(new TestRun(expectedTestRunResult, actualTestRunResult)); }
private static string ReadTestRunResult(TestSolution solution, string fileName) { var testRunResult = DeserializeTestRunResult(solution, fileName); NormalizeTestRunResult(testRunResult); return(JsonSerializer.Serialize(testRunResult, CreateJsonSerializerOptions())); }
private static void RunTestRunner(TestSolution testSolution) { if (Options.UseDocker) { RunTestRunnerUsingDocker(testSolution); } else { RunTestRunnerWithoutDocker(testSolution); } }
public static TestRun Run(TestSolution testSolution) { RunSolutionTestScript(testSolution); return(CreateTestRun(testSolution)); }
private static void RunSolutionTestScript(TestSolution testSolution) => Process.Start("pwsh", $"{DirectoryHelper.FindFileInTree("run.ps1")} {testSolution.Slug} {testSolution.Directory} {testSolution.Directory}")?.WaitForExit();
private static void RunTestRunnerWithoutDocker(TestSolution testSolution) => Program.Main(new[] { testSolution.Slug, testSolution.DirectoryFullPath, testSolution.DirectoryFullPath });
private static void RunTestRunnerUsingDocker(TestSolution testSolution) => Process.Start("docker", $"run -v {testSolution.DirectoryFullPath}:/solution -v {testSolution.DirectoryFullPath}:/results exercism/csharp-test-runner {testSolution.Slug} /solution /results") !.WaitForExit();
public void SolutionIsTestedCorrectly(TestSolution solution) { var testRun = TestSolutionRunner.Run(solution); Assert.Equal(testRun.Expected.NormalizeJson(), testRun.Actual.NormalizeJson()); }
public static string ReadExpected(TestSolution solution) => ReadFile(solution, "expected_results.json");
public static string ReadActual(TestSolution solution) => ReadFile(solution, "results.json");
private static string ReadFile(TestSolution solution, string fileName) => File.ReadAllText(Path.Combine(solution.Directory, fileName));
public static string ReadActual(TestSolution solution) => ReadTestRunResult(solution, "results.json");
private static TestRunResult DeserializeTestRunResult(TestSolution solution, string fileName) => JsonSerializer.Deserialize <TestRunResult>(ReadFile(solution, fileName), CreateJsonSerializerOptions());