forked from asyncapi/saunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asyncapi#196 add unitTests for tofile
- Loading branch information
Senn Geerts
authored and
Senn Geerts
committed
Jul 11, 2024
1 parent
240c9ed
commit e181850
Showing
20 changed files
with
754 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project> | ||
<ItemGroup> | ||
<!-- Make it possible for NSubstitube to make substitues of internal classes --> | ||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" /> | ||
|
||
<!-- Make project internals visible to their respective .Tests project --> | ||
<InternalsVisibleTo Include="$(AssemblyName).Tests" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/AsyncAPI.Saunter.Generator.Cli/ToFile/StreamProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace AsyncAPI.Saunter.Generator.Cli.ToFile; | ||
|
||
internal interface IStreamProvider | ||
{ | ||
Stream GetStreamFor(string path); | ||
} | ||
|
||
internal class StreamProvider : IStreamProvider | ||
{ | ||
public Stream GetStreamFor(string path) | ||
{ | ||
if (!string.IsNullOrEmpty(path)) | ||
{ | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
} | ||
|
||
return path != null ? File.Create(path) : Console.OpenStandardOutput(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Diagnostics; | ||
using Shouldly; | ||
using Xunit.Abstractions; | ||
|
||
namespace AsyncAPI.Saunter.Generator.Cli.Tests; | ||
|
||
public class E2ETests(ITestOutputHelper output) | ||
{ | ||
private string Run(string file, string args, string workingDirectory, int expectedExitCode = 0) | ||
{ | ||
var process = Process.Start(new ProcessStartInfo(file) | ||
{ | ||
Arguments = args, | ||
WorkingDirectory = workingDirectory, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false, | ||
}); | ||
process.WaitForExit(TimeSpan.FromSeconds(20)); | ||
var stdOut = process.StandardOutput.ReadToEnd().Trim(); | ||
var stdError = process.StandardError.ReadToEnd().Trim(); | ||
output.WriteLine($"### Output of \"{file} {args}\""); | ||
output.WriteLine(stdOut); | ||
output.WriteLine(stdError); | ||
|
||
process.ExitCode.ShouldBe(expectedExitCode); | ||
return stdOut; | ||
} | ||
|
||
[Fact(Skip = "Manual verification only")] | ||
public void Pack_Install_Run_Uninstall_Test() | ||
{ | ||
var workingDirectory = "../../../../../src/AsyncAPI.Saunter.Generator.Cli"; | ||
var stdOut = this.Run("dotnet", "pack", workingDirectory); | ||
stdOut.ShouldContain("Successfully created package"); | ||
|
||
// use --force flag to ensure the test starts clean every run | ||
stdOut = this.Run("dotnet", "new tool-manifest --force", workingDirectory); | ||
stdOut.ShouldContain("The template \"Dotnet local tool manifest file\" was created successfully"); | ||
|
||
stdOut = this.Run("dotnet", "tool install --local --add-source ./bin/Release AsyncAPI.Saunter.Generator.Cli", workingDirectory); | ||
stdOut = stdOut.Replace("Skipping NuGet package signature verification.", "").Trim(); | ||
stdOut.ShouldContain("You can invoke the tool from this directory using the following commands: 'dotnet tool run dotnet-asyncapi"); | ||
stdOut.ShouldContain("was successfully installed."); | ||
|
||
stdOut = this.Run("dotnet", "tool list --local asyncapi.saunter.generator.cli", workingDirectory); | ||
stdOut.ShouldContain("dotnet-asyncapi"); | ||
|
||
stdOut = this.Run("dotnet", "tool run dotnet-asyncapi", workingDirectory, 1); | ||
stdOut.ShouldContain("tofile: retrieves AsyncAPI from a startup assembly, and writes to file"); | ||
|
||
stdOut = this.Run("dotnet", "tool uninstall --local asyncapi.saunter.generator.cli", workingDirectory); | ||
stdOut.ShouldContain(" was successfully uninstalled"); | ||
stdOut.ShouldContain("removed from manifest file"); | ||
|
||
stdOut = this.Run("dotnet", "tool list --local asyncapi.saunter.generator.cli", workingDirectory, 1); | ||
stdOut.ShouldNotContain("dotnet-asyncapi"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
test/AsyncAPI.Saunter.Generator.Cli.Tests/PackAndInstallLocalTests.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.