void TestCategory() { System.Console.Write("Test - Category"); try { // GET all RESTOptions <Category> optionsCategory = new RESTOptions <Category>(); List <Category> categoryList = this.conn.GetObjects <Category>(optionsCategory); Category category = categoryList[0]; // PUT test, no need to retain returned object string newCategoryOriginalName = category.Name; category.Name = "REST Test Category rename"; this.conn.SendObject <Category>(category); // GET to verify PUT Category getCategory = this.conn.GetObject <Category>(category.Id, optionsCategory); Debug.Assert(getCategory.Name == "REST Test Category rename"); category.Name = newCategoryOriginalName; this.conn.SendObject <Category>(category); } catch (Exception e) { System.Console.WriteLine(": FAIL"); System.Console.WriteLine("Error:"); System.Console.WriteLine(e); System.Console.WriteLine("---------------------"); return; } System.Console.WriteLine(": OK"); }
public bool AttachHeroImage(File file, Project project) { Console.Write("Marking file as HeroImage: "); RESTOptions <File> _file = new RESTOptions <File>(); project.HeroImageId = file.Id; Project resp = this.conn.SendObject <Project>(project, false); return(true); }
// Initiates the test public void init() { //RESTOptions<Project> pOptions = new RESTOptions<Project>(); //List<Project> emProjects = this.conn.GetObjects<Project>(5, BaseNoun.GetNoun(typeof(Employee)), pOptions); //pOptions.SetSearchParameter("fields", "all"); //Project project = this.conn.GetObject<Project>(1, pOptions); RESTOptions <Employee> eOptions = new RESTOptions <Employee>(); eOptions.IfModifiedSince = DateTime.Parse("Tue, 27 Oct 2015 12:49:00 GMT"); Employee employee = this.conn.GetObject <Employee>(5, eOptions); //List<Employee> employees = this.conn.GetObjects<Employee>(options); //List<Category> categories1 = this.conn.GetObjects<Category>(options); //List<Category> categories2 = this.conn.GetObjects<Category>(options); System.Console.WriteLine("Recovered employee"); }
void TestResult(int id, int count) { System.Console.Write("Test - Result"); try { RESTOptions <Result> options = new RESTOptions <Result>(); List <Result> itemList = this.conn.GetObjects <Result>(id, "Searches", options); Debug.Assert(itemList.Count == count); } catch (Exception e) { System.Console.WriteLine(": FAIL"); System.Console.WriteLine("Error:"); System.Console.WriteLine(e); System.Console.WriteLine("---------------------"); } }
void TestFieldLookupString(int id) { System.Console.Write("Test - FieldLookupString"); try { RESTOptions <FieldLookupString> options = new RESTOptions <FieldLookupString>(); options.AddDisplayField("field_id"); options.SetSearchParameter("id", id.ToString()); List <FieldLookupString> nestedFieldLookupString = this.conn.GetObjects <FieldLookupString>(id, "Fields", options); } catch (Exception e) { System.Console.WriteLine(": Fail"); System.Console.WriteLine("Error:"); System.Console.WriteLine(e); System.Console.WriteLine("--------------------"); } System.Console.WriteLine(": OK"); }
// Generic test for Nounds that only support GET void TestGet <T>(string testName, int numberToAssert) where T : OpenAsset.RestClient.Library.Noun.Base.BaseNoun, new() { System.Console.Write("Test - " + testName); try { RESTOptions <T> options = new RESTOptions <T>(); List <T> list = this.conn.GetObjects <T>(options); // some sort of check if (numberToAssert >= 0) { Debug.Assert(list.Count == numberToAssert); } } catch (Exception e) { System.Console.WriteLine(": FAIL"); System.Console.WriteLine("Error:"); System.Console.WriteLine(e); System.Console.WriteLine("---------------------"); return; } System.Console.WriteLine(": OK"); }
// Verifies that each search brought a result that includes the uploaded file public bool VerifySearches(List <Search> searchList, File file) { Console.WriteLine("Verifying Searches: "); RESTOptions <Result> options; List <Result> itemList; Search currSearch; bool fileFound = false; foreach (Search search in searchList) { Console.Write("\t" + search.SearchItems[0].Code + ": "); currSearch = this.conn.SendObject <Search>(search, true); options = new RESTOptions <Result>(); itemList = this.conn.GetObjects <Result>(currSearch.Id, "Searches", options); fileFound = false; foreach (Result result in itemList) { if (result.FileId == file.Id) { Console.WriteLine("GOOD"); fileFound = true; break; } } if (!fileFound) { throw new Exception("File search not found for " + currSearch.Code + " (" + currSearch.Id + ")"); } } Console.WriteLine("Verification Passed"); return(true); }
// Generic test for Nouns that support all verbs void Test <T>(string testName, Func <T> setup, Func <T, T> modify, Func <T, T, bool> compare, bool post, bool delete, string args = "") where T : OpenAsset.RestClient.Library.Noun.Base.BaseNoun, new() { System.Console.Write("Test - " + testName); try { RESTOptions <T> options = new RESTOptions <T>(); // GET All List <T> startList = this.conn.GetObjects <T>(options); T newInstance = setup(); if (post) { // POST Test T postInstance; if (testName == "File") { postInstance = this.conn.SendObject <T>(newInstance, args, true); } else { postInstance = this.conn.SendObject <T>(newInstance, true); } newInstance.Id = postInstance.Id; } else { newInstance = startList[startList.Count - 1]; } // Verify with a single GET T getInstance = this.conn.GetObject <T>(newInstance.Id, options); Debug.Assert(compare(newInstance, getInstance)); if (post) { // Verify all on server side List <T> postList = this.conn.GetObjects <T>(options); Debug.Assert(postList.Count == startList.Count + 1); } // PUT Test newInstance = modify(newInstance); T putInstance = this.conn.SendObject(newInstance, false); putInstance = this.conn.GetObject <T>(newInstance.Id, options); Debug.Assert(compare(getInstance, putInstance) == false); // DELETE Test if (delete) { this.conn.DeleteObject <T>(newInstance.Id); } } catch (Exception e) { System.Console.WriteLine(": FAIL"); System.Console.WriteLine("Error:"); System.Console.WriteLine(e); System.Console.WriteLine("---------------------"); return; } System.Console.WriteLine(": OK"); }
// Override this method to give custom control of RESTOptions based on Noun public virtual RESTOptions <T> GetRESTOptions <T>() where T : Noun.Base.BaseNoun { RESTOptions <T> options = new RESTOptions <T>(); return(options); }