update C# ParamterToString to support array of object, add test case

This commit is contained in:
wing328
2015-09-11 22:48:38 +08:00
parent 16afd4ee9b
commit f21fa08cd6
9 changed files with 50 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
@@ -189,7 +190,7 @@ namespace IO.Swagger.Client
/// <summary>
/// If parameter is DateTime, output in ISO8601 format.
/// If parameter is a list of string, join the list with ",".
/// If parameter is a list, join the list with ",".
/// Otherwise just return the string.
/// </summary>
/// <param name="obj">The parameter (header, path, query, form).</param>
@@ -198,8 +199,14 @@ namespace IO.Swagger.Client
{
if (obj is DateTime)
return ((DateTime)obj).ToString ("u");
else if (obj is List<string>)
return String.Join(",", obj as List<string>);
else if (obj is IList) {
string flattenString = "";
string separator = ",";
foreach (var param in (IList)obj) {
flattenString += param.ToString() + separator;
}
return flattenString.Remove(flattenString.Length - 1);;
}
else
return Convert.ToString (obj);
}

View File

@@ -55,6 +55,7 @@
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Model\Tag.cs" />
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Model\User.cs" />
<Compile Include="TestPet.cs" />
<Compile Include="TestApiClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -0,0 +1,26 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using IO.Swagger.Client;
namespace SwaggerClient.TestApiClient
{
public class TestApiClient
{
[Test ()]
public void TestParameterToString ()
{
ApiClient api = new ApiClient ();
// test array of string
List<string> statusList = new List<String>(new String[] {"available", "sold"});
Assert.AreEqual("available,sold", api.ParameterToString (statusList));
// test array of int
List<int> numList = new List<int>(new int[] {1, 37});
Assert.AreEqual("1,37", api.ParameterToString (numList));
}
}
}

View File

@@ -1,8 +1,8 @@
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll