Merge pull request #2007 from wing328/csharp_readme

[C#] Add unit tests for C# APIs and models
This commit is contained in:
wing328 2016-02-02 12:43:44 +08:00
commit b2d98acb21
18 changed files with 1080 additions and 2 deletions

View File

@ -51,6 +51,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<String>(
Arrays.asList(
// local variable names in API methods (endpoints)
@ -270,6 +273,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 +355,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<String, Object> postProcessOperations(Map<String, Object> objs) {
super.postProcessOperations(objs);

View File

@ -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

View File

@ -0,0 +1,65 @@
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;
/// <summary>
/// Setup before each unit test
/// </summary>
[SetUp]
public void Init()
{
instance = new {{classname}}();
}
/// <summary>
/// Clean up after each unit test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of {{classname}}
/// </summary>
[Test]
public void {{operationId}}InstanceTest()
{
Assert.IsInstanceOf<{{classname}}> (instance, "instance is a {{classname}}");
}
{{#operations}}{{#operation}}
/// <summary>
/// Test {{operationId}}
/// </summary>
[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}}
}
}

View File

@ -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;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
instance = new {{classname}}();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of {{classname}}
/// </summary>
[Test]
public void {{classname}}InstanceTest()
{
Assert.IsInstanceOf<{{classname}}> (instance, "instance is a {{classname}}");
}
{{#vars}}
/// <summary>
/// Test the property '{{name}}'
/// </summary>
[Test]
public void {{name}}Test()
{
// TODO: unit test for the property '{{name}}'
}
{{/vars}}
}
}
{{/model}}
{{/models}}

View File

@ -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;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
instance = new Category();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of Category
/// </summary>
[Test]
public void CategoryInstanceTest()
{
Assert.IsInstanceOf<Category> (instance, "instance is a Category");
}
/// <summary>
/// Test the property 'Id'
/// </summary>
[Test]
public void IdTest()
{
// TODO: unit test for the property 'Id'
}
/// <summary>
/// Test the property 'Name'
/// </summary>
[Test]
public void NameTest()
{
// TODO: unit test for the property 'Name'
}
}
}

View File

@ -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;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
instance = new Order();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of Order
/// </summary>
[Test]
public void OrderInstanceTest()
{
Assert.IsInstanceOf<Order> (instance, "instance is a Order");
}
/// <summary>
/// Test the property 'Id'
/// </summary>
[Test]
public void IdTest()
{
// TODO: unit test for the property 'Id'
}
/// <summary>
/// Test the property 'PetId'
/// </summary>
[Test]
public void PetIdTest()
{
// TODO: unit test for the property 'PetId'
}
/// <summary>
/// Test the property 'Quantity'
/// </summary>
[Test]
public void QuantityTest()
{
// TODO: unit test for the property 'Quantity'
}
/// <summary>
/// Test the property 'ShipDate'
/// </summary>
[Test]
public void ShipDateTest()
{
// TODO: unit test for the property 'ShipDate'
}
/// <summary>
/// Test the property 'Status'
/// </summary>
[Test]
public void StatusTest()
{
// TODO: unit test for the property 'Status'
}
/// <summary>
/// Test the property 'Complete'
/// </summary>
[Test]
public void CompleteTest()
{
// TODO: unit test for the property 'Complete'
}
}
}

View File

