Skip to content

Commit

Permalink
Summary comments contain improperly escaped backslashes (Issue Azure#…
Browse files Browse the repository at this point in the history
…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
fearthecowboy authored Jun 16, 2016
1 parent 61d1467 commit 74917b9
Show file tree
Hide file tree
Showing 16 changed files with 376 additions and 8 deletions.
15 changes: 15 additions & 0 deletions AutoRest.sln
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CSharp.Tests", "AutoRest\Ge
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Azure.CSharp.Tests", "AutoRest\Generators\CSharp\Azure.CSharp.Tests\Azure.CSharp.Tests.xproj", "{43DFEF27-2FD7-4827-A669-DFD2DD1CBBCC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharp.Unit.Tests", "AutoRest\Generators\CSharp\CSharp.Unit.Tests\CSharp.Unit.Tests.csproj", "{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -518,6 +520,18 @@ Global
{43DFEF27-2FD7-4827-A669-DFD2DD1CBBCC}.Portable-Release|Any CPU.Build.0 = Release|Any CPU
{43DFEF27-2FD7-4827-A669-DFD2DD1CBBCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43DFEF27-2FD7-4827-A669-DFD2DD1CBBCC}.Release|Any CPU.Build.0 = Release|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096}.Release|Any CPU.Build.0 = Portable-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -562,5 +576,6 @@ Global
{1C3B4A33-E045-4C8F-9202-1B651A686567} = {B6A1FC1E-0779-4900-84EE-262DD0E53FF4}
{784D4B45-F12A-4B8F-A86C-35A080814A19} = {03E75B1D-A443-4A12-B31F-860DB2B45140}
{43DFEF27-2FD7-4827-A669-DFD2DD1CBBCC} = {03E75B1D-A443-4A12-B31F-860DB2B45140}
{8192BAA3-C606-4D44-B0D7-46BE7AFA4096} = {03E75B1D-A443-4A12-B31F-860DB2B45140}
EndGlobalSection
EndGlobal
3 changes: 0 additions & 3 deletions AutoRest/AutoRest.Core/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ protected virtual string WrapComment(string prefix, string comment)
return null;
}

// escape comment as needed
comment = comment.Replace("\\", Resources.CommentString);

int available =
MaximumCommentColumn - // Maximum desired width
Indentation.Length - // - Space used for indent
Expand Down
16 changes: 15 additions & 1 deletion AutoRest/AutoRest.Core/Utilities/MemoryFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Microsoft.Rest.Generator.Utilities
{
// TODO: MemoryFileSystem is for testing. Consider moving to test project.
public class MemoryFileSystem : IFileSystem
public class MemoryFileSystem : IFileSystem, IDisposable
{
private const string FolderKey = "Folder";

Expand Down Expand Up @@ -177,5 +177,19 @@ private static string WildcardToRegex(string wildcard)
}
return sb.ToString().ToLowerInvariant();
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_virtualStore?.Clear();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public partial class AutoRestValidationTest : ServiceClient<AutoRestValidationTe
public string SubscriptionId { get; set; }

/// <summary>
/// Required string following pattern \\\\d{2}-\\\\d{2}-\\\\d{4}
/// Required string following pattern \d{2}-\d{2}-\d{4}
/// </summary>
public string ApiVersion { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public partial interface IAutoRestValidationTest : IDisposable
string SubscriptionId { get; set; }

/// <summary>
/// Required string following pattern \\\\d{2}-\\\\d{2}-\\\\d{4}
/// Required string following pattern \d{2}-\d{2}-\d{4}
/// </summary>
string ApiVersion { get; set; }

Expand Down
26 changes: 26 additions & 0 deletions AutoRest/Generators/CSharp/CSharp.Unit.Tests/Bug1152.cs
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);
}
}
}
}
24 changes: 24 additions & 0 deletions AutoRest/Generators/CSharp/CSharp.Unit.Tests/Bug1161.cs
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);


}
}
}
}
24 changes: 24 additions & 0 deletions AutoRest/Generators/CSharp/CSharp.Unit.Tests/BugTest.cs
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;
}
}
}
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>
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 AutoRest/Generators/CSharp/CSharp.Unit.Tests/Resource/Bug1152.yaml
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 AutoRest/Generators/CSharp/CSharp.Unit.Tests/Resource/Bug1161.yaml
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'


Loading

0 comments on commit 74917b9

Please sign in to comment.