From 587615b6564c0bd96e4fcc830c94f2dbd0fed1a0 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 30 Jan 2016 23:06:45 +0800 Subject: [PATCH 1/4] update c# readme with command to generate DLL --- .../swagger-codegen/src/main/resources/csharp/README.md | 8 +++++++- .../csharp/SwaggerClientTest/Lib/SwaggerClient/README.md | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/csharp/README.md b/modules/swagger-codegen/src/main/resources/csharp/README.md index 0e6f969d37..3ce83da957 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/README.md +++ b/modules/swagger-codegen/src/main/resources/csharp/README.md @@ -10,5 +10,11 @@ NOTE: The DLLs included in the package may not be the latest version. We recommn ``` Install-Package RestSharp Install-Package Newtonsoft.Json -``` +``` +## Installation +Run the following command to generate the DLL +- [Mac/Linux] compile-mono.sh +- [Windows] compile.bat + +Then include the DLL (under the `bin` folder) in the C# project diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md index 0e6f969d37..8d71999564 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md @@ -11,4 +11,9 @@ NOTE: The DLLs included in the package may not be the latest version. We recommn Install-Package RestSharp Install-Package Newtonsoft.Json ``` +## Installation +Run the following command to generate the DLL +- [Mac/Linux] compile-mono.sh +- [Windows] compile.bat +Then include the DLL (under the `bin` folder) in the C# project From 4ce255dc38ed4dbc074fc5d4e106df19cdbe85c7 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 31 Jan 2016 01:52:41 +0800 Subject: [PATCH 2/4] add unit test files for C# --- .../languages/CSharpClientCodegen.java | 24 +++ .../main/resources/csharp/api_test.mustache | 61 ++++++++ .../main/resources/csharp/model_test.mustache | 63 ++++++++ .../Lib/SwaggerClient.Test/CategoryTests.cs | 68 +++++++++ .../Lib/SwaggerClient.Test/OrderTests.cs | 104 +++++++++++++ .../Lib/SwaggerClient.Test/PetApiTests.cs | 141 ++++++++++++++++++ .../Lib/SwaggerClient.Test/PetTests.cs | 104 +++++++++++++ .../Lib/SwaggerClient.Test/StoreApiTests.cs | 87 +++++++++++ .../Lib/SwaggerClient.Test/TagTests.cs | 68 +++++++++ .../Lib/SwaggerClient.Test/UserApiTests.cs | 123 +++++++++++++++ .../Lib/SwaggerClient.Test/UserTests.cs | 122 +++++++++++++++ .../Lib/SwaggerClient/README.md | 3 +- .../main/csharp/IO/Swagger/Model/Category.cs | 1 + .../src/main/csharp/IO/Swagger/Model/Order.cs | 1 + .../src/main/csharp/IO/Swagger/Model/Pet.cs | 1 + .../src/main/csharp/IO/Swagger/Model/Tag.cs | 1 + .../src/main/csharp/IO/Swagger/Model/User.cs | 1 + 17 files changed, 972 insertions(+), 1 deletion(-) create mode 100644 modules/swagger-codegen/src/main/resources/csharp/api_test.mustache create mode 100644 modules/swagger-codegen/src/main/resources/csharp/model_test.mustache create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs create mode 100644 samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs 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 7697bd5b02..991b60cd49 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 @@ -41,6 +41,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig protected String packageVersion = "1.0.0"; protected String clientPackage = "IO.Swagger.Client"; protected String sourceFolder = "src" + File.separator + "main" + File.separator + "csharp"; + protected String testFolder = "Test"; public CSharpClientCodegen() { super(); @@ -51,6 +52,9 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig apiPackage = "IO.Swagger.Api"; modelPackage = "IO.Swagger.Model"; + modelTestTemplateFiles.put("model_test.mustache", ".cs"); + apiTestTemplateFiles.put("api_test.mustache", ".cs"); + reservedWords = new HashSet( Arrays.asList( // local variable names in API methods (endpoints) @@ -270,6 +274,16 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig return "_" + name; } + @Override + public String apiTestFileFolder() { + return outputFolder + ".Test"; + } + + @Override + public String modelTestFileFolder() { + return outputFolder + ".Test"; + } + @Override public String apiFileFolder() { return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar); @@ -342,6 +356,16 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig return toModelName(name); } + @Override + public String toApiTestFilename(String name) { + return toApiName(name) + "Tests"; + } + + @Override + public String toModelTestFilename(String name) { + return toModelName(name) + "Tests"; + } + @Override public Map postProcessOperations(Map objs) { super.postProcessOperations(objs); diff --git a/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache b/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache new file mode 100644 index 0000000000..3afe27063d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache @@ -0,0 +1,61 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using NUnit.Framework; + +using {{packageName}}.Client; +using {{packageName}}.Api; +{{#hasImport}}using {{packageName}}.Model; +{{/hasImport}} + +namespace {{packageName}}.Test +{ + [TestFixture] + public class {{classname}}Tests + { + private {{classname}} instance; + + /// + /// Setup before each unit test + /// + [SetUp] + public void Init() + { + instance = new {{classname}}(); + } + + /// + /// Clean up after each unit test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of {{classname}} + /// + [Test] + public void {{operationId}}InstanceTest() + { + Assert.IsInstanceOf<{{classname}}> (instance, "instance is a {{classname}}"); + } + + {{#operations}}{{#operation}} + /// + /// Test {{operationId}} + /// + [Test] + public void {{operationId}}Test() + { + // TODO: add unit test for the method '{{operationId}}' + } + {{/operation}}{{/operations}} + } + +} diff --git a/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache b/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache new file mode 100644 index 0000000000..5b70f3ebf8 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/csharp/model_test.mustache @@ -0,0 +1,63 @@ +using NUnit.Framework; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using {{packageName}}.Api; +using {{packageName}}.Model; +using {{packageName}}.Client; +using System.Reflection; + +{{#models}} +{{#model}} +namespace {{packageName}}.Test +{ + [TestFixture] + public class {{classname}}Tests + { + private {{classname}} instance; + + /// + /// Setup before each test + /// + [SetUp] + public void Init() + { + instance = new {{classname}}(); + } + + /// + /// Clean up after each test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of {{classname}} + /// + [Test] + public void {{classname}}InstanceTest() + { + Assert.IsInstanceOf<{{classname}}> (instance, "instance is a {{classname}}"); + } + + {{#vars}} + /// + /// Test the property '{{name}}' + /// + [Test] + public void {{name}}Test() + { + // TODO: unit test for the property '{{name}}' + } + {{/vars}} + + } + +} +{{/model}} +{{/models}} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs new file mode 100644 index 0000000000..6384ee4179 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/CategoryTests.cs @@ -0,0 +1,68 @@ +using NUnit.Framework; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using IO.Swagger.Api; +using IO.Swagger.Model; +using IO.Swagger.Client; +using System.Reflection; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class CategoryTests + { + private Category instance; + + /// + /// Setup before each test + /// + [SetUp] + public void Init() + { + instance = new Category(); + } + + /// + /// Clean up after each test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of Category + /// + [Test] + public void CategoryInstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a Category"); + } + + + /// + /// Test the property 'Id' + /// + [Test] + public void IdTest() + { + // TODO: unit test for the property 'Id' + } + + /// + /// Test the property 'Name' + /// + [Test] + public void NameTest() + { + // TODO: unit test for the property 'Name' + } + + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs new file mode 100644 index 0000000000..7d0bc854ce --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/OrderTests.cs @@ -0,0 +1,104 @@ +using NUnit.Framework; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using IO.Swagger.Api; +using IO.Swagger.Model; +using IO.Swagger.Client; +using System.Reflection; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class OrderTests + { + private Order instance; + + /// + /// Setup before each test + /// + [SetUp] + public void Init() + { + instance = new Order(); + } + + /// + /// Clean up after each test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of Order + /// + [Test] + public void OrderInstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a Order"); + } + + + /// + /// Test the property 'Id' + /// + [Test] + public void IdTest() + { + // TODO: unit test for the property 'Id' + } + + /// + /// Test the property 'PetId' + /// + [Test] + public void PetIdTest() + { + // TODO: unit test for the property 'PetId' + } + + /// + /// Test the property 'Quantity' + /// + [Test] + public void QuantityTest() + { + // TODO: unit test for the property 'Quantity' + } + + /// + /// Test the property 'ShipDate' + /// + [Test] + public void ShipDateTest() + { + // TODO: unit test for the property 'ShipDate' + } + + /// + /// Test the property 'Status' + /// + [Test] + public void StatusTest() + { + // TODO: unit test for the property 'Status' + } + + /// + /// Test the property 'Complete' + /// + [Test] + public void CompleteTest() + { + // TODO: unit test for the property 'Complete' + } + + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs new file mode 100644 index 0000000000..aeb2f1262b --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs @@ -0,0 +1,141 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using NUnit.Framework; + +using IO.Swagger.Client; +using IO.Swagger.Api; +using IO.Swagger.Model; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class PetApiTests + { + private PetApi instance; + + /// + /// Setup before each unit test + /// + [SetUp] + public void Init() + { + instance = new PetApi(); + } + + /// + /// Clean up after each unit test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of PetApi + /// + [Test] + public void InstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a PetApi"); + } + + + /// + /// Test UpdatePet + /// + [Test] + public void UpdatePetTest() + { + // TODO: add unit test for the method 'UpdatePet' + } + + /// + /// Test AddPet + /// + [Test] + public void AddPetTest() + { + // TODO: add unit test for the method 'AddPet' + } + + /// + /// Test FindPetsByStatus + /// + [Test] + public void FindPetsByStatusTest() + { + // TODO: add unit test for the method 'FindPetsByStatus' + } + + /// + /// Test FindPetsByTags + /// + [Test] + public void FindPetsByTagsTest() + { + // TODO: add unit test for the method 'FindPetsByTags' + } + + /// + /// Test GetPetById + /// + [Test] + public void GetPetByIdTest() + { + // TODO: add unit test for the method 'GetPetById' + } + + /// + /// Test UpdatePetWithForm + /// + [Test] + public void UpdatePetWithFormTest() + { + // TODO: add unit test for the method 'UpdatePetWithForm' + } + + /// + /// Test DeletePet + /// + [Test] + public void DeletePetTest() + { + // TODO: add unit test for the method 'DeletePet' + } + + /// + /// Test UploadFile + /// + [Test] + public void UploadFileTest() + { + // TODO: add unit test for the method 'UploadFile' + } + + /// + /// Test GetPetByIdWithByteArray + /// + [Test] + public void GetPetByIdWithByteArrayTest() + { + // TODO: add unit test for the method 'GetPetByIdWithByteArray' + } + + /// + /// Test AddPetUsingByteArray + /// + [Test] + public void AddPetUsingByteArrayTest() + { + // TODO: add unit test for the method 'AddPetUsingByteArray' + } + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs new file mode 100644 index 0000000000..6b203dbd12 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetTests.cs @@ -0,0 +1,104 @@ +using NUnit.Framework; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using IO.Swagger.Api; +using IO.Swagger.Model; +using IO.Swagger.Client; +using System.Reflection; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class PetTests + { + private Pet instance; + + /// + /// Setup before each test + /// + [SetUp] + public void Init() + { + instance = new Pet(); + } + + /// + /// Clean up after each test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of Pet + /// + [Test] + public void PetInstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a Pet"); + } + + + /// + /// Test the property 'Id' + /// + [Test] + public void IdTest() + { + // TODO: unit test for the property 'Id' + } + + /// + /// Test the property 'Category' + /// + [Test] + public void CategoryTest() + { + // TODO: unit test for the property 'Category' + } + + /// + /// Test the property 'Name' + /// + [Test] + public void NameTest() + { + // TODO: unit test for the property 'Name' + } + + /// + /// Test the property 'PhotoUrls' + /// + [Test] + public void PhotoUrlsTest() + { + // TODO: unit test for the property 'PhotoUrls' + } + + /// + /// Test the property 'Tags' + /// + [Test] + public void TagsTest() + { + // TODO: unit test for the property 'Tags' + } + + /// + /// Test the property 'Status' + /// + [Test] + public void StatusTest() + { + // TODO: unit test for the property 'Status' + } + + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs new file mode 100644 index 0000000000..f271564e62 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs @@ -0,0 +1,87 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using NUnit.Framework; + +using IO.Swagger.Client; +using IO.Swagger.Api; +using IO.Swagger.Model; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class StoreApiTests + { + private StoreApi instance; + + /// + /// Setup before each unit test + /// + [SetUp] + public void Init() + { + instance = new StoreApi(); + } + + /// + /// Clean up after each unit test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of StoreApi + /// + [Test] + public void InstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a StoreApi"); + } + + + /// + /// Test GetInventory + /// + [Test] + public void GetInventoryTest() + { + // TODO: add unit test for the method 'GetInventory' + } + + /// + /// Test PlaceOrder + /// + [Test] + public void PlaceOrderTest() + { + // TODO: add unit test for the method 'PlaceOrder' + } + + /// + /// Test GetOrderById + /// + [Test] + public void GetOrderByIdTest() + { + // TODO: add unit test for the method 'GetOrderById' + } + + /// + /// Test DeleteOrder + /// + [Test] + public void DeleteOrderTest() + { + // TODO: add unit test for the method 'DeleteOrder' + } + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs new file mode 100644 index 0000000000..ad772584cc --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/TagTests.cs @@ -0,0 +1,68 @@ +using NUnit.Framework; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using IO.Swagger.Api; +using IO.Swagger.Model; +using IO.Swagger.Client; +using System.Reflection; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class TagTests + { + private Tag instance; + + /// + /// Setup before each test + /// + [SetUp] + public void Init() + { + instance = new Tag(); + } + + /// + /// Clean up after each test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of Tag + /// + [Test] + public void TagInstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a Tag"); + } + + + /// + /// Test the property 'Id' + /// + [Test] + public void IdTest() + { + // TODO: unit test for the property 'Id' + } + + /// + /// Test the property 'Name' + /// + [Test] + public void NameTest() + { + // TODO: unit test for the property 'Name' + } + + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs new file mode 100644 index 0000000000..13d62345eb --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs @@ -0,0 +1,123 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using NUnit.Framework; + +using IO.Swagger.Client; +using IO.Swagger.Api; +using IO.Swagger.Model; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class UserApiTests + { + private UserApi instance; + + /// + /// Setup before each unit test + /// + [SetUp] + public void Init() + { + instance = new UserApi(); + } + + /// + /// Clean up after each unit test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of UserApi + /// + [Test] + public void InstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a UserApi"); + } + + + /// + /// Test CreateUser + /// + [Test] + public void CreateUserTest() + { + // TODO: add unit test for the method 'CreateUser' + } + + /// + /// Test CreateUsersWithArrayInput + /// + [Test] + public void CreateUsersWithArrayInputTest() + { + // TODO: add unit test for the method 'CreateUsersWithArrayInput' + } + + /// + /// Test CreateUsersWithListInput + /// + [Test] + public void CreateUsersWithListInputTest() + { + // TODO: add unit test for the method 'CreateUsersWithListInput' + } + + /// + /// Test LoginUser + /// + [Test] + public void LoginUserTest() + { + // TODO: add unit test for the method 'LoginUser' + } + + /// + /// Test LogoutUser + /// + [Test] + public void LogoutUserTest() + { + // TODO: add unit test for the method 'LogoutUser' + } + + /// + /// Test GetUserByName + /// + [Test] + public void GetUserByNameTest() + { + // TODO: add unit test for the method 'GetUserByName' + } + + /// + /// Test UpdateUser + /// + [Test] + public void UpdateUserTest() + { + // TODO: add unit test for the method 'UpdateUser' + } + + /// + /// Test DeleteUser + /// + [Test] + public void DeleteUserTest() + { + // TODO: add unit test for the method 'DeleteUser' + } + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs new file mode 100644 index 0000000000..4610313b73 --- /dev/null +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserTests.cs @@ -0,0 +1,122 @@ +using NUnit.Framework; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using IO.Swagger.Api; +using IO.Swagger.Model; +using IO.Swagger.Client; +using System.Reflection; + +namespace IO.Swagger.Test +{ + [TestFixture] + public class UserTests + { + private User instance; + + /// + /// Setup before each test + /// + [SetUp] + public void Init() + { + instance = new User(); + } + + /// + /// Clean up after each test + /// + [TearDown] + public void Cleanup() + { + + } + + /// + /// Test an instance of User + /// + [Test] + public void UserInstanceTest() + { + Assert.IsInstanceOf (instance, "instance is a User"); + } + + + /// + /// Test the property 'Id' + /// + [Test] + public void IdTest() + { + // TODO: unit test for the property 'Id' + } + + /// + /// Test the property 'Username' + /// + [Test] + public void UsernameTest() + { + // TODO: unit test for the property 'Username' + } + + /// + /// Test the property 'FirstName' + /// + [Test] + public void FirstNameTest() + { + // TODO: unit test for the property 'FirstName' + } + + /// + /// Test the property 'LastName' + /// + [Test] + public void LastNameTest() + { + // TODO: unit test for the property 'LastName' + } + + /// + /// Test the property 'Email' + /// + [Test] + public void EmailTest() + { + // TODO: unit test for the property 'Email' + } + + /// + /// Test the property 'Password' + /// + [Test] + public void PasswordTest() + { + // TODO: unit test for the property 'Password' + } + + /// + /// Test the property 'Phone' + /// + [Test] + public void PhoneTest() + { + // TODO: unit test for the property 'Phone' + } + + /// + /// Test the property 'UserStatus' + /// + [Test] + public void UserStatusTest() + { + // TODO: unit test for the property 'UserStatus' + } + + + } + +} diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md index 8d71999564..3ce83da957 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/README.md @@ -10,7 +10,8 @@ NOTE: The DLLs included in the package may not be the latest version. We recommn ``` Install-Package RestSharp Install-Package Newtonsoft.Json -``` +``` + ## Installation Run the following command to generate the DLL - [Mac/Linux] compile-mono.sh diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs index 11223d8899..681d878531 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs index c09efc1acf..09b595410a 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs index 313103a3b8..f36ceed935 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs index 2c1cb092a3..fab0081f0b 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs index abbcea65b5..42c5b98100 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Runtime.Serialization; using Newtonsoft.Json; From 047abc63a41f5695daee3bdb5ad5e52abd0f9493 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 31 Jan 2016 12:49:32 +0800 Subject: [PATCH 3/4] add test case for c# method --- .../main/resources/csharp/api_test.mustache | 4 ++ .../Lib/SwaggerClient.Test/PetApiTests.cs | 45 +++++++++++++++++++ .../Lib/SwaggerClient.Test/StoreApiTests.cs | 15 +++++++ .../Lib/SwaggerClient.Test/UserApiTests.cs | 33 ++++++++++++++ 4 files changed, 97 insertions(+) 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 3afe27063d..2e638711b0 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/api_test.mustache @@ -54,6 +54,10 @@ namespace {{packageName}}.Test public void {{operationId}}Test() { // TODO: add unit test for the method '{{operationId}}' + {{#allParams}}{{{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}} } {{/operation}}{{/operations}} } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs index aeb2f1262b..a7caec2f54 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/PetApiTests.cs @@ -53,6 +53,10 @@ namespace IO.Swagger.Test public void UpdatePetTest() { // TODO: add unit test for the method 'UpdatePet' + Pet body = null; // TODO: replace null with proper value + + instance.UpdatePet(body); + } /// @@ -62,6 +66,10 @@ namespace IO.Swagger.Test public void AddPetTest() { // TODO: add unit test for the method 'AddPet' + Pet body = null; // TODO: replace null with proper value + + instance.AddPet(body); + } /// @@ -71,6 +79,10 @@ namespace IO.Swagger.Test public void FindPetsByStatusTest() { // TODO: add unit test for the method 'FindPetsByStatus' + List status = null; // TODO: replace null with proper value + + var response = instance.FindPetsByStatus(status); + Assert.IsInstanceOf> (response, "response is List"); } /// @@ -80,6 +92,10 @@ namespace IO.Swagger.Test public void FindPetsByTagsTest() { // TODO: add unit test for the method 'FindPetsByTags' + List tags = null; // TODO: replace null with proper value + + var response = instance.FindPetsByTags(tags); + Assert.IsInstanceOf> (response, "response is List"); } /// @@ -89,6 +105,10 @@ namespace IO.Swagger.Test public void GetPetByIdTest() { // TODO: add unit test for the method 'GetPetById' + long? petId = null; // TODO: replace null with proper value + + var response = instance.GetPetById(petId); + Assert.IsInstanceOf (response, "response is Pet"); } /// @@ -98,6 +118,12 @@ namespace IO.Swagger.Test public void UpdatePetWithFormTest() { // TODO: add unit test for the method 'UpdatePetWithForm' + string petId = null; // TODO: replace null with proper value + string name = null; // TODO: replace null with proper value + string status = null; // TODO: replace null with proper value + + instance.UpdatePetWithForm(petId, name, status); + } /// @@ -107,6 +133,11 @@ namespace IO.Swagger.Test public void DeletePetTest() { // TODO: add unit test for the method 'DeletePet' + long? petId = null; // TODO: replace null with proper value + string apiKey = null; // TODO: replace null with proper value + + instance.DeletePet(petId, apiKey); + } /// @@ -116,6 +147,12 @@ namespace IO.Swagger.Test public void UploadFileTest() { // TODO: add unit test for the method 'UploadFile' + long? petId = null; // TODO: replace null with proper value + string additionalMetadata = null; // TODO: replace null with proper value + Stream file = null; // TODO: replace null with proper value + + instance.UploadFile(petId, additionalMetadata, file); + } /// @@ -125,6 +162,10 @@ namespace IO.Swagger.Test public void GetPetByIdWithByteArrayTest() { // TODO: add unit test for the method 'GetPetByIdWithByteArray' + long? petId = null; // TODO: replace null with proper value + + var response = instance.GetPetByIdWithByteArray(petId); + Assert.IsInstanceOf (response, "response is byte[]"); } /// @@ -134,6 +175,10 @@ namespace IO.Swagger.Test public void AddPetUsingByteArrayTest() { // TODO: add unit test for the method 'AddPetUsingByteArray' + byte[] body = null; // TODO: replace null with proper value + + instance.AddPetUsingByteArray(body); + } } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs index f271564e62..8e3f99eff2 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/StoreApiTests.cs @@ -53,6 +53,9 @@ namespace IO.Swagger.Test public void GetInventoryTest() { // TODO: add unit test for the method 'GetInventory' + + var response = instance.GetInventory(); + Assert.IsInstanceOf> (response, "response is Dictionary"); } /// @@ -62,6 +65,10 @@ namespace IO.Swagger.Test public void PlaceOrderTest() { // TODO: add unit test for the method 'PlaceOrder' + Order body = null; // TODO: replace null with proper value + + var response = instance.PlaceOrder(body); + Assert.IsInstanceOf (response, "response is Order"); } /// @@ -71,6 +78,10 @@ namespace IO.Swagger.Test public void GetOrderByIdTest() { // TODO: add unit test for the method 'GetOrderById' + string orderId = null; // TODO: replace null with proper value + + var response = instance.GetOrderById(orderId); + Assert.IsInstanceOf (response, "response is Order"); } /// @@ -80,6 +91,10 @@ namespace IO.Swagger.Test public void DeleteOrderTest() { // TODO: add unit test for the method 'DeleteOrder' + string orderId = null; // TODO: replace null with proper value + + instance.DeleteOrder(orderId); + } } diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs index 13d62345eb..0d543c384a 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient.Test/UserApiTests.cs @@ -53,6 +53,10 @@ namespace IO.Swagger.Test public void CreateUserTest() { // TODO: add unit test for the method 'CreateUser' + User body = null; // TODO: replace null with proper value + + instance.CreateUser(body); + } /// @@ -62,6 +66,10 @@ namespace IO.Swagger.Test public void CreateUsersWithArrayInputTest() { // TODO: add unit test for the method 'CreateUsersWithArrayInput' + List body = null; // TODO: replace null with proper value + + instance.CreateUsersWithArrayInput(body); + } /// @@ -71,6 +79,10 @@ namespace IO.Swagger.Test public void CreateUsersWithListInputTest() { // TODO: add unit test for the method 'CreateUsersWithListInput' + List body = null; // TODO: replace null with proper value + + instance.CreateUsersWithListInput(body); + } /// @@ -80,6 +92,11 @@ namespace IO.Swagger.Test public void LoginUserTest() { // TODO: add unit test for the method 'LoginUser' + string username = null; // TODO: replace null with proper value + string password = null; // TODO: replace null with proper value + + var response = instance.LoginUser(username, password); + Assert.IsInstanceOf (response, "response is string"); } /// @@ -89,6 +106,9 @@ namespace IO.Swagger.Test public void LogoutUserTest() { // TODO: add unit test for the method 'LogoutUser' + + instance.LogoutUser(); + } /// @@ -98,6 +118,10 @@ namespace IO.Swagger.Test public void GetUserByNameTest() { // TODO: add unit test for the method 'GetUserByName' + string username = null; // TODO: replace null with proper value + + var response = instance.GetUserByName(username); + Assert.IsInstanceOf (response, "response is User"); } /// @@ -107,6 +131,11 @@ namespace IO.Swagger.Test public void UpdateUserTest() { // TODO: add unit test for the method 'UpdateUser' + string username = null; // TODO: replace null with proper value + User body = null; // TODO: replace null with proper value + + instance.UpdateUser(username, body); + } /// @@ -116,6 +145,10 @@ namespace IO.Swagger.Test public void DeleteUserTest() { // TODO: add unit test for the method 'DeleteUser' + string username = null; // TODO: replace null with proper value + + instance.DeleteUser(username); + } } From b275eefbbfc546d4dfffcee5c36735916ee98164 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 2 Feb 2016 00:57:57 +0800 Subject: [PATCH 4/4] remove testFolder (not used) --- .../java/io/swagger/codegen/languages/CSharpClientCodegen.java | 1 - 1 file changed, 1 deletion(-) 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 991b60cd49..07252e685f 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 @@ -41,7 +41,6 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig protected String packageVersion = "1.0.0"; protected String clientPackage = "IO.Swagger.Client"; protected String sourceFolder = "src" + File.separator + "main" + File.separator + "csharp"; - protected String testFolder = "Test"; public CSharpClientCodegen() { super();