public void RunQueryTest_GetJsonFromSqlTest_SQLServerOffline() { // arrange string jsonResult = string.Empty; GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java" })); gitHubApiQuery.MillisecondsToWait = 10000; // Adjust for LAN service access. gitHubApiQuery.ApiItemsPerPage = 5; gitHubApiQuery.ApiPages = 1; gitHubApiQuery.RunQuery(); jsonResult = gitHubApiQuery.GetJsonFromSql(); Assert.IsTrue(string.IsNullOrEmpty(jsonResult), "\n\nPara este teste passar o SQL Server deve estar indisponível.\n"); } catch (Exception ex) { Assert.Fail(ex.Message, ex); } // assert Assert.IsTrue(string.IsNullOrEmpty(jsonResult)); }
public void RunQueryTest_GitHubApiOffline_Exception() { // arrange GitHubApiQuery gitHubApiQuery = null; string gitHubApiResult = string.Empty; // act try { gitHubApiQuery = new GitHubApiQuery("Java"); gitHubApiResult = gitHubApiQuery.RunQuery(); if (!string.IsNullOrEmpty(gitHubApiResult)) { Assert.IsTrue(string.IsNullOrEmpty(gitHubApiResult), "\nO serviço GitHubApi tem que estar fora do ar para este teste passar\nDesconecte-se da internet."); } } catch (Exception ex) { Assert.Fail(ex.Message, ex); } // assert Assert.IsTrue(string.IsNullOrEmpty(gitHubApiResult)); }
public void RunQueryTest_GetJsonFromSqlTest_SQLServerOnline() { // arrange List <string> languages = new List <string>(new string[] { "Java", "C", "Python", "C++", "C#" }); string jsonResult = string.Empty; GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(languages); gitHubApiQuery.MillisecondsToWait = 100000; // Adjust for LAN service access. gitHubApiQuery.ApiItemsPerPage = 5; gitHubApiQuery.ApiPages = 1; gitHubApiQuery.RunQuery(); jsonResult = gitHubApiQuery.GetJsonFromSql(); } catch (Exception ex) { Assert.Fail(ex.Message, ex); } // assert Assert.IsFalse(string.IsNullOrEmpty(jsonResult)); }
public void RunQueryTest_HttpRequest_TimeOutException() { // arrange bool throwException = false; bool throwTimeOutException = false; string result = string.Empty; GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java"); gitHubApiQuery.MillisecondsToWait = 500; // act try { result = gitHubApiQuery.RunQuery(); if (string.IsNullOrEmpty(result)) { throwException = true; throwTimeOutException = true; } } // // HttpClient take care about TimeoutException so TaskCanceledException should be used instead. // Keep this code here things may change in the future. // catch (TimeoutException) { throwException = true; throwTimeOutException = true; } // assert Assert.IsTrue(throwException && throwTimeOutException); }
public void RunQueryTest_WithValidLanguageName() { // arrange string queryResult = string.Empty; GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java"); // act queryResult = gitHubApiQuery.RunQuery(); // assert Assert.IsFalse(string.IsNullOrEmpty(queryResult)); }
public void RunQueryTest_GetItemsTest_EmptyObjectListFromJson() { // arrange GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(""); gitHubApiQuery.RunQuery(); } catch (ArgumentException) { gitHubApiQuery = null; } // assert Assert.IsTrue(gitHubApiQuery == null); }
public void RunQueryTest_GetItemsTest_NotEmptyObjectListFromJson() { // arrange string jsonResult = string.Empty; GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java", "C", "Python", "C++", "C#" })); gitHubApiQuery.MillisecondsToWait = 100000; // Adjust for LAN service access. jsonResult = gitHubApiQuery.RunQuery(); } catch (Exception ex) { Assert.Fail(ex.Message, ex); } // assert Assert.IsFalse(gitHubApiQuery == null && string.IsNullOrEmpty(jsonResult)); }
public HttpResponseMessage GitHubQuery() { // arrange string jsonResult = string.Empty; GitHubApiQuery gitHubApiQuery = null; //Requester info - Just to log - Later a cache control may be implemented. //var ip = HttpRequestMessageExtensions.GetClientIpAddress(this.Request); // act try { gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java", "C", "Python", "C++", "C#" })); gitHubApiQuery.ApiItemsPerPage = 5; gitHubApiQuery.ApiPages = 1; gitHubApiQuery.RunQuery(); jsonResult = gitHubApiQuery.GetJsonFromSql(); } catch (FileLoadException) { // Ignore - Debug exception. } catch (Exception) { // Serviço não está ativo. //throw new Exception(ex.Message, ex); return(null); } HttpResponseMessage resp = new HttpResponseMessage { Content = new StringContent(jsonResult, System.Text.Encoding.UTF8, "application/json") }; return(resp); }