public void GitHubQueryJsonResultTests_JustToCoverability_Test() { // arrange GitHubQueryJsonResult gitHubQueryJsonResult = new GitHubQueryJsonResult(); bool incomplete_results = false; int total_count = 0; List <Item> Items = new List <Item>(); // Act gitHubQueryJsonResult.incomplete_results = incomplete_results; gitHubQueryJsonResult.total_count = total_count; gitHubQueryJsonResult.Items = Items; incomplete_results = gitHubQueryJsonResult.incomplete_results; total_count = gitHubQueryJsonResult.total_count; Items = gitHubQueryJsonResult.Items; // Assert Assert.IsTrue(gitHubQueryJsonResult.incomplete_results == incomplete_results || gitHubQueryJsonResult.total_count == total_count || gitHubQueryJsonResult.Items == Items); }
/**********************************************************************************************//** * \fn public string RunQuery() * * \brief Executes the query operation * * \author Delmiro Paes * * \exception TimeoutException Thrown when a Timeout error condition occurs. * * \returns A string. **************************************************************************************************/ public string RunQuery() { List <Item> Items = new List <Item>(); string queryResultString = String.Empty; List <Tuple <string, Task <string> > > languageTaskTuples = new List <Tuple <string, Task <string> > >(); try { foreach (string language in _languages) { Tuple <string, Task <string> > tupleLanguageTask = new Tuple <string, Task <string> >(language, RunQuery(language)); languageTaskTuples.Add(tupleLanguageTask); } // // Slow but make me appear smart. // TODO: Use an auxiliary class. Task.WaitAll(languageTaskTuples.FindAll(x => x.Item2 != null).Select(x => x.Item2).ToArray()); } catch (AggregateException ae) { bool timeout = false; if (ae.InnerExceptions.Count == 1 && ae.InnerExceptions[0].InnerException is TaskCanceledException) { timeout = true; } else { // //TODO: Find a better way to do this. Remove Lambda for better test coverability. // ae.Handle(x => { // // Put some errors as timeout error. // if (x is TimeoutException || x is TaskCanceledException || x is HttpRequestException || x is OperationCanceledException) // This we know how to handle. { timeout = true; return(true); } //TODO: Check this! TRY TEST. return(false); }); } if (timeout) { throw new TimeoutException("**** From AggregateException ***", ae); } } catch (Exception) { return(string.Empty); } foreach (Tuple <string, Task <string> > languageTaskTuple in languageTaskTuples) { // All or nothing. if (string.IsNullOrEmpty(languageTaskTuple.Item2.Result)) { return(string.Empty); } GitHubQueryJsonResult gitHubQueryJsonResult = JsonConvert.DeserializeObject <GitHubQueryJsonResult>(languageTaskTuple.Item2.Result); Items.AddRange(gitHubQueryJsonResult.Items); queryResultString += languageTaskTuple.Item2.Result; } if (false == SetSqlServerItems(Items)) { queryResultString = string.Empty; } return(queryResultString); }