2015-09-11 14:48:38 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using IO.Swagger.Client;
|
2016-01-18 03:39:32 +00:00
|
|
|
|
using IO.Swagger.Api;
|
2015-09-11 14:48:38 +00:00
|
|
|
|
|
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));
|
|
|
|
|
}
|
2016-01-14 02:43:56 +00:00
|
|
|
|
|
|
|
|
|
[Test ()]
|
|
|
|
|
public void TestSanitizeFilename ()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("sun.gif"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("../sun.gif"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("/var/tmp/sun.gif"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("./sun.gif"));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("sun", ApiClient.SanitizeFilename("sun"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("..\\sun.gif"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("\\var\\tmp\\sun.gif"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("c:\\var\\tmp\\sun.gif"));
|
|
|
|
|
Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename(".\\sun.gif"));
|
|
|
|
|
|
|
|
|
|
}
|
2016-01-18 03:39:32 +00:00
|
|
|
|
|
|
|
|
|
[Test ()]
|
|
|
|
|
public void TestApiClientInstance ()
|
|
|
|
|
{
|
|
|
|
|
PetApi p1 = new PetApi ();
|
|
|
|
|
PetApi p2 = new PetApi ();
|
|
|
|
|
|
|
|
|
|
Configuration c1 = new Configuration (); // using default ApiClient
|
|
|
|
|
PetApi p3 = new PetApi (c1);
|
|
|
|
|
|
|
|
|
|
ApiClient a1 = new ApiClient();
|
2016-01-18 03:45:13 +00:00
|
|
|
|
Configuration c2 = new Configuration (a1); // using "a1" as the ApiClient
|
2016-01-18 03:39:32 +00:00
|
|
|
|
PetApi p4 = new PetApi (c2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ensure both using the same default ApiClient
|
|
|
|
|
Assert.AreSame(p1.Configuration.ApiClient, p2.Configuration.ApiClient);
|
|
|
|
|
Assert.AreSame(p1.Configuration.ApiClient, Configuration.Default.ApiClient);
|
|
|
|
|
|
2016-01-18 03:45:13 +00:00
|
|
|
|
// ensure both using the same default ApiClient
|
2016-01-18 03:39:32 +00:00
|
|
|
|
Assert.AreSame(p3.Configuration.ApiClient, c1.ApiClient);
|
|
|
|
|
Assert.AreSame(p3.Configuration.ApiClient, Configuration.Default.ApiClient);
|
|
|
|
|
|
2016-01-18 03:45:13 +00:00
|
|
|
|
// ensure it's not using the default ApiClient
|
2016-01-18 03:39:32 +00:00
|
|
|
|
Assert.AreSame(p4.Configuration.ApiClient, c2.ApiClient);
|
|
|
|
|
Assert.AreNotSame(p4.Configuration.ApiClient, Configuration.Default.ApiClient);
|
|
|
|
|
|
|
|
|
|
}
|
2015-12-11 23:28:37 +00:00
|
|
|
|
}
|
2015-09-11 14:48:38 +00:00
|
|
|
|
}
|
|
|
|
|
|