@ -0,0 +1,186 @@
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;
/// <summary>
/// Setup before each unit test
/// </summary>
[SetUp]
public void Init()
{
instance = new PetApi();
}
/// <summary>
/// Clean up after each unit test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of PetApi
/// </summary>
[Test]
public void InstanceTest()
{
Assert.IsInstanceOf<PetApi> (instance, "instance is a PetApi");
}
/// <summary>
/// Test UpdatePet
/// </summary>
[Test]
public void UpdatePetTest()
{
// TODO: add unit test for the method 'UpdatePet'
Pet body = null; // TODO: replace null with proper value
instance.UpdatePet(body);
}
/// <summary>
/// Test AddPet
/// </summary>
[Test]
public void AddPetTest()
{
// TODO: add unit test for the method 'AddPet'
Pet body = null; // TODO: replace null with proper value
instance.AddPet(body);
}
/// <summary>
/// Test FindPetsByStatus
/// </summary>
[Test]
public void FindPetsByStatusTest()
{
// TODO: add unit test for the method 'FindPetsByStatus'
List<string> status = null; // TODO: replace null with proper value
var response = instance.FindPetsByStatus(status);
Assert.IsInstanceOf<List<Pet>> (response, "response is List<Pet>");
}
/// <summary>
/// Test FindPetsByTags
/// </summary>
[Test]
public void FindPetsByTagsTest()
{
// TODO: add unit test for the method 'FindPetsByTags'
List<string> tags = null; // TODO: replace null with proper value
var response = instance.FindPetsByTags(tags);
Assert.IsInstanceOf<List<Pet>> (response, "response is List<Pet>");
}
/// <summary>
/// Test GetPetById
/// </summary>
[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<Pet> (response, "response is Pet");
}
/// <summary>
/// Test UpdatePetWithForm
/// </summary>
[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);
}
/// <summary>
/// Test DeletePet
/// </summary>
[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);
}
/// <summary>
/// Test UploadFile
/// </summary>
[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);
}
/// <summary>
/// Test GetPetByIdWithByteArray
/// </summary>
[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<byte[]> (response, "response is byte[]");
}
/// <summary>
/// Test AddPetUsingByteArray
/// </summary>
[Test]
public void AddPetUsingByteArrayTest()
{
// TODO: add unit test for the method 'AddPetUsingByteArray'
byte[] body = null; // TODO: replace null with proper value
instance.AddPetUsingByteArray(body);
}
}
}

View File

@ -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;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
instance = new Pet();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of Pet
/// </summary>
[Test]
public void PetInstanceTest()
{
Assert.IsInstanceOf<Pet> (instance, "instance is a Pet");
}
/// <summary>
/// Test the property 'Id'
/// </summary>
[Test]
public void IdTest()
{
// TODO: unit test for the property 'Id'
}
/// <summary>
/// Test the property 'Category'
/// </summary>
[Test]
public void CategoryTest()
{
// TODO: unit test for the property 'Category'
}
/// <summary>
/// Test the property 'Name'
/// </summary>
[Test]
public void NameTest()
{
// TODO: unit test for the property 'Name'
}
/// <summary>
/// Test the property 'PhotoUrls'
/// </summary>
[Test]
public void PhotoUrlsTest()
{
// TODO: unit test for the property 'PhotoUrls'
}
/// <summary>
/// Test the property 'Tags'
/// </summary>
[Test]
public void TagsTest()
{
// TODO: unit test for the property 'Tags'
}
/// <summary>
/// Test the property 'Status'
/// </summary>
[Test]
public void StatusTest()
{
// TODO: unit test for the property 'Status'
}
}
}

View File

@ -0,0 +1,102 @@
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;
/// <summary>
/// Setup before each unit test
/// </summary>
[SetUp]
public void Init()
{
instance = new StoreApi();
}
/// <summary>
/// Clean up after each unit test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of StoreApi
/// </summary>
[Test]
public void InstanceTest()
{
Assert.IsInstanceOf<StoreApi> (instance, "instance is a StoreApi");
}
/// <summary>
/// Test GetInventory
/// </summary>
[Test]
public void GetInventoryTest()
{
// TODO: add unit test for the method 'GetInventory'
var response = instance.GetInventory();
Assert.IsInstanceOf<Dictionary<string, int?>> (response, "response is Dictionary<string, int?>");
}
/// <summary>
/// Test PlaceOrder
/// </summary>
[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<Order> (response, "response is Order");
}
/// <summary>
/// Test GetOrderById
/// </summary>
[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<Order> (response, "response is Order");
}
/// <summary>
/// Test DeleteOrder
/// </summary>
[Test]
public void DeleteOrderTest()
{
// TODO: add unit test for the method 'DeleteOrder'
string orderId = null; // TODO: replace null with proper value
instance.DeleteOrder(orderId);
}
}
}

View File

@ -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;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
instance = new Tag();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of Tag
/// </summary>
[Test]
public void TagInstanceTest()
{
Assert.IsInstanceOf<Tag> (instance, "instance is a Tag");
}
/// <summary>
/// Test the property 'Id'
/// </summary>
[Test]
public void IdTest()
{
// TODO: unit test for the property 'Id'
}
/// <summary>
/// Test the property 'Name'
/// </summary>
[Test]
public void NameTest()
{
// TODO: unit test for the property 'Name'
}
}
}

View File

@ -0,0 +1,156 @@
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;
/// <summary>
/// Setup before each unit test
/// </summary>
[SetUp]
public void Init()
{
instance = new UserApi();
}
/// <summary>
/// Clean up after each unit test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of UserApi
/// </summary>
[Test]
public void InstanceTest()
{
Assert.IsInstanceOf<UserApi> (instance, "instance is a UserApi");
}
/// <summary>
/// Test CreateUser
/// </summary>
[Test]
public void CreateUserTest()
{
// TODO: add unit test for the method 'CreateUser'
User body = null; // TODO: replace null with proper value
instance.CreateUser(body);
}
/// <summary>
/// Test CreateUsersWithArrayInput
/// </summary>
[Test]
public void CreateUsersWithArrayInputTest()
{
// TODO: add unit test for the method 'CreateUsersWithArrayInput'
List<User> body = null; // TODO: replace null with proper value
instance.CreateUsersWithArrayInput(body);
}
/// <summary>
/// Test CreateUsersWithListInput
/// </summary>
[Test]
public void CreateUsersWithListInputTest()
{
// TODO: add unit test for the method 'CreateUsersWithListInput'
List<User> body = null; // TODO: replace null with proper value
instance.CreateUsersWithListInput(body);
}
/// <summary>
/// Test LoginUser
/// </summary>
[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<string> (response, "response is string");
}
/// <summary>
/// Test LogoutUser
/// </summary>
[Test]
public void LogoutUserTest()
{
// TODO: add unit test for the method 'LogoutUser'
instance.LogoutUser();
}
/// <summary>
/// Test GetUserByName
/// </summary>
[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<User> (response, "response is User");
}
/// <summary>
/// Test UpdateUser
/// </summary>
[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);
}
/// <summary>
/// Test DeleteUser
/// </summary>
[Test]
public void DeleteUserTest()
{
// TODO: add unit test for the method 'DeleteUser'
string username = null; // TODO: replace null with proper value
instance.DeleteUser(username);
}
}
}

View File

@ -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;
/// <summary>
/// Setup before each test
/// </summary>
[SetUp]
public void Init()
{
instance = new User();
}
/// <summary>
/// Clean up after each test
/// </summary>
[TearDown]
public void Cleanup()
{
}
/// <summary>
/// Test an instance of User
/// </summary>
[Test]
public void UserInstanceTest()
{
Assert.IsInstanceOf<User> (instance, "instance is a User");
}
/// <summary>
/// Test the property 'Id'
/// </summary>
[Test]
public void IdTest()
{
// TODO: unit test for the property 'Id'
}
/// <summary>
/// Test the property 'Username'
/// </summary>
[Test]
public void UsernameTest()
{
// TODO: unit test for the property 'Username'
}
/// <summary>
/// Test the property 'FirstName'
/// </summary>
[Test]
public void FirstNameTest()
{
// TODO: unit test for the property 'FirstName'
}
/// <summary>
/// Test the property 'LastName'
/// </summary>
[Test]
public void LastNameTest()
{
// TODO: unit test for the property 'LastName'
}
/// <summary>
/// Test the property 'Email'
/// </summary>
[Test]
public void EmailTest()
{
// TODO: unit test for the property 'Email'
}
/// <summary>
/// Test the property 'Password'
/// </summary>
[Test]
public void PasswordTest()
{
// TODO: unit test for the property 'Password'
}
/// <summary>
/// Test the property 'Phone'
/// </summary>
[Test]
public void PhoneTest()
{
// TODO: unit test for the property 'Phone'
}
/// <summary>
/// Test the property 'UserStatus'
/// </summary>
[Test]
public void UserStatusTest()
{
// TODO: unit test for the property 'UserStatus'
}
}
}

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;