From 74260a8fb877dcb86dec50ead7afcfb2d5b798f0 Mon Sep 17 00:00:00 2001 From: Senn Geerts Date: Sat, 13 Jul 2024 21:41:02 +0200 Subject: [PATCH] #196 permission issue? --- .../ToFile/StreamProvider.cs | 16 +------------- .../IntegrationTests.cs | 22 +++++++++---------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/StreamProvider.cs b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/StreamProvider.cs index 19583e6..7ada619 100644 --- a/src/AsyncAPI.Saunter.Generator.Cli/ToFile/StreamProvider.cs +++ b/src/AsyncAPI.Saunter.Generator.Cli/ToFile/StreamProvider.cs @@ -16,21 +16,7 @@ public Stream GetStreamFor(string path) if (!string.IsNullOrEmpty(path)) { - var directory = new DirectoryInfo(Path.GetDirectoryName(path)); - var sw = Stopwatch.StartNew(); - do - { - try - { - directory.Create(); - } - catch (Exception e) when (sw.Elapsed < TimeSpan.FromMilliseconds(250)) - { - logger.LogDebug(e, $"Retry... {directory.Parent.Exists}, {directory.Parent.Parent.Exists}, {directory.Parent.Parent.Parent.Exists}"); - Thread.Sleep(100); - } - } - while (!directory.Exists); + Directory.CreateDirectory(Path.GetDirectoryName(path)); } return path != null ? File.Create(path) : Console.OpenStandardOutput(); diff --git a/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs b/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs index 0f35280..c607991 100644 --- a/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs +++ b/test/AsyncAPI.Saunter.Generator.Cli.Tests/IntegrationTests.cs @@ -60,26 +60,26 @@ Retrieves AsyncAPI spec from a startup assembly and writes to file. [InlineData("StreetlightsAPI.TopLevelStatement", "net8.0")] public void Streetlights_ExportSpecTest(string csprojName, string targetFramework) { - var path = Path.Combine(Directory.GetCurrentDirectory(), csprojName, "specs"); + var path = Path.Combine(Directory.GetCurrentDirectory()); output.WriteLine($"Output path: {path}"); - var stdOut = RunTool($"tofile ../../../../../examples/{csprojName}/bin/Debug/{targetFramework}/{csprojName}.dll --output {path} --format json,yml,yaml"); + var stdOut = RunTool($"tofile ../../../../../examples/{csprojName}/bin/Debug/{targetFramework}/{csprojName}.dll --output {path} --filename {csprojName}.{{extension}} --format json,yml,yaml"); stdOut.ShouldNotBeEmpty(); - stdOut.ShouldContain($"AsyncAPI yaml successfully written to {Path.Combine(path, "asyncapi.yaml")}"); - stdOut.ShouldContain($"AsyncAPI yml successfully written to {Path.Combine(path, "asyncapi.yml")}"); - stdOut.ShouldContain($"AsyncAPI json successfully written to {Path.Combine(path, "asyncapi.json")}"); + stdOut.ShouldContain($"AsyncAPI yaml successfully written to {Path.Combine(path, $"{csprojName}.yaml")}"); + stdOut.ShouldContain($"AsyncAPI yml successfully written to {Path.Combine(path, $"{csprojName}.yml")}"); + stdOut.ShouldContain($"AsyncAPI json successfully written to {Path.Combine(path, $"{csprojName}.json")}"); - File.Exists(Path.Combine(path, "asyncapi.yml")).ShouldBeTrue("asyncapi.yml"); - File.Exists(Path.Combine(path, "asyncapi.yaml")).ShouldBeTrue("asyncapi.yaml"); - File.Exists(Path.Combine(path, "asyncapi.json")).ShouldBeTrue("asyncapi.json"); + File.Exists(Path.Combine(path, $"{csprojName}.yml")).ShouldBeTrue(); + File.Exists(Path.Combine(path, $"{csprojName}.yaml")).ShouldBeTrue(); + File.Exists(Path.Combine(path, $"{csprojName}.json")).ShouldBeTrue(); - var yml = File.ReadAllText(Path.Combine(path, "asyncapi.yml")); + var yml = File.ReadAllText(Path.Combine(path, $"{csprojName}.yml")); yml.ShouldBe(ExpectedSpecFiles.Yml_v2_6, "yml"); - var yaml = File.ReadAllText(Path.Combine(path, "asyncapi.yaml")); + var yaml = File.ReadAllText(Path.Combine(path, $"{csprojName}.yaml")); yaml.ShouldBe(yml, "yaml"); - var json = File.ReadAllText(Path.Combine(path, "asyncapi.json")); + var json = File.ReadAllText(Path.Combine(path, $"{csprojName}.json")); json.ShouldBe(ExpectedSpecFiles.Json_v2_6, "json"); } }