public void GetTickers_Search() { // Arrange const string query = "crude oil"; const bool isSearch = true; var paging = new PagingOptions(10, 1); // Act var dataSource = _dataProvider.GetTickers(query, isSearch, paging); // Assert Assert.True(dataSource.Success); Assert.True(dataSource.Data.Tickers.Any()); }
public OperationResult<DataSet> GetTickers(string query, bool isSearch, PagingOptions paging) { try { var client = new RestClient(QuandlSettings.QuandlSearchUrl); var restRequest = new RestRequest("datasets.json", Method.GET); if (isSearch) { restRequest.AddParameter("query", query); } else { restRequest.AddParameter("query", "*"); restRequest.AddParameter("source_code", query); } restRequest.AddParameter("per_page", paging.PerPage); restRequest.AddParameter("page", paging.PageNumber); restRequest.AddParameter("auth_token", QuandlSettings.QuandlToken); var response = client.Execute(restRequest); if (response.ResponseStatus != ResponseStatus.Completed) { _logger.Error(response.ErrorException); return new OperationResult<DataSet>(false, response.ErrorMessage); } else { var result = response.Content.FromJson<RootObjectDataSet>(); var data = _mapper.ToDataSet(result); if (isSearch) { data.TotalCount = data.Tickers.Count; } return new OperationResult<DataSet>(data); } } catch (Exception ex) { _logger.Error(ex); throw new QuandlProviderException(ex.Message, ex); } }