Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Oct 24, 2024
1 parent 66e63b4 commit 28cdd7a
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ await GetService<ICommandLineRunner>()
.EnsureSuccess();
// }

result.ExitCode.HasValue.ShouldBeTrue();
result.ExitCode.HasValue.ShouldBeTrue(result.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public void Run()
lines.ShouldContain("MyEnv=MyVal");
// }

result.ExitCode.HasValue.ShouldBeTrue();
result.ExitCode.HasValue.ShouldBeTrue(result.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public void Run()
.Run(default, TimeSpan.FromMilliseconds(1))
.EnsureSuccess()
.ExitCode;

exitCode.HasValue.ShouldBeFalse();
// }

exitCode.HasValue.ShouldBeFalse(exitCode.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
8 changes: 5 additions & 3 deletions CSharpInteractive.Tests/UsageScenarios/DotNetBuildScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildMessage>();
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);

Expand All @@ -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);
// }
}
}
42 changes: 42 additions & 0 deletions CSharpInteractive.Tests/UsageScenarios/DotNetCsiScenario.cs
Original file line number Diff line number Diff line change
@@ -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<string>();
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());
// }
}
}
4 changes: 2 additions & 2 deletions CSharpInteractive.Tests/UsageScenarios/DotNetPackScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void Run()
.WithWorkingDirectory("MyLib")
.WithFramework("net8.0")
.Build().EnsureSuccess();

result.ExitCode.ShouldBe(0);
// }

result.ExitCode.ShouldBe(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void Run()
result = new DotNetRestore()
.WithWorkingDirectory("MyLib")
.Build().EnsureSuccess();

result.ExitCode.ShouldBe(0);
// }

result.ExitCode.ShouldBe(0);
}
}
3 changes: 2 additions & 1 deletion CSharpInteractive.Tests/UsageScenarios/DotNetRunScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
result = new DotNetRun().WithWorkingDirectory("MyApp")
result = new DotNetRun()
.WithWorkingDirectory("MyApp")
.Build(message => stdOut.Add(message.Text))
.EnsureSuccess();

Expand Down
6 changes: 3 additions & 3 deletions CSharpInteractive.Tests/UsageScenarios/DotNetTestScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
// }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions CSharpInteractive.Tests/UsageScenarios/DotNetVSTestScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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());
// }
}

Expand Down
6 changes: 3 additions & 3 deletions CSharpInteractive.Tests/UsageScenarios/MSBuildScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
// }
}
}

0 comments on commit 28cdd7a

Please sign in to comment.