Represents a collection of functions to interact with the API endpoints
Inheritance: IPetApi
Beispiel #1
0
		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 ("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);

		}
Beispiel #2
0
 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);
		}
Beispiel #4
0
 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");
 }
Beispiel #5
0
        public void Init()
        {
            // create pet
            Pet p = createPet();

            // add pet before testing
            PetApi petApi = new PetApi("http://petstore.swagger.io/v2/");
            petApi.AddPet (p);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
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.IsInstanceOf<Pet> (pet, "Response is a Pet");
                Assert.AreEqual ("csharp sample tag name1", pet.Tags[0]);
            }
        }
        public void TestDefautlConfiguration()
        {
            PetApi p1 = new PetApi ();
            PetApi p2 = new PetApi ();
            Assert.AreSame (p1.Configuration, p2.Configuration);
            // same as the default
            Assert.AreSame (p1.Configuration, Configuration.Default);

            Configuration c = new Configuration ();
            Assert.AreNotSame (c, p1.Configuration);

            PetApi p3 = new PetApi (c);
            // same as c
            Assert.AreSame (p3.Configuration, c);
            // not same as default
            Assert.AreNotSame (p3.Configuration, p1.Configuration);
        }
Beispiel #10
0
        public void TestGetPetById()
        {
            PetApi petApi = new PetApi ();
            Pet response = petApi.GetPetById (petId);
            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 ("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 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 ApiClient
            ApiClient a1 = new ApiClient ("http://new-api-client.com");
            Configuration c2 = new Configuration (a1);
            PetApi p4 = new PetApi (c2);
            Assert.AreSame (p4.Configuration.ApiClient, a1);
        }
Beispiel #12
0
        public void UpdatePetWithFormTest()
        {
			PetApi petApi = new PetApi ();
			petApi.UpdatePetWithForm (petId, "new form name", "pending");

			Pet response = petApi.GetPetById (petId);
			Assert.IsInstanceOfType(typeof(Pet), response, "Response is a Pet");
			Assert.IsInstanceOfType(typeof(Category), response.Category, "Response.Category is a Category");
			Assert.IsInstanceOfType(typeof(List<Tag>), response.Tags, "Response.Tags is a Array");

			Assert.AreEqual ("new form name", response.Name);
			Assert.AreEqual (Pet.StatusEnum.Pending, response.Status);

			Assert.AreEqual (petId, response.Tags [0].Id);
			Assert.AreEqual (56, response.Category.Id);

			// test optional parameter
			petApi.UpdatePetWithForm (petId, "new form name2");
			Pet response2 = petApi.GetPetById (petId);
			Assert.AreEqual ("new form name2", response2.Name);           
        }
Beispiel #13
0
        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");
        }
Beispiel #14
0
 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);
 }
Beispiel #15
0
 public void Cleanup()
 {
     // remove the pet after testing
     PetApi petApi = new PetApi ();
     petApi.DeletePet(petId, "test key");
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        public void TestUpdatePetWithForm()
        {
            PetApi petApi = new PetApi ();
            petApi.UpdatePetWithForm (petId.ToString(), "new form name", "pending");

            Pet response = petApi.GetPetById (petId);
            Assert.IsInstanceOf<Pet> (response, "Response is a Pet");
            Assert.IsInstanceOf<Category> (response.Category, "Response.Category is a Category");
            Assert.IsInstanceOf<List<Tag>> (response.Tags, "Response.Tags is a Array");

            Assert.AreEqual ("new form name", response.Name);
            Assert.AreEqual ("pending", response.Status);

            Assert.AreEqual (petId, response.Tags [0].Id);
            Assert.AreEqual (56, response.Category.Id);
        }
Beispiel #18
0
        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 TestGetPetById()
        {
            // set timeout to 10 seconds
            Configuration c1 = new Configuration (timeout: 10000);

            PetApi petApi = new PetApi (c1);
            Pet response = petApi.GetPetById (petId);
            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);
        }
Beispiel #20
0
        public void GetPetByIdTest()
        {
			// set timeout to 10 seconds
			Configuration c1 = new Configuration (timeout: 10000, userAgent: "TEST_USER_AGENT");

			PetApi petApi = new PetApi (c1);
			Pet response = petApi.GetPetById (petId);
			Assert.IsInstanceOfType(typeof(Pet), response, "Response is a Pet");

			Assert.AreEqual ("Csharp test", response.Name);
			Assert.AreEqual (Pet.StatusEnum.Available, response.Status);

			Assert.IsInstanceOfType(typeof(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.IsInstanceOfType(typeof(List<String>), response.PhotoUrls, "Response.PhotoUrls is a Array");
			Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);

			Assert.IsInstanceOfType(typeof(Category), response.Category, "Response.Category is a Category");
			Assert.AreEqual (56, response.Category.Id);
			Assert.AreEqual ("sample category name2", response.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);

		}
Beispiel #22
0
		public void TestGetPetByIdAsync ()
		{
			PetApi petApi = new PetApi ();
			var task = petApi.GetPetByIdAsync (petId);
			Pet response = task.Result;
			Assert.IsInstanceOfType(typeof(Pet), response, "Response is a Pet");

			Assert.AreEqual ("Csharp test", response.Name);
			Assert.AreEqual (Pet.StatusEnum.Available, response.Status);

			Assert.IsInstanceOfType(typeof(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.IsInstanceOfType(typeof(List<String>), response.PhotoUrls, "Response.PhotoUrls is a Array");
			Assert.AreEqual ("sample photoUrls", response.PhotoUrls [0]);

			Assert.IsInstanceOfType(typeof(Category), response.Category, "Response.Category is a Category");
			Assert.AreEqual (56, response.Category.Id);
			Assert.AreEqual ("sample category name2", response.Category.Name);

		}
 public void Init()
 {
     instance = new PetApi();
 }
Beispiel #24
0
        public void UploadFileTest()
        {
			Assembly _assembly = Assembly.GetExecutingAssembly();
			Stream _imageStream = _assembly.GetManifestResourceStream("IO.Swagger.Test.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);

        }
Beispiel #25
0
		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");
		}
Beispiel #26
0
        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"]);
        }
Beispiel #27
-1
        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);
        }