public void should_Return_Exception_When_InvalidJSON() { string apiKey = ConfigurationManager.AppSettings["APIKey"]; String url = "http://search.twitter.com/search.{1}?q=hello"; APIReader apiReader = new APIReader(url, apiKey, APIReader.outputFormat.JSON); String result = apiReader.getFetchedResults(); string json = apiReader.executeURL(); json = json + "xxxxx"; Assert.IsFalse(apiReader.IsValidJSON(json)); }
public void should_Fetch_Data_As_XML_When_API_URL_Is_Passed_In_Invalid() { string apiKey = ConfigurationManager.AppSettings["APIKey"]; String url = "http://www.muzu.tv/api/browse?muzuid={0}&af=a&g=pop&format={1}"; //"http://search.twitter.com/search.{0}?q=hello"; APIReader apiReader = new APIReader(url, apiKey, APIReader.outputFormat.XML); string expected = "http://www.muzu.tv/api/browse?muzuid=" + apiKey + "&af=a&g=pop&format=xml"; String result = apiReader.getFetchedResults(); string xml = apiReader.executeURL(); xml = xml + "xxxx"; Assert.AreEqual(expected, result); Assert.AreEqual(false, apiReader.IsValidXML(xml)); }
public void should_Return_Data_As_Valid_JSON_When_API_URL_Is_Passed_In() { string apiKey = ConfigurationManager.AppSettings["APIKey"]; String url = "http://search.twitter.com/search.{1}?q=hello"; APIReader apiReader = new APIReader(url, apiKey, APIReader.outputFormat.JSON); String result = apiReader.getFetchedResults(); string json = apiReader.executeURL(); JavaScriptSerializer ser = new JavaScriptSerializer(); var valid = ser.Deserialize<object>(json); Assert.IsNotNull(valid); }
public void should_Fetch_Data_As_JSON_When_API_URL_Is_Passed_In() { string json = ""; JavaScriptSerializer ser = new JavaScriptSerializer(); var xx = ser.Deserialize<object>(json); string apiKey = ConfigurationManager.AppSettings["APIKey"]; String url = "http://search.twitter.com/search.{1}?q=hello"; APIReader apiReader = new APIReader(url, apiKey, APIReader.outputFormat.JSON); String result = apiReader.getFetchedResults(); Assert.AreEqual("http://search.twitter.com/search.json?q=hello", result); }