Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 8 additions & 39 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public static IAnyPlugin GetPlugin(string name)
{
switch (name)
{
case "CSharp": return new AutoRest.CSharp.PluginCs();
case "Azure.CSharp": return new AutoRest.CSharp.Azure.PluginCsa();
case "Azure.CSharp.Fluent": return new AutoRest.CSharp.Azure.Fluent.PluginCsaf();
case "Azure.JsonRpcClient": return new AutoRest.CSharp.Azure.JsonRpcClient.PluginCsa();
case "csharp": return new AutoRest.CSharp.PluginCs();
case "Azure.csharp": return new AutoRest.CSharp.Azure.PluginCsa();
case "Azure.csharp.Fluent": return new AutoRest.CSharp.Azure.Fluent.PluginCsaf();
case "Azure.jsonrpcclient": return new AutoRest.CSharp.Azure.JsonRpcClient.PluginCsa();
}
throw new Exception("Unknown plugin: " + name);
}
Expand All @@ -34,7 +34,7 @@ public static int Main(string[] args )
{
if(args != null && args.Length > 0 && args[0] == "--server") {
var connection = new Connection(Console.Out, Console.OpenStandardInput());
connection.Dispatch<IEnumerable<string>>("GetPluginNames", async () => new []{ "csharp", "csharp-simplifier" });
connection.Dispatch<IEnumerable<string>>("GetPluginNames", async () => new []{ "jsonrpcclient", "csharp", "csharp-simplifier" });
connection.Dispatch<string, string, bool>("Process", (plugin, sessionId) => new Program(connection, plugin, sessionId).Process());
connection.DispatchNotification("Shutdown", connection.Stop);

Expand Down Expand Up @@ -98,8 +98,6 @@ protected override async Task<bool> ProcessInternal()
}
else
{
var codeGenerator = this.plugin;

var files = await ListInputs();
if (files.Length != 1)
{
Expand All @@ -108,20 +106,6 @@ protected override async Task<bool> ProcessInternal()
var modelAsJson = (await ReadFile(files[0])).EnsureYamlIsJson();
var codeModelT = new ModelSerializer<CodeModel>().Load(modelAsJson);

// get internal name
var language = new[] {
"CSharp",
"Ruby",
"NodeJS",
"Python",
"Go",
"Php",
"Java",
"AzureResourceSchema",
"JsonRpcClient" }
.Where(x => x.ToLowerInvariant() == codeGenerator)
.First();

// build settings
var altNamespace = (await GetValue<string[]>("input-file") ?? new[] { "" }).FirstOrDefault()?.Split('/').Last().Split('\\').Last().Split('.').First();

Expand All @@ -142,30 +126,15 @@ protected override async Task<bool> ProcessInternal()
Settings.Instance.CustomSettings.Add("SyncMethods", GetXmsCodeGenSetting<string>(codeModelT, "syncMethods") ?? await GetValue("sync-methods") ?? "essential");
Settings.Instance.CustomSettings.Add("UseDateTimeOffset", GetXmsCodeGenSetting<bool?>(codeModelT, "useDateTimeOffset") ?? await GetValue<bool?>("use-datetimeoffset") ?? false);
Settings.Instance.CustomSettings["ClientSideValidation"] = await GetValue<bool?>("client-side-validation") ?? false;
int defaultMaximumCommentColumns = codeGenerator == "go" ? 120 : Settings.DefaultMaximumCommentColumns;
int defaultMaximumCommentColumns = Settings.DefaultMaximumCommentColumns;
Settings.Instance.MaximumCommentColumns = await GetValue<int?>("max-comment-columns") ?? defaultMaximumCommentColumns;
Settings.Instance.OutputFileName = await GetValue<string>("output-file");
if (codeGenerator == "csharp")
{
Settings.Instance.Header = $"<auto-generated>\n{Settings.Instance.Header}\n</auto-generated>";
}
if (codeGenerator == "ruby" || codeGenerator == "python")
{
// TODO: sort out matters here entirely instead of relying on Input being read somewhere...
var inputFile = await GetValue<string[]>("input-file");
Settings.Instance.Input = inputFile.FirstOrDefault();
Settings.Instance.PackageName = await GetValue("package-name");
Settings.Instance.PackageVersion = await GetValue("package-version");
}
if (codeGenerator == "go")
{
Settings.Instance.PackageVersion = await GetValue("package-version");
}
Settings.Instance.Header = $"<auto-generated>\n{Settings.Instance.Header}\n</auto-generated>";

// process
var plugin = ExtensionsLoader.GetPlugin(
(await GetValue<bool?>("azure-arm") ?? false ? "Azure." : "") +
language +
this.plugin +
(await GetValue<bool?>("fluent") ?? false ? ".Fluent" : "") +
(await GetValue<bool?>("testgen") ?? false ? ".TestGen" : ""));
Settings.PopulateSettings(plugin.Settings, Settings.Instance.CustomSettings);
Expand Down
4 changes: 2 additions & 2 deletions src/autorest.csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-Perks.CodeGen" Version="1.0.16" />
<PackageReference Include="dotnet-Perks.CodeGen" Version="1.0.16">
<DotNetCliToolReference Include="dotnet-Perks.CodeGen" Version="2.0.1" />
<PackageReference Include="dotnet-Perks.CodeGen" Version="2.0.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/azure/CSharpAzureCodeNamingFrameworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void ConvertsPageResultsToPageTypeTest()
var input = Path.Combine(Core.Utilities.Extensions.CodeBaseDirectory(typeof(CSharpAzureCodeNamingFrameworkTests)), "Resource", "azure-paging.json");
var modeler = new SwaggerModeler();
var codeModel = modeler.Build(SwaggerParser.Parse(File.ReadAllText(input)));
var plugin = new PluginCsa();
var plugin = new AutoRest.CSharp.Azure.PluginCsa();
using (plugin.Activate()) {
codeModel = plugin.Serializer.Load(codeModel);
codeModel = plugin.Transformer.TransformCodeModel(codeModel);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug1560.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task MarkAllDeprecatedOperationVariantsObsolete()
[Fact]
public async Task MarkAllDeprecatedOperationVariantsObsoleteAzure()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
Assert.True(fileSystem.FileExists(@"Models\ResultObject.cs"));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug1587.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Bug1587(ITestOutputHelper output) : base(output)
[Fact]
public async Task CheckLruCodegenBehavior()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
Assert.True(fileSystem.FileExists(@"SimpleAPIClient.cs"));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug1623.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Bug1623(ITestOutputHelper output) : base(output)
[Fact]
public async Task CheckForCorrectParameterType()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
Assert.True(fileSystem.FileExists(@"Models\Page.cs"));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug1664.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Bug1664(ITestOutputHelper output) : base(output)
public async Task EnsureClientNameEndsWithClient()
{
// simplified test pattern for unit testing aspects of code generation
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
Assert.True(fileSystem.FileExists(@"SimpleAPIClient.cs"));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug1720.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Bug1720(ITestOutputHelper output) : base(output)
[Fact]
public async Task PolymorphicTypesAreNotConstants()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
Assert.True(fileSystem.FileExists(@"JobDefinitionsOperations.cs"));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug1806.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Bug1806(ITestOutputHelper output) : base(output)
public async Task EmptyDefaultResponseExceptionHandling()
{
// simplified test pattern for unit testing aspects of code generation
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// check for the expected class.
Assert.True(fileSystem.FileExists(@"ContainerServicesOperations.cs"));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug2039.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Bug2039(ITestOutputHelper output) : base(output)
[Fact]
public void CircularReferenceBreaksIsConstant()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// if we reach this, apparently no stack overflow has happened :-)
Assert.True(fileSystem.FileExists(@"Models\Node.cs"));
Expand Down
1 change: 0 additions & 1 deletion test/unit/Bug470.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public async Task SupportModelsNameOverride()

var settings = new Settings
{
CodeGenerator = "CSharp",
OutputDirectory = "",
Namespace = "Test",
ModelsName = modelsName
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Bug781.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Bug781(ITestOutputHelper output) : base(output)
[Fact]
public async Task EnsureCustomInitMethodInConstructors()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
Assert.True(fileSystem.FileExists(@"Models\Product.cs"));
Expand Down
11 changes: 6 additions & 5 deletions test/unit/BugTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace AutoRest.CSharp.Unit.Tests {
using System.Runtime.Loader;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;


using IAnyPlugin = AutoRest.Core.Extensibility.IPlugin<AutoRest.Core.Extensibility.IGeneratorSettings, AutoRest.Core.IModelSerializer<AutoRest.Core.Model.CodeModel>, AutoRest.Core.ITransformer<AutoRest.Core.Model.CodeModel>, AutoRest.Core.CodeGenerator, AutoRest.Core.CodeNamer, AutoRest.Core.Model.CodeModel>;

public class BugTest {
internal static string[] SuppressWarnings = {"CS1701","CS1702", "CS1591"};
Expand All @@ -46,13 +47,13 @@ public BugTest() {

protected virtual MemoryFileSystem CreateMockFilesystem() => new MemoryFileSystem();

protected virtual MemoryFileSystem GenerateCodeForTestFromSpec(string codeGenerator = "CSharp") {
return GenerateCodeForTestFromSpec($"{GetType().Name}", codeGenerator);
protected virtual MemoryFileSystem GenerateCodeForTestFromSpec(IAnyPlugin plugin = null) {
return GenerateCodeForTestFromSpec($"{GetType().Name}", plugin);
}

protected virtual MemoryFileSystem GenerateCodeForTestFromSpec(string dirName, string codeGenerator = "CSharp") {
protected virtual MemoryFileSystem GenerateCodeForTestFromSpec(string dirName, IAnyPlugin plugin = null) {
var fs = CreateMockFilesystem();
return dirName.GenerateCodeInto(fs, codeGenerator);
return dirName.GenerateCodeInto(fs, plugin ?? new PluginCs());
}

protected virtual void WriteLine(string format, params object[] values) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/NullableParamBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task NullableParams()
[Fact]
public async Task NullableParamsAzure()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
// Expected Files
string generatedCodeFileName = "TestOperations.cs";
Expand Down
1 change: 0 additions & 1 deletion test/unit/ServerCodeSimpleGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public async Task CompileAndVerifyServerCode()

var settings = new Settings
{
CodeGenerator = "CSharp",
FileSystemInput = fileSystem,
OutputDirectory = "",
Namespace = "Test",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/SharedResponseHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SharedResponseHeaders(ITestOutputHelper output) : base(output)
[Fact]
public async Task CheckGeneratesValidCSharp()
{
using (var fileSystem = GenerateCodeForTestFromSpec(codeGenerator: "Azure.CSharp"))
using (var fileSystem = GenerateCodeForTestFromSpec(new AutoRest.CSharp.Azure.PluginCsa()))
{
Assert.True(fileSystem.FileExists("Models/RetryHeader.cs"));
Assert.False(fileSystem.FileExists("Models/BatchAccountCreateHeaders.cs"));
Expand Down
11 changes: 6 additions & 5 deletions test/unit/TestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using AutoRest.Swagger;
using AutoRest.Modeler;

using IAnyPlugin = AutoRest.Core.Extensibility.IPlugin<AutoRest.Core.Extensibility.IGeneratorSettings, AutoRest.Core.IModelSerializer<AutoRest.Core.Model.CodeModel>, AutoRest.Core.ITransformer<AutoRest.Core.Model.CodeModel>, AutoRest.Core.CodeGenerator, AutoRest.Core.CodeNamer, AutoRest.Core.Model.CodeModel>;

namespace AutoRest.CSharp.Unit.Tests
{
internal static class TestExtensions
Expand Down Expand Up @@ -60,25 +62,25 @@ internal static string[] GetFilesByExtension(this MemoryFileSystem fileSystem, s
return fileSystem.GetFiles(path, "*.*", s).Where(f => fileExts.Contains(f.Substring(f.LastIndexOf(".")+1))).ToArray();
}

internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem inputFileSystem, string codeGenerator="CSharp")
internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem inputFileSystem, IAnyPlugin plugin = null)
{
using (NewContext)
{
var settings = new Settings
{
CodeGenerator = codeGenerator,
FileSystemInput = inputFileSystem,
OutputDirectory = "",
Namespace = "Test",
CodeGenerationMode = "rest-client"
};

return testName.GenerateCodeInto(inputFileSystem, settings);
return testName.GenerateCodeInto(inputFileSystem, settings, plugin);
}
}

internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem inputFileSystem, Settings settings)
internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem inputFileSystem, Settings settings, IAnyPlugin plugin = null)
{
plugin = plugin ?? new PluginCs();
Settings.Instance.FileSystemInput = inputFileSystem;
// copy the whole input directory into the memoryfilesystem.
inputFileSystem.CopyFolder("Resource", testName,"");
Expand All @@ -95,7 +97,6 @@ internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFi
throw new Exception($"Can't find swagger file ${testName} [.yaml] [.json] [.md]");
}

var plugin = ExtensionsLoader.GetPlugin(settings.CodeGenerator);
var modeler = new SwaggerModeler(Settings.Instance);
var swagger = Singleton<AutoRest.Modeler.Model.ServiceDefinition>.Instance = SwaggerParser.Parse(inputFileSystem.ReadAllText(Settings.Instance.Input));
var codeModel = modeler.Build(swagger);
Expand Down