public async Task ExecutesGeneratorTarget_WithOutputPath() { var project = new TemporaryOpenApiProject("test", _temporaryDirectory, "Microsoft.NET.Sdk") .WithTargetFrameworks(_targetFramework) .WithItem(new TemporaryOpenApiProject.ItemSpec { Include = "files/azureMonitor.json", OutputPath = "Custom.cs" }); _temporaryDirectory.WithCSharpProject(project); project.Create(); using var process = await RunBuild(); Assert.Equal(0, process.ExitCode); Assert.Empty(process.Error); // Note OutputPath also overrides ClassName. Assert.Contains( "GenerateNSwagCSharp " + $"{Path.Combine(_temporaryDirectory.Root, "files", "azureMonitor.json")} " + "Class: 'test.Custom' FirstForGenerator: 'true' " + $"Options: '' OutputPath: '{Path.Combine("obj", "Custom.cs")}'", process.Output); }
public async Task ExecutesGeneratorTarget_WithMultipleGenerators() { var project = new TemporaryOpenApiProject("test", _temporaryDirectory, "Microsoft.NET.Sdk") .WithTargetFrameworks(_targetFramework) .WithItem(new TemporaryOpenApiProject.ItemSpec { Include = "files/azureMonitor.json", }) .WithItem(new TemporaryOpenApiProject.ItemSpec { Include = "files/azureMonitor.json", CodeGenerator = "NSwagTypeScript" }); _temporaryDirectory.WithCSharpProject(project); project.Create(); using var process = await RunBuild(); Assert.Equal(0, process.ExitCode); Assert.Empty(process.Error); Assert.Contains( "GenerateNSwagCSharp " + $"{Path.Combine(_temporaryDirectory.Root, "files", "azureMonitor.json")} " + "Class: 'test.azureMonitorClient' FirstForGenerator: 'true' " + $"Options: '' OutputPath: '{Path.Combine("obj", "azureMonitorClient.cs")}'", process.Output); Assert.Contains( "GenerateNSwagTypeScript " + $"{Path.Combine(_temporaryDirectory.Root, "files", "azureMonitor.json")} " + "Class: 'test.azureMonitorClient' FirstForGenerator: 'true' " + $"Options: '' OutputPath: '{Path.Combine("obj", "azureMonitorClient.ts")}'", process.Output); }
public async Task AddsExpectedItems_WithMultipleFilesFromGenerator() { var project = new TemporaryOpenApiProject("test", _temporaryDirectory, "Microsoft.NET.Sdk") .WithTargetFrameworks(_targetFramework) .WithItem(new TemporaryOpenApiProject.ItemSpec { Include = "files/azureMonitor.json", CodeGenerator = "CustomCSharp", }); _temporaryDirectory.WithCSharpProject(project); project.Create(); using var process = await RunBuild(); Assert.Equal(0, process.ExitCode); Assert.Empty(process.Error); Assert.Contains($"Compile: {Path.Combine("obj", "azureMonitorClient.cs", "Generated1.cs")}", process.Output); Assert.Contains($"Compile: {Path.Combine("obj", "azureMonitorClient.cs", "Generated2.cs")}", process.Output); Assert.Contains( $"FileWrites: {Path.Combine("obj", "azureMonitorClient.cs", "Generated1.cs")}", process.Output); Assert.Contains( $"FileWrites: {Path.Combine("obj", "azureMonitorClient.cs", "Generated2.cs")}", process.Output); Assert.DoesNotContain("TypeScriptCompile:", process.Output); }
public async Task SkipsGeneratorTarget_WithOpenApiGenerateCodeOnBuild() { var project = new TemporaryOpenApiProject("test", _temporaryDirectory, "Microsoft.NET.Sdk") .WithTargetFrameworks(_targetFramework) .WithProperty("OpenApiGenerateCodeOnBuild", "false") .WithItem(new TemporaryOpenApiProject.ItemSpec { Include = "files/azureMonitor.json", }); _temporaryDirectory.WithCSharpProject(project); project.Create(); using var process = await RunBuild(); Assert.Equal(0, process.ExitCode); Assert.Empty(process.Error); Assert.DoesNotContain("GenerateNSwagCSharp ", process.Output); }
public async Task SkipsGeneratorTarget_InSubsequentBuilds() { // Arrange var project = new TemporaryOpenApiProject("test", _temporaryDirectory, "Microsoft.NET.Sdk") .WithTargetFrameworks(_targetFramework) .WithProperty("OpenApiGenerateCodeOnBuild", "false") .WithItem(new TemporaryOpenApiProject.ItemSpec { Include = "files/azureMonitor.json", }); _temporaryDirectory.WithCSharpProject(project); project.Create(); // Act 1 using var firstProcess = await RunBuild(); // Assert 1 aka Guards Assert.Equal(0, firstProcess.ExitCode); Assert.Empty(firstProcess.Error); // Act 2 using var secondProcess = await RunBuild(); // Assert 2 Assert.Equal(0, secondProcess.ExitCode); Assert.Empty(secondProcess.Error); Assert.DoesNotContain("GenerateNSwagCSharp ", secondProcess.Output); // Act 3 using var thirdProcess = await RunBuild(); // Assert 2 Assert.Equal(0, thirdProcess.ExitCode); Assert.Empty(thirdProcess.Error); Assert.DoesNotContain("GenerateNSwagCSharp ", thirdProcess.Output); }