diff --git a/CSharpInteractive.Tests/UsageScenarios/CommandLineAsyncScenario.cs b/CSharpInteractive.Tests/UsageScenarios/CommandLineAsyncScenario.cs index 377b2a0e..c1b1a72a 100644 --- a/CSharpInteractive.Tests/UsageScenarios/CommandLineAsyncScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/CommandLineAsyncScenario.cs @@ -35,6 +35,6 @@ await GetService() .EnsureSuccess(); // } - result.ExitCode.HasValue.ShouldBeTrue(); + result.ExitCode.HasValue.ShouldBeTrue(result.ToString()); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/CommandLineInParallelScenario.cs b/CSharpInteractive.Tests/UsageScenarios/CommandLineInParallelScenario.cs index 04f3abcf..3f10e242 100644 --- a/CSharpInteractive.Tests/UsageScenarios/CommandLineInParallelScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/CommandLineInParallelScenario.cs @@ -36,7 +36,7 @@ public async Task Run() await task; // } - task.Result.ExitCode.HasValue.ShouldBeTrue(); - result.ExitCode.HasValue.ShouldBeTrue(); + task.Result.ExitCode.HasValue.ShouldBeTrue(result.ToString()); + result.ExitCode.HasValue.ShouldBeTrue(result.ToString()); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/CommandLineOutputScenario.cs b/CSharpInteractive.Tests/UsageScenarios/CommandLineOutputScenario.cs index 3dd3cf6d..27b24e85 100644 --- a/CSharpInteractive.Tests/UsageScenarios/CommandLineOutputScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/CommandLineOutputScenario.cs @@ -33,6 +33,6 @@ public void Run() lines.ShouldContain("MyEnv=MyVal"); // } - result.ExitCode.HasValue.ShouldBeTrue(); + result.ExitCode.HasValue.ShouldBeTrue(result.ToString()); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/CommandLineWithTimeoutScenario.cs b/CSharpInteractive.Tests/UsageScenarios/CommandLineWithTimeoutScenario.cs index 7608f255..76fd402b 100644 --- a/CSharpInteractive.Tests/UsageScenarios/CommandLineWithTimeoutScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/CommandLineWithTimeoutScenario.cs @@ -30,8 +30,8 @@ public void Run() .Run(default, TimeSpan.FromMilliseconds(1)) .EnsureSuccess() .ExitCode; - - exitCode.HasValue.ShouldBeFalse(); // } + + exitCode.HasValue.ShouldBeFalse(exitCode.ToString()); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DockerDotNetBuildScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DockerDotNetBuildScenario.cs index 55345370..a91a501c 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DockerDotNetBuildScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DockerDotNetBuildScenario.cs @@ -49,12 +49,12 @@ public void Run() .Build() .EnsureSuccess(); - // The "result" variable provides details about a build - result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(); - result.ExitCode.ShouldBe(0); - string ToAbsoluteLinuxPath(string path) => "/" + path.Replace(":", "").Replace('\\', '/'); // } + + // The "result" variable provides details about a build + result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(result.ToString()); + result.ExitCode.ShouldBe(0, result.ToString()); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetBuildScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetBuildScenario.cs index c2f53d87..afea731f 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetBuildScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetBuildScenario.cs @@ -30,11 +30,13 @@ public void Run() .Build().EnsureSuccess(); // Builds the library project, running a command like: "dotnet build" from the directory "MyLib" + var messages = new List(); var result = new DotNetBuild() .WithWorkingDirectory("MyLib") - .Build().EnsureSuccess(); + .Build(message => messages.Add(message)).EnsureSuccess(); // The "result" variable provides details about a build + messages.Count.ShouldBeGreaterThan(0, result.ToString()); result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(); result.ExitCode.ShouldBe(0); @@ -43,10 +45,10 @@ public void Run() .WithWorkingDirectory("MyLib") .Build() .EnsureSuccess(); - + // } + result.ExitCode.ShouldBe(0); result.Summary.Tests.ShouldBe(1); result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); - // } } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetCsiScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetCsiScenario.cs new file mode 100644 index 00000000..3f532373 --- /dev/null +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetCsiScenario.cs @@ -0,0 +1,42 @@ +// ReSharper disable StringLiteralTypo +// ReSharper disable ObjectCreationAsStatement +// ReSharper disable ReturnValueOfPureMethodIsNotUsed + +namespace CSharpInteractive.Tests.UsageScenarios; + +using System.Diagnostics.CodeAnalysis; +using HostApi; + +[CollectionDefinition("Integration", DisableParallelization = true)] +[Trait("Integration", "True")] +[SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] +public class DotNetCsiScenario : BaseScenario +{ + [Fact] + public void Run() + { + // $visible=true + // $tag=07 .NET CLI + // $priority=02 + // $description=Run C# script + // { + // Adds the namespace "HostApi" to use .NET build API + // ## using HostApi; + + var script = Path.GetTempFileName(); + File.WriteAllText(script, "Console.WriteLine($\"Hello, {Args[0]}!\");"); + + var stdOut = new List(); + var result = new DotNetCsi() + .WithScript(script) + .AddArgs("World") + .Build(message => stdOut.Add(message.Text)) + .EnsureSuccess(); + + result.ExitCode.ShouldBe(0); + + // Checks StdOut + stdOut.Contains("Hello, World!").ShouldBeTrue(result.ToString()); + // } + } +} \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetPackScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetPackScenario.cs index 92b4ebbe..1d15ef17 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetPackScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetPackScenario.cs @@ -36,8 +36,8 @@ public void Run() .WithWorkingDirectory("MyLib") .AddProps(("version", "1.2.3")) .Build().EnsureSuccess(); - - result.ExitCode.ShouldBe(0); // } + + result.ExitCode.ShouldBe(0, result.ToString()); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetPublishScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetPublishScenario.cs index e9fc34c6..1d7d6de5 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetPublishScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetPublishScenario.cs @@ -37,8 +37,8 @@ public void Run() .WithWorkingDirectory("MyLib") .WithFramework("net8.0") .Build().EnsureSuccess(); - - result.ExitCode.ShouldBe(0); // } + + result.ExitCode.ShouldBe(0); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetRestoreScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetRestoreScenario.cs index 92699e35..8abd7d5d 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetRestoreScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetRestoreScenario.cs @@ -35,8 +35,8 @@ public void Run() result = new DotNetRestore() .WithWorkingDirectory("MyLib") .Build().EnsureSuccess(); - - result.ExitCode.ShouldBe(0); // } + + result.ExitCode.ShouldBe(0); } } \ No newline at end of file diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetRunScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetRunScenario.cs index dae0388d..6b3bf6b0 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetRunScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetRunScenario.cs @@ -34,7 +34,8 @@ public void Run() // Runs the console project using a command like: "dotnet run" from the directory "MyApp" var stdOut = new List(); - result = new DotNetRun().WithWorkingDirectory("MyApp") + result = new DotNetRun() + .WithWorkingDirectory("MyApp") .Build(message => stdOut.Add(message.Text)) .EnsureSuccess(); diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetTestScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetTestScenario.cs index 16d5b287..9af90e14 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetTestScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetTestScenario.cs @@ -37,9 +37,9 @@ public void Run() .EnsureSuccess(); // The "result" variable provides details about a build - result.ExitCode.ShouldBe(0); - result.Summary.Tests.ShouldBe(1); - result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); + result.ExitCode.ShouldBe(0, result.ToString()); + result.Summary.Tests.ShouldBe(1, result.ToString()); + result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1, result.ToString()); // } } diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetTestWithDotCoverScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetTestWithDotCoverScenario.cs index 4fe0a4da..b7ff88aa 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetTestWithDotCoverScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetTestWithDotCoverScenario.cs @@ -60,8 +60,8 @@ public void Run() .Build().EnsureSuccess(); // The "result" variable provides details about a build - result.ExitCode.ShouldBe(0); - result.Tests.Count(i => i.State == TestState.Finished).ShouldBe(1); + result.ExitCode.ShouldBe(0, result.ToString()); + result.Tests.Count(i => i.State == TestState.Finished).ShouldBe(1, result.ToString()); // Generates a HTML code coverage report. new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReport}", "--reportType=HTML") diff --git a/CSharpInteractive.Tests/UsageScenarios/DotNetVSTestScenario.cs b/CSharpInteractive.Tests/UsageScenarios/DotNetVSTestScenario.cs index bfa3da0f..db0dc6e4 100644 --- a/CSharpInteractive.Tests/UsageScenarios/DotNetVSTestScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/DotNetVSTestScenario.cs @@ -29,7 +29,7 @@ public void Run() .WithForce(true) .Build().EnsureSuccess(); - result.ExitCode.ShouldBe(0); + result.ExitCode.ShouldBe(0, result.ToString()); // Builds the test project, running a command like: "dotnet build -c Release" from the directory "MyTests" result = new DotNetBuild() @@ -38,7 +38,7 @@ public void Run() .WithOutput("MyOutput") .Build().EnsureSuccess(); - result.ExitCode.ShouldBe(0); + result.ExitCode.ShouldBe(0, result.ToString()); // Runs tests via a command like: "dotnet vstest" from the directory "MyTests" result = new VSTest() @@ -47,9 +47,9 @@ public void Run() .Build().EnsureSuccess(); // The "result" variable provides details about a build - result.ExitCode.ShouldBe(0); - result.Summary.Tests.ShouldBe(1); - result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); + result.ExitCode.ShouldBe(0, result.ToString()); + result.Summary.Tests.ShouldBe(1, result.ToString()); + result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1, result.ToString()); // } } diff --git a/CSharpInteractive.Tests/UsageScenarios/MSBuildScenario.cs b/CSharpInteractive.Tests/UsageScenarios/MSBuildScenario.cs index 9ab3f9f4..e4c64a1f 100644 --- a/CSharpInteractive.Tests/UsageScenarios/MSBuildScenario.cs +++ b/CSharpInteractive.Tests/UsageScenarios/MSBuildScenario.cs @@ -30,7 +30,7 @@ public void Run() .WithForce(true) .Build().EnsureSuccess(); - result.ExitCode.ShouldBe(0); + result.ExitCode.ShouldBe(0, result.ToString()); // Builds the library project, running a command like: "dotnet msbuild /t:Build -restore /p:configuration=Release -verbosity=detailed" from the directory "MyLib" result = new MSBuild() @@ -42,8 +42,8 @@ public void Run() .Build().EnsureSuccess(); // The "result" variable provides details about a build - result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(); - result.ExitCode.ShouldBe(0); + result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(result.ToString()); + result.ExitCode.ShouldBe(0, result.ToString()); // } } } \ No newline at end of file