forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary comments contain improperly escaped backslashes (Issue Azure#…
…1152) (Azure#1176) * removing escaping of backslashes in comments. * Adding unit test project for CSharp generator * making MemoryFileSystem IDisposable to support test parallelization better * search for tools better * added csharp unit tests to .sln * regenerated expected acceptance test files * Adjusted namespace
- Loading branch information
1 parent
61d1467
commit 74917b9
Showing
16 changed files
with
376 additions
and
8 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Text.RegularExpressions; | ||
using Xunit; | ||
|
||
namespace Microsoft.Rest.Generator.CSharp.UnitTest | ||
{ | ||
public class Bug1152 : BugTest | ||
{ | ||
/// <summary> | ||
/// https://github.com/Azure/autorest/issues/1152 | ||
/// | ||
/// The C# code generator seems to needlessly escape backslashes when generating /// | ||
/// </summary> | ||
[Fact] | ||
public void SummaryCommentsContainImproperlyEscapedBackslashes() | ||
{ | ||
// simplified test pattern for unit testing aspects of code generation | ||
using (var fileSystem = "Bug1152.yaml".GenerateCodeInto(CreateMockFilesystem())) | ||
{ | ||
Assert.True(fileSystem.FileExists(@"GeneratedCode\Models\TestObject.cs")); | ||
var testObject = fileSystem.ReadFileAsText(@"GeneratedCode\Models\TestObject.cs"); | ||
|
||
Assert.DoesNotContain(@"\\\\" , Regex.Match(testObject, "Default is.*").Value); | ||
} | ||
} | ||
} | ||
} |
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,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.Rest.Generator.CSharp.UnitTest | ||
{ | ||
public class Bug1161 : BugTest | ||
{ | ||
[Fact] | ||
public void DoubleQuestionMarksWhenUsingEnumsInAnArray() | ||
{ | ||
using (var fileSystem = "Bug1161.yaml".GenerateCodeInto(CreateMockFilesystem())) | ||
{ | ||
Assert.True(fileSystem.FileExists(@"GeneratedCode\Models\RecurrenceSchedule.cs")); | ||
|
||
var recurrenceSchedule = fileSystem.ReadFileAsText(@"GeneratedCode\Models\RecurrenceSchedule.cs"); | ||
Assert.NotNull(recurrenceSchedule); | ||
|
||
|
||
} | ||
} | ||
} | ||
} |
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,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using Microsoft.Rest.Generator.Logging; | ||
using Microsoft.Rest.Generator.Utilities; | ||
|
||
namespace Microsoft.Rest.Generator.CSharp.UnitTest | ||
{ | ||
public class BugTest | ||
{ | ||
public BugTest() | ||
{ | ||
Logger.Entries.Clear(); | ||
} | ||
|
||
protected MemoryFileSystem CreateMockFilesystem() | ||
{ | ||
var fs = new MemoryFileSystem(); | ||
fs.Copy(Path.Combine("Resource", "AutoRest.json")); | ||
return fs; | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
AutoRest/Generators/CSharp/CSharp.Unit.Tests/CSharp.Unit.Tests.csproj
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,86 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="TurnOffCodeAnalysis"> | ||
<Import Project="$(SolutionDir)\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('$(SolutionDir)\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" /> | ||
<Import Project="$(SolutionDir)\packages\xunit.runner.msbuild.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.props" Condition="Exists('$(SolutionDir)\packages\xunit.runner.msbuild.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.props')" /> | ||
<Import Project="$(SolutionDir)\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props" Condition="Exists('$(SolutionDir)\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" /> | ||
<PropertyGroup> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<LibraryFxTarget Condition="'$(LibraryFxTarget)' == ''">net45</LibraryFxTarget> | ||
<ProductVersion>10.0.0</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>Microsoft.Rest.Generator.CSharp.UnitTest</RootNamespace> | ||
<AssemblyName>AutoRest.Csharp.Unit.Tests</AssemblyName> | ||
<RestorePackages>true</RestorePackages> | ||
<AutoRestTest>true</AutoRestTest> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Net45-Debug</Configuration> | ||
</PropertyGroup> | ||
<Import Project="$(SolutionDir)\Tools\AutoRest.Settings.targets" /> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Net45-Debug|AnyCPU' "> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Net45-Debug</OutputPath> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="xunit.abstractions"> | ||
<HintPath>$(SolutionDir)\packages\xunit.abstractions.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.abstractions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>$(SolutionDir)\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>$(SolutionDir)\packages\xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>$(SolutionDir)\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Bug1161.cs" /> | ||
<Compile Include="Bug1152.cs" /> | ||
<Compile Include="BugTest.cs" /> | ||
<Compile Include="TestExtensions.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(SolutionDir)\autorest\AutoRest.Core\AutoRest.Core.csproj"> | ||
<Project>{c876085f-9dc3-41f0-b7b4-17022cd84684}</Project> | ||
<Name>AutoRest.Core</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\CSharp\AutoRest.Generator.CSharp.csproj"> | ||
<Project>{cc1eec95-41ef-44b6-8761-00fa3e647248}</Project> | ||
<Name>AutoRest.Generator.CSharp</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
<None Include="Resource\Bug1152.yaml"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Include="Resource\AutoRest.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Include="Resource\Bug1161.yaml"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('$(SolutionDir)\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props'))" /> | ||
<Error Condition="!Exists('$(SolutionDir)\packages\xunit.runner.msbuild.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\xunit.runner.msbuild.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.props'))" /> | ||
<Error Condition="!Exists('$(SolutionDir)\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" /> | ||
</Target> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
24 changes: 24 additions & 0 deletions
24
AutoRest/Generators/CSharp/CSharp.Unit.Tests/Resource/AutoRest.json
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,24 @@ | ||
{ | ||
"codeGenerators": { | ||
"Angular": { | ||
"type": "JavaScriptAngularCodeGenerator, AutoRest.Generator.JavaScript.Angular" | ||
}, | ||
"CSharp": { | ||
"type": "CSharpCodeGenerator, AutoRest.Generator.CSharp" | ||
}, | ||
"NodeJS": { | ||
"type": "NodeJSCodeGenerator, AutoRest.Generator.NodeJS", | ||
"settings": { | ||
"disableTypeScriptGeneration": true | ||
} | ||
} | ||
}, | ||
"modelers": { | ||
"Swagger": { | ||
"type": "SwaggerModeler, AutoRest.Modeler.Swagger" | ||
}, | ||
"CompositeSwagger": { | ||
"type": "CompositeSwaggerModeler, AutoRest.Modeler.CompositeSwagger" | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
AutoRest/Generators/CSharp/CSharp.Unit.Tests/Resource/Bug1152.yaml
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,20 @@ | ||
swagger: '2.0' | ||
info: | ||
version: 1.0.0 | ||
title: Simple API | ||
paths: | ||
/: | ||
get: | ||
operationId: my_operation | ||
responses: | ||
200: | ||
description: OK | ||
schema: | ||
$ref: '#/definitions/TestObject' | ||
definitions: | ||
TestObject: | ||
properties: | ||
pattern: | ||
type: string | ||
default: '\w+' | ||
description: 'A regular expression pattern to match token separators. Default is "\W+".' |
77 changes: 77 additions & 0 deletions
77
AutoRest/Generators/CSharp/CSharp.Unit.Tests/Resource/Bug1161.yaml
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,77 @@ | ||
swagger: '2.0' | ||
info: | ||
version: 1.0.0 | ||
title: Simple API | ||
paths: | ||
/getday: | ||
get: | ||
operationId: getday | ||
responses: | ||
200: | ||
description: OK | ||
schema: | ||
$ref: '#/definitions/SomethingWithADay' | ||
/: | ||
get: | ||
operationId: myoperation | ||
responses: | ||
200: | ||
description: OK | ||
schema: | ||
$ref: '#/definitions/testObject' | ||
|
||
/getSchedule: | ||
get: | ||
operationId: getschedule | ||
responses: | ||
200: | ||
description: OK | ||
schema: | ||
$ref: '#/definitions/RecurrenceSchedule' | ||
|
||
definitions: | ||
|
||
DayOfWeek: | ||
type: string | ||
enum: | ||
- Sunday | ||
- Monday | ||
- Tuesday | ||
- Wednesday | ||
- Thursday | ||
- Friday | ||
- Saturday | ||
x-ms-enum: | ||
name: DayOfWeek | ||
modelAsString: false | ||
|
||
SomethingWithADay: | ||
type: object | ||
properties: | ||
theDay : | ||
type: array | ||
$ref: '#/definitions/DayOfWeek' | ||
anotherday: | ||
type: array | ||
$ref: '#/definitions/DayOfWeek' | ||
|
||
testObject: | ||
properties: | ||
pattern: | ||
type: string | ||
default: '\w+' | ||
description: 'A regular expression pattern to match token separators. Default is "\W+".' | ||
|
||
RecurrenceSchedule: | ||
type: object | ||
properties: | ||
weekDays : | ||
type: array | ||
items: | ||
$ref: '#/definitions/DayOfWeek' | ||
otherweekDays : | ||
type: array | ||
items: | ||
$ref: '#/definitions/DayOfWeek' | ||
|
||
|
Oops, something went wrong.