Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions test/Swashbuckle.AspNetCore.Cli.Test/ToolTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text;
using System.Text.Json;
using Swashbuckle.AspNetCore.TestSupport.Utilities;
using Xunit;
Expand Down Expand Up @@ -131,10 +132,32 @@ public static void Does_Not_Run_Crashing_HostedService()
Assert.True(path.TryGetProperty("get", out _));
}

private static JsonDocument RunApplication(Func<string, string[]> setup)
[Fact]
public static void Creates_New_Folder_Path()
{
using var document = RunApplication(outputPath =>
[
"tofile",
"--output",
outputPath,
"--serializeasv2",
Path.Combine(Directory.GetCurrentDirectory(), "Basic.dll"),
"v1"
], GenerateRandomString(5));

// verify one of the endpoints
var paths = document.RootElement.GetProperty("paths");
var productsPath = paths.GetProperty("/products");
Assert.True(productsPath.TryGetProperty("post", out _));
}

private static JsonDocument RunApplication(Func<string, string[]> setup, string subOutputPath = default)
{
using var temporaryDirectory = new TemporaryDirectory();
string outputPath = Path.Combine(temporaryDirectory.Path, "swagger.json");

var outputPath = !string.IsNullOrEmpty(subOutputPath)
? Path.Combine(temporaryDirectory.Path, subOutputPath, "swagger.json")
: Path.Combine(temporaryDirectory.Path, "swagger.json");

string[] args = setup(outputPath);

Expand All @@ -143,5 +166,20 @@ private static JsonDocument RunApplication(Func<string, string[]> setup)
string json = File.ReadAllText(outputPath);
return JsonDocument.Parse(json);
}

private static string GenerateRandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder result = new StringBuilder(length);
Random random = new Random();

for (int i = 0; i < length; i++)
{
result.Append(chars[random.Next(chars.Length)]);
}

return result.ToString();
}

}
}