From bc04ebed94ea8036cb3bef86835dc482a57e5778 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 11 Jun 2016 23:44:48 +0800 Subject: [PATCH] add mono script to nunit test csharp client --- .gitignore | 1 + .../languages/CSharpClientCodegen.java | 2 ++ .../main/resources/csharp/api_test.mustache | 8 +++--- .../resources/csharp/compile-mono.sh.mustache | 5 ++++ .../main/resources/csharp/model_test.mustache | 8 ++++-- .../resources/csharp/mono_nunit_test.mustache | 28 +++++++++++++++++++ .../resources/csharp/packages.config.mustache | 2 +- .../csharp/packages_test.config.mustache | 4 +-- .../csharp/SwaggerClient/IO.Swagger.sln | 10 +++---- .../petstore/csharp/SwaggerClient/README.md | 14 +++++----- .../petstore/csharp/SwaggerClient/build.sh | 5 ++++ .../csharp/SwaggerClient/mono_nunit_test.sh | 25 +++++++++++++++++ .../IO.Swagger.Test/IO.Swagger.Test.csproj | 2 +- .../src/IO.Swagger/IO.Swagger.csproj | 2 +- 14 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/csharp/mono_nunit_test.mustache create mode 100644 samples/client/petstore/csharp/SwaggerClient/mono_nunit_test.sh diff --git a/.gitignore b/.gitignore index 5eba3895f59..3118eafbcfd 100644 --- a/.gitignore +++ b/.gitignore @@ -112,6 +112,7 @@ samples/client/petstore/csharp/SwaggerClient/bin samples/client/petstore/csharp/SwaggerClient/obj/Debug/ samples/client/petstore/csharp/SwaggerClient/bin/Debug/ samples/client/petstore/csharp/SwaggerClient/packages +samples/client/petstore/csharp/SwaggerClient/TestResult.xml # Python *.pyc diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index 7546d89e968..ef3baedd78e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -238,6 +238,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen { supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat")); supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh")); + // shell script to run the nunit test + supportingFiles.add(new SupportingFile("mono_nunit_test.mustache", "", "mono_nunit_test.sh")); // copy package.config to nuget's standard location for project-level installs supportingFiles.add(new SupportingFile("packages.config.mustache", packageFolder + File.separator, "packages.config")); diff --git a/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache b/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache index cc487fb681e..84904b8c08b 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache @@ -61,12 +61,12 @@ namespace {{packageName}}.Test [Test] public void {{operationId}}Test() { - // TODO: add unit test for the method '{{operationId}}' + // TODO uncomment below to test the method '{{operationId}}' {{#allParams}} - {{{dataType}}} {{paramName}} = null; // TODO: replace null with proper value + //{{{dataType}}} {{paramName}} = null; // TODO: replace null with proper value {{/allParams}} - {{#returnType}}var response = {{/returnType}}instance.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - {{#returnType}}Assert.IsInstanceOf<{{{returnType}}}> (response, "response is {{{returnType}}}");{{/returnType}} + //{{#returnType}}var response = {{/returnType}}instance.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{#returnType}}//Assert.IsInstanceOf<{{{returnType}}}> (response, "response is {{{returnType}}}");{{/returnType}} } {{/operation}}{{/operations}} } diff --git a/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache b/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache index f93437eb0c8..2d3e96b9677 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache @@ -2,14 +2,19 @@ frameworkVersion={{targetFrameworkNuget}} netfx=${frameworkVersion#net} +echo "[INFO] Target framework: ${frameworkVersion}" + +echo "[INFO] Download nuget and packages" wget -nc https://nuget.org/nuget.exe; mozroots --import --sync mono nuget.exe install src/{{packageName}}/packages.config -o packages; mkdir -p bin; +echo "[INFO] Copy DLLs to the 'bin' folder" cp packages/Newtonsoft.Json.8.0.2/lib/{{targetFrameworkNuget}}/Newtonsoft.Json.dll bin/Newtonsoft.Json.dll; cp packages/RestSharp.105.1.0/lib/{{targetFrameworkNuget}}/RestSharp.dll bin/RestSharp.dll; +echo "[INFO] Run 'mcs' to build bin/{{{packageName}}}.dll" mcs -sdk:${netfx} -r:bin/Newtonsoft.Json.dll,\ bin/RestSharp.dll,\ System.Runtime.Serialization.dll \ diff --git a/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache b/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache index f9dd3c08efc..6fcc4672b32 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache @@ -33,7 +33,8 @@ namespace {{packageName}}.Test [SetUp] public void Init() { - instance = new {{classname}}(); + // TODO uncomment below to create an instance of {{classname}} + //instance = new {{classname}}(); } /// @@ -51,7 +52,8 @@ namespace {{packageName}}.Test [Test] public void {{classname}}InstanceTest() { - Assert.IsInstanceOf<{{classname}}> (instance, "instance is a {{classname}}"); + // TODO uncomment below to test "IsInstanceOf" {{classname}} + //Assert.IsInstanceOf<{{classname}}> (instance, "variable 'instance' is a {{classname}}"); } {{#vars}} @@ -61,7 +63,7 @@ namespace {{packageName}}.Test [Test] public void {{name}}Test() { - // TODO: unit test for the property '{{name}}' + // TODO unit test for the property '{{name}}' } {{/vars}} diff --git a/modules/swagger-codegen/src/main/resources/csharp/mono_nunit_test.mustache b/modules/swagger-codegen/src/main/resources/csharp/mono_nunit_test.mustache new file mode 100644 index 00000000000..33b960ac82b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/csharp/mono_nunit_test.mustache @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +wget -nc https://nuget.org/nuget.exe +mozroots --import --sync + +echo "[INFO] remove bin/Debug/SwaggerClientTest.dll" +rm src/IO.Swagger.Test/bin/Debug/{{{packageName}}}.Test.dll 2> /dev/null + +echo "[INFO] install NUnit runners via NuGet" +wget -nc https://nuget.org/nuget.exe +mozroots --import --sync +mono nuget.exe install src/{{{packageName}}}.Test/packages.config -o packages + +echo "[INFO] Copy DLLs to the 'bin' folder" +# for project {{{packageName}}} +cp packages/Newtonsoft.Json.8.0.3/lib/{{targetFrameworkNuget}}/Newtonsoft.Json.dll src/{{{packageName}}}/bin/Debug/Newtonsoft.Json.dll +cp packages/RestSharp.105.1.0/lib/{{targetFrameworkNuget}}/RestSharp.dll src/{{{packageName}}}/bin/Debug/RestSharp.dll +cp packages/NUnit.2.6.4/lib/nunit.framework.dll src/{{{packageName}}}/bin/Debug/nunit.framework.dll +# for project {{{packageName}}}.Test +cp packages/Newtonsoft.Json.8.0.3/lib/{{targetFrameworkNuget}}/Newtonsoft.Json.dll src/{{{packageName}}}.Test/bin/Debug/Newtonsoft.Json.dll +cp packages/RestSharp.105.1.0/lib/{{targetFrameworkNuget}}/RestSharp.dll src/{{{packageName}}}.Test/bin/Debug/RestSharp.dll +cp packages/NUnit.2.6.4/lib/nunit.framework.dll src/{{{packageName}}}.Test/bin/Debug/nunit.framework.dll + +echo "[INFO] Install NUnit runners via NuGet" +mono nuget.exe install NUnit.Runners -Version 2.6.4 -OutputDirectory packages + +echo "[INFO] build the solution and run the unit test" +xbuild {{{packageName}}}.sln && \ + mono ./packages/NUnit.Runners.2.6.4/tools/nunit-console.exe src/{{{packageName}}}.Test/bin/debug/{{{packageName}}}.Test.dll diff --git a/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache b/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache index bd4428e687e..d9e5dea7d9f 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/packages.config.mustache @@ -1,5 +1,5 @@ - + diff --git a/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache b/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache index 5464714bcef..7e6f4575391 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/packages_test.config.mustache @@ -1,6 +1,6 @@ - + - + diff --git a/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln b/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln index 740ca6561ac..dc645198f38 100644 --- a/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln +++ b/samples/client/petstore/csharp/SwaggerClient/IO.Swagger.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{EE727567-9CAF-4258-AA0E-FDF89487D7D6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{7B057377-44BA-47A5-AC6B-70EEB6034E6F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger.Test", "src\IO.Swagger.Test\IO.Swagger.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}" EndProject @@ -12,10 +12,10 @@ Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Debug|Any CPU.Build.0 = Debug|Any CPU -{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Release|Any CPU.ActiveCfg = Release|Any CPU -{EE727567-9CAF-4258-AA0E-FDF89487D7D6}.Release|Any CPU.Build.0 = Release|Any CPU +{7B057377-44BA-47A5-AC6B-70EEB6034E6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{7B057377-44BA-47A5-AC6B-70EEB6034E6F}.Debug|Any CPU.Build.0 = Debug|Any CPU +{7B057377-44BA-47A5-AC6B-70EEB6034E6F}.Release|Any CPU.ActiveCfg = Release|Any CPU +{7B057377-44BA-47A5-AC6B-70EEB6034E6F}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/samples/client/petstore/csharp/SwaggerClient/README.md b/samples/client/petstore/csharp/SwaggerClient/README.md index c94e740d7b3..38d36d71493 100644 --- a/samples/client/petstore/csharp/SwaggerClient/README.md +++ b/samples/client/petstore/csharp/SwaggerClient/README.md @@ -6,7 +6,7 @@ This C# SDK is automatically generated by the [Swagger Codegen](https://github.c - API version: 1.0.0 - SDK version: 1.0.0 -- Build date: 2016-06-10T08:07:39.769-04:00 +- Build date: 2016-06-11T23:10:58.942+08:00 - Build package: class io.swagger.codegen.languages.CSharpClientCodegen ## Frameworks supported @@ -138,6 +138,12 @@ Class | Method | HTTP request | Description ## Documentation for Authorization +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ### petstore_auth - **Type**: OAuth @@ -147,9 +153,3 @@ Class | Method | HTTP request | Description - write:pets: modify pets in your account - read:pets: read your pets -### api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - diff --git a/samples/client/petstore/csharp/SwaggerClient/build.sh b/samples/client/petstore/csharp/SwaggerClient/build.sh index 159673fd60c..88180f68398 100644 --- a/samples/client/petstore/csharp/SwaggerClient/build.sh +++ b/samples/client/petstore/csharp/SwaggerClient/build.sh @@ -2,14 +2,19 @@ frameworkVersion=net45 netfx=${frameworkVersion#net} +echo "[INFO] Target framework: ${frameworkVersion}" + +echo "[INFO] Download nuget and packages" wget -nc https://nuget.org/nuget.exe; mozroots --import --sync mono nuget.exe install src/IO.Swagger/packages.config -o packages; mkdir -p bin; +echo "[INFO] Copy DLLs to the 'bin' folder" cp packages/Newtonsoft.Json.8.0.2/lib/net45/Newtonsoft.Json.dll bin/Newtonsoft.Json.dll; cp packages/RestSharp.105.1.0/lib/net45/RestSharp.dll bin/RestSharp.dll; +echo "[INFO] Run 'mcs' to build bin/IO.Swagger.dll" mcs -sdk:${netfx} -r:bin/Newtonsoft.Json.dll,\ bin/RestSharp.dll,\ System.Runtime.Serialization.dll \ diff --git a/samples/client/petstore/csharp/SwaggerClient/mono_nunit_test.sh b/samples/client/petstore/csharp/SwaggerClient/mono_nunit_test.sh new file mode 100644 index 00000000000..e2be7882f39 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClient/mono_nunit_test.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +wget -nc https://nuget.org/nuget.exe; +mozroots --import --sync + +echo "[INFO] remove bin/Debug/SwaggerClientTest.dll" +rm src/IO.Swagger.Test/bin/Debug/IO.Swagger.Test.dll 2> /dev/null + +echo "[INFO] install NUnit runners via NuGet" +wget -nc https://nuget.org/nuget.exe; +mozroots --import --sync +mono nuget.exe install src/IO.Swagger.Test/packages.config -o packages; + +echo "[INFO] Copy DLLs to the 'bin' folder" +# for project IO.Swagger +cp packages/Newtonsoft.Json.8.0.2/lib/net45/Newtonsoft.Json.dll src/IO.Swagger/bin/Debug/Newtonsoft.Json.dll +cp packages/RestSharp.105.1.0/lib/net45/RestSharp.dll src/IO.Swagger/bin/Debug/RestSharp.dll +cp packages/NUnit.2.6.3/lib/nunit.framework.dll src/IO.Swagger/bin/Debug/nunit.framework.dll +# for project IO.Swagger.Test +cp packages/Newtonsoft.Json.8.0.2/lib/net45/Newtonsoft.Json.dll src/IO.Swagger.Test/bin/Debug/Newtonsoft.Json.dll +cp packages/RestSharp.105.1.0/lib/net45/RestSharp.dll src/IO.Swagger.Test/bin/Debug/RestSharp.dll +cp packages/NUnit.2.6.3/lib/nunit.framework.dll src/IO.Swagger.Test/bin/Debug/nunit.framework.dll + +echo "[INFO] build the solution and run the unit test" +xbuild IO.Swagger.sln && \ + mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe src/IO.Swagger.Test/bin/debug/IO.Swagger.Test.dll diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj index 2cc0dd9525c..2ba51f5afa6 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger.Test/IO.Swagger.Test.csproj @@ -86,7 +86,7 @@ limitations under the License. - {EE727567-9CAF-4258-AA0E-FDF89487D7D6} + {7B057377-44BA-47A5-AC6B-70EEB6034E6F} IO.Swagger diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj index a484b5b5026..9164a6b3fb0 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj @@ -24,7 +24,7 @@ limitations under the License. Debug AnyCPU - {EE727567-9CAF-4258-AA0E-FDF89487D7D6} + {7B057377-44BA-47A5-AC6B-70EEB6034E6F} Library Properties Swagger Library