public void TestUsage() { // basic use case using default base URL PetApi p1 = new PetApi(); Assert.AreSame(p1.Configuration, Configuration.Default, "PetApi should use default configuration"); // using a different base URL PetApi p2 = new PetApi("http://new-base-url.com/"); Assert.AreEqual(p2.Configuration.ApiClient.RestClient.BaseUrl.ToString(), "http://new-base-url.com/"); // using a different configuration Configuration c1 = new Configuration(); PetApi p3 = new PetApi(c1); Assert.AreSame(p3.Configuration, c1); // using a different base URL via a new Configuration String newApiClientUrl = "http://new-api-client.com"; Configuration c2 = new Configuration { BasePath = newApiClientUrl }; PetApi p4 = new PetApi(c2); Assert.AreEqual(p4.Configuration.ApiClient.RestClient.BaseUrl, new Uri(newApiClientUrl)); }
public void TestGetPetByIdInObject() { // set timeout to 10 seconds Configuration c1 = new Configuration(timeout: 10000); PetApi petApi = new PetApi(c1); InlineResponse200 response = petApi.GetPetByIdInObject(petId); Assert.IsInstanceOf <InlineResponse200> (response, "Response is a Pet"); Assert.AreEqual("Csharp test", response.Name); Assert.AreEqual(InlineResponse200.StatusEnum.Available, response.Status); Assert.IsInstanceOf <List <Tag> > (response.Tags, "Response.Tags is a Array"); Assert.AreEqual(petId, response.Tags [0].Id); Assert.AreEqual("csharp sample tag name1", response.Tags [0].Name); Assert.IsInstanceOf <List <String> > (response.PhotoUrls, "Response.PhotoUrls is a Array"); Assert.AreEqual("sample photoUrls", response.PhotoUrls [0]); Assert.IsInstanceOf <Newtonsoft.Json.Linq.JObject> (response.Category, "Response.Category is a Newtonsoft.Json.Linq.JObject"); Newtonsoft.Json.Linq.JObject category = (Newtonsoft.Json.Linq.JObject)response.Category; Assert.AreEqual(56, (int)category ["id"]); Assert.AreEqual("sample category name2", (string)category["name"]); }
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(); Configuration c2 = new Configuration(a1); // using "a1" as the ApiClient 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); // ensure both using the same default ApiClient Assert.AreSame(p3.Configuration.ApiClient, c1.ApiClient); Assert.AreSame(p3.Configuration.ApiClient, Configuration.Default.ApiClient); // ensure it's not using the default ApiClient Assert.AreSame(p4.Configuration.ApiClient, c2.ApiClient); Assert.AreNotSame(p4.Configuration.ApiClient, Configuration.Default.ApiClient); }
public void GetPetByIdTest() { // set timeout to 10 seconds Configuration c1 = new Configuration(); c1.Timeout = 10000; c1.UserAgent = "TEST_USER_AGENT"; PetApi petApi = new PetApi(c1); Pet response = petApi.GetPetById(petId); Assert.IsInstanceOf(typeof(Pet), response); Assert.AreEqual("Csharp test", response.Name); Assert.AreEqual(Pet.StatusEnum.Available, response.Status); Assert.IsInstanceOf(typeof(List <Tag>), response.Tags); Assert.AreEqual(petId, response.Tags[0].Id); Assert.AreEqual("csharp sample tag name1", response.Tags[0].Name); Assert.IsInstanceOf(typeof(List <String>), response.PhotoUrls); Assert.AreEqual("sample photoUrls", response.PhotoUrls[0]); Assert.IsInstanceOf(typeof(Category), response.Category); Assert.AreEqual(56, response.Category.Id); Assert.AreEqual("sample category name2", response.Category.Name); }
public void TestGetPetByIdWithHttpInfoAsync() { PetApi petApi = new PetApi(); var task = petApi.GetPetByIdWithHttpInfoAsync(petId); Assert.Equal(200, (int)task.Result.StatusCode); Assert.True(task.Result.Headers.ContainsKey("Content-Type")); Assert.Equal("application/json", task.Result.Headers["Content-Type"][0]); Pet response = task.Result.Data; Assert.IsType <Pet>(response); Assert.Equal("Csharp test", response.Name); Assert.Equal(Pet.StatusEnum.Available, response.Status); Assert.IsType <List <Tag> >(response.Tags); Assert.Equal(petId, response.Tags[0].Id); Assert.Equal("csharp sample tag name1", response.Tags[0].Name); Assert.IsType <List <String> >(response.PhotoUrls); Assert.Equal("sample photoUrls", response.PhotoUrls[0]); Assert.IsType <Category>(response.Category); Assert.Equal(56, response.Category.Id); Assert.Equal("sample category name2", response.Category.Name); }
public void TestGetPetByIdAsyncWithHttpInfo() { PetApi petApi = new PetApi(); var task = petApi.GetPetByIdAsyncWithHttpInfo(petId); Assert.AreEqual(200, task.Result.StatusCode); Assert.IsTrue(task.Result.Headers.ContainsKey("Content-Type")); Assert.AreEqual(task.Result.Headers["Content-Type"], "application/json"); Pet response = task.Result.Data; Assert.IsInstanceOf(typeof(Pet), response); Assert.AreEqual("Csharp test", response.Name); Assert.AreEqual(Pet.StatusEnum.Available, response.Status); Assert.IsInstanceOf(typeof(List <Tag>), response.Tags); Assert.AreEqual(petId, response.Tags[0].Id); Assert.AreEqual("csharp sample tag name1", response.Tags[0].Name); Assert.IsInstanceOf(typeof(List <String>), response.PhotoUrls); Assert.AreEqual("sample photoUrls", response.PhotoUrls[0]); Assert.IsInstanceOf(typeof(Category), response.Category); Assert.AreEqual(56, response.Category.Id); Assert.AreEqual("sample category name2", response.Category.Name); }
[SetUp] public void Init() { // create pet Pet p = new Pet(); p.Id = petId; p.Name = "Csharp test"; p.Status = "available"; // create Category object Category category = new Category(); category.Id = 56; category.Name = "sample category name2"; List <String> photoUrls = new List <String>(new String[] { "sample photoUrls" }); // create Tag object Tag tag = new Tag(); tag.Id = petId; tag.Name = "sample tag name1"; List <Tag> tags = new List <Tag>(new Tag[] { tag }); p.Tags = tags; p.Category = category; p.PhotoUrls = photoUrls; // add pet before testing PetApi petApi = new PetApi("http://petstore.swagger.io/v2/"); petApi.AddPet(p); }
public void Cleanup() { // remove the pet after testing PetApi petApi = new PetApi(); petApi.DeletePet(petId, "test key"); }
public void TestGetPetByIdAsyncWithHttpInfo() { PetApi petApi = new PetApi(); var task = petApi.GetPetByIdAsyncWithHttpInfo(petId); Assert.AreEqual(200, task.Result.StatusCode); Assert.IsTrue(task.Result.Headers.ContainsKey("Content-Type")); Assert.AreEqual(task.Result.Headers["Content-Type"], "application/json"); Pet response = task.Result.Data; Assert.IsInstanceOf <Pet> (response, "Response is a Pet"); Assert.AreEqual("Csharp test", response.Name); Assert.AreEqual("available", response.Status); Assert.IsInstanceOf <List <Tag> > (response.Tags, "Response.Tags is a Array"); Assert.AreEqual(petId, response.Tags [0].Id); Assert.AreEqual("csharp sample tag name1", response.Tags [0].Name); Assert.IsInstanceOf <List <String> > (response.PhotoUrls, "Response.PhotoUrls is a Array"); Assert.AreEqual("sample photoUrls", response.PhotoUrls [0]); Assert.IsInstanceOf <Category> (response.Category, "Response.Category is a Category"); Assert.AreEqual(56, response.Category.Id); Assert.AreEqual("sample category name2", response.Category.Name); }
public void GetPetByIdTest() { // set timeout to 10 seconds Configuration c1 = new Configuration(); c1.Timeout = 10000; c1.UserAgent = "TEST_USER_AGENT"; HttpClient httpClient = new HttpClient(); HttpClientHandler httpClientHandler = new HttpClientHandler(); PetApi petApi = new PetApi(httpClient, c1, httpClientHandler); Pet response = petApi.GetPetById(petId); Assert.IsType <Pet>(response); Assert.Equal("Csharp test", response.Name); Assert.Equal(Pet.StatusEnum.Available, response.Status); Assert.IsType <List <Tag> >(response.Tags); Assert.Equal(petId, response.Tags[0].Id); Assert.Equal("csharp sample tag name1", response.Tags[0].Name); Assert.IsType <List <String> >(response.PhotoUrls); Assert.Equal("sample photoUrls", response.PhotoUrls[0]); Assert.IsType <Category>(response.Category); Assert.Equal(56, response.Category.Id); Assert.Equal("sample category name2", response.Category.Name); }
public void TestUploadFile() { PetApi petApi = new PetApi(); //NOTE: please provide a valid file (full path) FileStream fileStream = new FileStream("/var/tmp/small.gif", FileMode.Open); petApi.UploadFile(petId, "new form name", fileStream); }
public void TestStatusCodeAndHeader() { PetApi petApi = new PetApi(); var response = petApi.GetPetByIdWithHttpInfo(petId); Assert.AreEqual(response.StatusCode, 200); Assert.IsTrue(response.Headers.ContainsKey("Content-Type")); Assert.AreEqual(response.Headers["Content-Type"], "application/json"); }
public void TestDefaultHeader() { PetApi petApi = new PetApi(); // there should be a warning for using AddDefaultHeader (deprecated) below petApi.AddDefaultHeader("header_key", "header_value"); // the following should be used instead as suggested in the doc petApi.Configuration.AddDefaultHeader("header_key2", "header_value2"); }
public void TestBasePath() { PetApi p = new PetApi("http://new-basepath.com"); Assert.AreEqual(p.Configuration.ApiClient.RestClient.BaseUrl, "http://new-basepath.com"); // Given that PetApi is initailized with a base path, a new configuration (with a new ApiClient) // is created by default Assert.AreNotSame(p.Configuration, Configuration.Default); }
public void TestDefaultHeader() { PetApi petApi = new PetApi(); // commented out the warning test below as it's confirmed the warning is working as expected // there should be a warning for using AddDefaultHeader (deprecated) below //petApi.AddDefaultHeader ("header_key", "header_value"); // the following should be used instead as suggested in the doc petApi.Configuration.AddDefaultHeader("header_key2", "header_value2"); }
[SetUp] public void Init() { // create pet Pet p = createPet(); // add pet before testing PetApi petApi = new PetApi("http://petstore.swagger.io/v2/"); petApi.AddPet(p); }
public void TestGetPetByIdWithByteArray() { // set timeout to 10 seconds Configuration c1 = new Configuration(timeout: 10000); PetApi petApi = new PetApi(c1); byte[] response = petApi.PetPetIdtestingByteArraytrueGet(petId); Assert.IsInstanceOf <byte[]> (response, "Response is byte array"); }
public void TestStatusCodeAndHeader() { PetApi petApi = new PetApi(); var response = petApi.GetPetByIdWithHttpInfo(petId); //Assert.Equal("OK", response.StatusCode); Assert.Equal(200, (int)response.StatusCode); Assert.True(response.Headers.ContainsKey("Content-Type")); Assert.Equal("application/json", response.Headers["Content-Type"][0]); }
public void TestAddPetUsingByteArray() { // set timeout to 10 seconds Configuration c1 = new Configuration(timeout: 10000); PetApi petApi = new PetApi(c1); Pet p = createPet(); byte[] petByteArray = GetBytes((string)petApi.Configuration.ApiClient.Serialize(p)); petApi.AddPetUsingByteArray(petByteArray); }
public void UploadFileTest() { Assembly _assembly = Assembly.GetExecutingAssembly(); Stream _imageStream = _assembly.GetManifestResourceStream("Org.OpenAPITools.Test.linux-logo.png"); PetApi petApi = new PetApi(); // test file upload with form parameters //petApi.UploadFile(petId, "new form name", _imageStream); // test file upload without any form parameters // using optional parameter syntax introduced at .net 4.0 //petApi.UploadFile(petId: petId, file: _imageStream); }
public void TestUploadFile() { PetApi petApi = new PetApi(); //NOTE: please provide a valid file (full path) FileStream fileStream = new FileStream("/var/tmp/small.gif", FileMode.Open); // test file upload with form parameters petApi.UploadFile(petId, "new form name", fileStream); // test file upload without any form parameters petApi.UploadFile(petId, null, fileStream); }
public PetApiTests() { instance = new PetApi(); // create pet Pet p = createPet(); // add pet before testing PetApi petApi = new PetApi("http://petstore.swagger.io/v2/"); petApi.AddPet(p); }
public void TestFindPetByStatus() { PetApi petApi = new PetApi(); List <String> statusList = new List <String>(new String[] { "available" }); List <Pet> listPet = petApi.FindPetsByStatus(statusList); foreach (Pet pet in listPet) // Loop through List with foreach. { Assert.IsInstanceOf <Pet> (pet, "Response is a Pet"); Assert.AreEqual("available", pet.Status); } }
public void FindPetsByStatusTest() { PetApi petApi = new PetApi(); List <String> tagsList = new List <String>(new String[] { "available" }); List <Pet> listPet = petApi.FindPetsByTags(tagsList); foreach (Pet pet in listPet) // Loop through List with foreach. { Assert.IsInstanceOf(typeof(Pet), pet); Assert.AreEqual("csharp sample tag name1", pet.Tags[0]); } }
public void TestUploadFile() { Assembly _assembly = Assembly.GetExecutingAssembly(); Stream _imageStream = _assembly.GetManifestResourceStream("SwaggerClientTest.swagger-logo.png"); PetApi petApi = new PetApi(); // test file upload with form parameters petApi.UploadFile(petId, "new form name", _imageStream); // test file upload without any form parameters // using optional parameter syntax introduced at .net 4.0 petApi.UploadFile(petId: petId, file: _imageStream); }
public void TestUploadFile() { PetApi petApi = new PetApi(); //NOTE: please provide a valid file (full path) FileStream fileStream = new FileStream("/var/tmp/small.gif", FileMode.Open); // test file upload with form parameters petApi.UploadFile(petId, "new form name", fileStream); // test file upload without any form parameters // using optional parameter syntax introduced at .net 4.0 petApi.UploadFile(petId: petId, file: fileStream); }
public void TestFindPetByTags() { PetApi petApi = new PetApi(); List <String> tagsList = new List <String>(new String[] { "available" }); List <Pet> listPet = petApi.FindPetsByTags(tagsList); foreach (Pet pet in listPet) // Loop through List with foreach. { Assert.IsInstanceOf <Pet> (pet, "Response is a Pet"); Assert.AreEqual("csharp sample tag name1", pet.Tags[0]); } }
public void FindPetsByStatusTest() { PetApi petApi = new PetApi(); List <String> tagsList = new List <String>(new String[] { "available" }); List <Pet> listPet = petApi.FindPetsByTags(tagsList); foreach (Pet pet in listPet) // Loop through List with foreach. { Assert.IsType <Pet>(pet); Assert.Equal("available", pet.Tags[0].Name); } }
public void TestGetPetById_TestException() { PetApi petApi = new PetApi(); var exception = Assert.Throws <ApiException>(() => { petApi.GetPetById(notExsistentPetId); }); Assert.IsType <ApiException>(exception); Assert.Equal(404, exception.ErrorCode); Assert.Equal("{\"code\":1,\"type\":\"error\",\"message\":\"Pet not found\"}", exception.ErrorContent); Assert.Equal("Error calling GetPetById: {\"code\":1,\"type\":\"error\",\"message\":\"Pet not found\"}", exception.Message); }
public void TestApiClientInstance() { PetApi p1 = new PetApi(); PetApi p2 = new PetApi(); Configuration c1 = new Configuration(); // using default ApiClient PetApi p3 = new PetApi(c1); // ensure both using the same default ApiClient Assert.AreSame(p1.Configuration.ApiClient, p2.Configuration.ApiClient); Assert.AreSame(p1.Configuration.ApiClient, Configuration.Default.ApiClient); // ensure both using the same default ApiClient Assert.AreSame(p3.Configuration.ApiClient, c1.ApiClient); }