public void WebRequestHelper_CallGetRequestWithIncorrectUrl_ThrowsException() { try { var request = WebRequestHelper.CallGetRequest("incorrectUrl"); Assert.Fail("no exception thrown"); } catch (Exception ex) { Assert.IsTrue(ex is UriFormatException); } }
/// <summary> /// Method for get repositories of specific user from GitHubApi /// </summary> /// <param name="userLogin">Login of user which repositories you want to get</param> /// <param name="bestReposCount">Number of best repositories to return</param> /// <returns>Collection of user repositories</returns> public IEnumerable <IUserRepo> GetUserRepos(string userLogin, int bestReposCount = 5) { try { var userReposUrl = $"{ApiAddress}/users/{userLogin}/repos"; var userReposResponseString = WebRequestHelper.CallGetRequest(userReposUrl); var userRepos = JsonConvert.DeserializeObject <List <UserRepoDto> >(userReposResponseString); return(userRepos.OrderByDescending(r => r.StargazersCount).Take(bestReposCount)); } catch (Exception ex) { _logger.LogException(ex); throw; } }
private void CheckAvailability() { try { var responseString = WebRequestHelper.CallGetRequest(ApiAddress); if (responseString == null) { throw new Exception("Api is unavailable"); } } catch (Exception ex) { _logger.LogException(ex); throw; } }
/// <summary> /// Method for get data of specific user from GitHubApi /// </summary> /// <param name="userLogin">Login of user which you are looking for</param> /// <returns>Object containing data of found user</returns> public IUser GetUserByLogin(string userLogin) { try { var userUrl = $"{ApiAddress}/users/{userLogin}"; var userResponseString = WebRequestHelper.CallGetRequest(userUrl); if (userResponseString.Equals("NotFound")) { return(UserDto.NullUser); } var foundUser = JsonConvert.DeserializeObject <UserDto>(userResponseString); return(foundUser); } catch (Exception ex) { _logger.LogException(ex); throw; } }
public void WebRequestHelper_CallGetRequestWithCorrectUrl_SuccessAndAvailable() { var request = WebRequestHelper.CallGetRequest("http://www.google.com"); Assert.IsNotNull(request); }