2015-09-11 14:48:38 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using IO.Swagger.Client;
|
|
|
|
|
|
2015-12-11 23:28:37 +00:00
|
|
|
|
namespace SwaggerClientTest.TestApiClient
|
2015-09-11 14:48:38 +00:00
|
|
|
|
{
|
|
|
|
|
public class TestApiClient
|
|
|
|
|
{
|
2015-12-11 23:28:37 +00:00
|
|
|
|
[TearDown()]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
|
|
|
|
// Reset to default, just in case
|
2015-12-14 08:07:41 +00:00
|
|
|
|
Configuration.Default.DateTimeFormat = "o";
|
2015-12-11 23:28:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-10 16:39:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test SelectHeaderContentType
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test ()]
|
|
|
|
|
public void TestSelectHeaderContentType ()
|
|
|
|
|
{
|
|
|
|
|
ApiClient api = new ApiClient ();
|
|
|
|
|
String[] contentTypes = new String[] { "application/json", "application/xml" };
|
|
|
|
|
Assert.AreEqual("application/json", api.SelectHeaderContentType (contentTypes));
|
|
|
|
|
|
|
|
|
|
contentTypes = new String[] { "application/xml" };
|
|
|
|
|
Assert.AreEqual("application/xml", api.SelectHeaderContentType (contentTypes));
|
|
|
|
|
|
|
|
|
|
contentTypes = new String[] {};
|
|
|
|
|
Assert.IsNull(api.SelectHeaderContentType (contentTypes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test ParameterToString
|
|
|
|
|
/// </summary>
|
2015-12-11 23:28:37 +00:00
|
|
|
|
[Test ()]
|
2015-09-11 14:48:38 +00:00
|
|
|
|
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));
|
2015-12-11 23:28:37 +00:00
|
|
|
|
}
|
2015-12-11 01:28:44 +00:00
|
|
|
|
|
2015-12-11 23:28:37 +00:00
|
|
|
|
[Test ()]
|
2015-12-14 08:07:41 +00:00
|
|
|
|
public void TestParameterToStringForDateTime ()
|
|
|
|
|
{
|
|
|
|
|
ApiClient api = new ApiClient ();
|
2015-12-11 01:42:30 +00:00
|
|
|
|
|
2015-12-14 08:07:41 +00:00
|
|
|
|
// 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));
|
2015-12-11 01:42:30 +00:00
|
|
|
|
|
2015-12-14 08:07:41 +00:00
|
|
|
|
// 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));
|
|
|
|
|
}
|
2015-12-11 01:28:44 +00:00
|
|
|
|
|
2015-12-14 08:07:41 +00:00
|
|
|
|
// The test below only passes when running at -04:00 timezone
|
|
|
|
|
[Ignore ()]
|
|
|
|
|
public void TestParameterToStringWithTimeZoneForDateTime ()
|
|
|
|
|
{
|
|
|
|
|
ApiClient api = new ApiClient ();
|
2015-12-11 23:28:37 +00:00
|
|
|
|
// test datetime with a time zone
|
2016-01-07 01:02:43 +00:00
|
|
|
|
DateTimeOffset dateWithTz = DateTimeOffset.Parse("2008-04-10T13:30:00.0000000-04:00", null, System.Globalization.DateTimeStyles.RoundtripKind);
|
2015-12-11 23:28:37 +00:00
|
|
|
|
Assert.AreEqual("2008-04-10T13:30:00.0000000-04:00", api.ParameterToString(dateWithTz));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test ()]
|
2015-12-14 08:07:41 +00:00
|
|
|
|
public void TestParameterToStringForDateTimeWithUFormat ()
|
2015-12-11 23:28:37 +00:00
|
|
|
|
{
|
|
|
|
|
// Setup the DateTimeFormat across all of the calls
|
2015-12-14 08:07:41 +00:00
|
|
|
|
Configuration.Default.DateTimeFormat = "u";
|
2015-12-11 23:28:37 +00:00
|
|
|
|
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 ()]
|
2015-12-14 08:07:41 +00:00
|
|
|
|
public void TestParameterToStringForDateTimeWithCustomFormat ()
|
2015-12-11 23:28:37 +00:00
|
|
|
|
{
|
|
|
|
|
// Setup the DateTimeFormat across all of the calls
|
2015-12-14 08:07:41 +00:00
|
|
|
|
Configuration.Default.DateTimeFormat = "dd/MM/yy HH:mm:ss";
|
2015-12-11 23:28:37 +00:00
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-11 14:48:38 +00:00
|
|
|
|
}
|
|
|
|
|
|