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_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_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_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 GitHubQuery_PingLocal_Test() { //Arrange bool result = false; //Act result = GitHubApiQuery.CheckByPing("127.0.0.1", 2000); //Assert Assert.IsTrue(result); }
public void GitHubQuery_PingWEB_Test() { //Arrange bool result = false; //Act result = GitHubApiQuery.CheckByPing("8.8.8.8", 2000); //Assert Assert.IsTrue(result); }
public void GitHubQuery_PingNoHost_Test() { //Arrange bool result = false; //Act result = GitHubApiQuery.CheckByPing(""); //Assert Assert.IsFalse(result); }
public void GitHubQuery_PingHostName_Test() { //Arrange bool result = false; //Act result = GitHubApiQuery.CheckByPing("www.google.com"); //Assert Assert.IsTrue(result); }
public void GitHubQuery_PingAssert_Test() { //Arrange bool result = false; //Act result = GitHubApiQuery.CheckByPing("127.0.0.1", -1); //Assert Assert.IsFalse(result); }
public void RunQueryTest_ApiQueryMinStars() { // arrange int apiResult = 1000; GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java"); // act gitHubApiQuery.ApiQueryMinStars = apiResult; // assert Assert.IsTrue(apiResult == gitHubApiQuery.ApiQueryMinStars); }
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_GetApiOrderCommand() { // arrange string apiResult = string.Empty; GitHubApiQuery gitHubApiQuery = new GitHubApiQuery("Java"); // act apiResult = gitHubApiQuery.GetApiOrderCommand(); // assert Assert.IsFalse(apiResult == string.Empty); }
public void RunQueryTest_WhiteSpaceLanguageName_Exception() { // arrange bool throwArgumentException = false; // act try { GitHubApiQuery gitHubApiQuery = new GitHubApiQuery(" "); } catch (Exception ex) { throwArgumentException = ex is ArgumentException; } // assert Assert.IsTrue(throwArgumentException); }
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_GitHubApiQuery_EmptyListString() { // arrange List <string> languages = new List <string>(); GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(languages); } catch (ArgumentException) { return; } // assert Assert.Fail(); }
public void RunQueryTest_HttpRequest_Exception() { // arrange bool throwException = false; bool throwArgumentException = false; GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(""); } catch (Exception ex) { throwException = true; throwArgumentException = ex is ArgumentException; } // assert Assert.IsTrue(throwException && throwArgumentException); }
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 void ApiVersion_JustToCoverability_Test() { // arrange string apiVersion = string.Empty; GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java" })); apiVersion = gitHubApiQuery.ApiVersion; gitHubApiQuery.ApiVersion = apiVersion; } catch (Exception ex) { Assert.Fail(ex.Message, ex); } // assert Assert.IsFalse(string.IsNullOrEmpty(apiVersion)); }
public void CheckGitWebApiAccess_JustToCoverability_Test() { // arrange bool result = false; GitHubApiQuery gitHubApiQuery = null; // act try { gitHubApiQuery = new GitHubApiQuery(new List <string>(new string[] { "Java" })); gitHubApiQuery.CheckGitWebApiAccess(); result = true; } catch (Exception ex) { Assert.Fail(ex.Message, ex); } // assert Assert.IsTrue(result); }
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); }