forked from loafle/openapi-generator-original
Added the ability to customize the DateTimeFormat
Updated Configuration to have a DateTimeFormat Added Unit Tests for Configuration.DateTimeFormat Cleaned up namespaces in SwaggerClientTest Added an embedded resource for testing uploads
This commit is contained in:
@@ -3,11 +3,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using IO.Swagger.Client;
|
||||
|
||||
namespace SwaggerClient.TestApiClient
|
||||
namespace SwaggerClientTest.TestApiClient
|
||||
{
|
||||
public class TestApiClient
|
||||
{
|
||||
[Test ()]
|
||||
[TearDown()]
|
||||
public void TearDown()
|
||||
{
|
||||
// Reset to default, just in case
|
||||
Configuration.DateTimeFormat = "o";
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString ()
|
||||
{
|
||||
ApiClient api = new ApiClient ();
|
||||
@@ -19,20 +26,49 @@ namespace SwaggerClient.TestApiClient
|
||||
// test array of int
|
||||
List<int> numList = new List<int>(new int[] {1, 37});
|
||||
Assert.AreEqual("1,37", api.ParameterToString (numList));
|
||||
|
||||
// test datetime
|
||||
DateTime dateUtc = DateTime.Parse("2008-04-10T13:30:00.0000000z", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000Z", api.ParameterToString (dateUtc));
|
||||
|
||||
// test datetime with no timezone
|
||||
DateTime dateWithNoTz = DateTime.Parse("2008-04-10T13:30:00.000", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000", api.ParameterToString (dateWithNoTz));
|
||||
|
||||
// test datetime with a time zone
|
||||
DateTime dateWithTz = DateTime.Parse("2008-04-10T13:30:00.0000000-04:00", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000-04:00", api.ParameterToString (dateWithTz));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString_DateTime ()
|
||||
{
|
||||
ApiClient api = new ApiClient();
|
||||
|
||||
// test datetime
|
||||
DateTime dateUtc = DateTime.Parse("2008-04-10T13:30:00.0000000z", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000Z", api.ParameterToString(dateUtc));
|
||||
|
||||
// test datetime with no timezone
|
||||
DateTime dateWithNoTz = DateTime.Parse("2008-04-10T13:30:00.000", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000", api.ParameterToString(dateWithNoTz));
|
||||
|
||||
// test datetime with a time zone
|
||||
DateTime dateWithTz = DateTime.Parse("2008-04-10T13:30:00.0000000-04:00", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2008-04-10T13:30:00.0000000-04:00", api.ParameterToString(dateWithTz));
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString_DateTime_WithUFormat ()
|
||||
{
|
||||
// Setup the DateTimeFormat across all of the calls
|
||||
Configuration.DateTimeFormat = "u";
|
||||
ApiClient api = new ApiClient();
|
||||
|
||||
// test datetime
|
||||
DateTime dateUtc = DateTime.Parse("2009-06-15 20:45:30Z", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("2009-06-15 20:45:30Z", api.ParameterToString(dateUtc));
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void TestParameterToString_DateTime_WithCustomFormat ()
|
||||
{
|
||||
// Setup the DateTimeFormat across all of the calls
|
||||
Configuration.DateTimeFormat = "dd/MM/yy HH:mm:ss";
|
||||
ApiClient api = new ApiClient();
|
||||
|
||||
// test datetime
|
||||
DateTime dateUtc = DateTime.Parse("2009-06-15 20:45:30Z", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
Assert.AreEqual("15/06/09 20:45:30", api.ParameterToString(dateUtc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user