add unit test files for C#

This commit is contained in:
wing328 2016-01-31 01:52:41 +08:00
parent 587615b656
commit 4ce255dc38
17 changed files with 972 additions and 1 deletions

View File

@ -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<String>(
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<String, Object> postProcessOperations(Map<String, Object> objs) {
super.postProcessOperations(objs);

View File

@ -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;
/// <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}}'
}
{{/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,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;
/// <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'
}
/// <summary>
/// Test AddPet
/// </summary>
[Test]
public void AddPetTest()
{
// TODO: add unit test for the method 'AddPet'
}
/// <summary>
/// Test FindPetsByStatus
/// </summary>
[Test]
public void FindPetsByStatusTest()
{
// TODO: add unit test for the method 'FindPetsByStatus'
}
/// <summary>
/// Test FindPetsByTags
/// </summary>
[Test]
public void FindPetsByTagsTest()
{
// TODO: add unit test for the method 'FindPetsByTags'
}
/// <summary>
/// Test GetPetById
/// </summary>
[Test]
public void GetPetByIdTest()
{
// TODO: add unit test for the method 'GetPetById'
}
/// <summary>
/// Test UpdatePetWithForm
/// </summary>
[Test]
public void UpdatePetWithFormTest()
{
// TODO: add unit test for the method 'UpdatePetWithForm'
}
/// <summary>
/// Test DeletePet
/// </summary>
[Test]
public void DeletePetTest()
{
// TODO: add unit test for the method 'DeletePet'
}
/// <summary>
/// Test UploadFile
/// </summary>
[Test]
public void UploadFileTest()
{
// TODO: add unit test for the method 'UploadFile'
}
/// <summary>
/// Test GetPetByIdWithByteArray
/// </summary>
[Test]
public void GetPetByIdWithByteArrayTest()
{
// TODO: add unit test for the method 'GetPetByIdWithByteArray'
}
/// <summary>
/// Test AddPetUsingByteArray
/// </summary>
[Test]
public void AddPetUsingByteArrayTest()
{
// TODO: add unit test for the method 'AddPetUsingByteArray'
}
}
}

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,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;
/// <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'
}
/// <summary>
/// Test PlaceOrder
/// </summary>
[Test]
public void PlaceOrderTest()
{
// TODO: add unit test for the method 'PlaceOrder'
}
/// <summary>
/// Test GetOrderById
/// </summary>
[Test]
public void GetOrderByIdTest()
{
// TODO: add unit test for the method 'GetOrderById'
}
/// <summary>
/// Test DeleteOrder
/// </summary>
[Test]
public void DeleteOrderTest()
{
// TODO: add unit test for the method 'DeleteOrder'
}
}
}

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,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;
/// <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'
}
/// <summary>
/// Test CreateUsersWithArrayInput
/// </summary>
[Test]
public void CreateUsersWithArrayInputTest()
{
// TODO: add unit test for the method 'CreateUsersWithArrayInput'
}
/// <summary>
/// Test CreateUsersWithListInput
/// </summary>
[Test]
public void CreateUsersWithListInputTest()
{
// TODO: add unit test for the method 'CreateUsersWithListInput'
}
/// <summary>
/// Test LoginUser
/// </summary>
[Test]
public void LoginUserTest()
{
// TODO: add unit test for the method 'LoginUser'
}
/// <summary>
/// Test LogoutUser
/// </summary>
[Test]
public void LogoutUserTest()
{
// TODO: add unit test for the method 'LogoutUser'
}
/// <summary>
/// Test GetUserByName
/// </summary>
[Test]
public void GetUserByNameTest()
{
// TODO: add unit test for the method 'GetUserByName'
}
/// <summary>
/// Test UpdateUser
/// </summary>
[Test]
public void UpdateUserTest()
{
// TODO: add unit test for the method 'UpdateUser'
}
/// <summary>
/// Test DeleteUser
/// </summary>
[Test]
public void DeleteUserTest()
{
// TODO: add unit test for the method 'DeleteUser'
}
}
}

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

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;