public void When_methods_call_query_api_function_should_match_method_name() { //Arrange var mockResponse = new HttpResponseMessage(); mockResponse.StatusCode = HttpStatusCode.NotFound; var mockHandler = new UriBuildingTests.MockHttpHandler(mockResponse); var httpClient = new HttpClient(mockHandler); var client = new GenericApiClient(httpClient); var stockTimeSeriesData = new StockTimeSeriesData("apifake", client); //Act var bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; var methodsToCheck = stockTimeSeriesData.GetType().GetMethods(bindingFlags); //TODO would be nice to use a TestCaseSource or Theory, but ehhhh Assert.Multiple(() => { //Assert foreach (var method in methodsToCheck) { //TODO build or find a library to invoke based on parameter names... //method.Invoke(stockTimeSeriesData, ) var foundFunction = Regex.Match(mockHandler.RequestUri.ToString(), "function=(.+?)(&|$)"); var textInfo = new CultureInfo("en-US", false).TextInfo; var enumNameTitleCase = textInfo.ToTitleCase(foundFunction.Groups[1].Value.ToLowerInvariant()).Replace("_", ""); Assert.That(method.Name, Is.EqualTo(enumNameTitleCase)); } }); }
public void When_deserializing_multicurrency_responses_should_get_all_values() { //Arrange var responseJson = @"{""Meta Data"":{""1. Information"":""Intraday Prices and Volumes for Digital Currency"",""2. Digital Currency Code"":""BTC"",""3. Digital Currency Name"":""Bitcoin"",""4. Market Code"":""EUR"",""5. Market Name"":""Euro"",""6. Interval"":""5min"",""7. Last Refreshed"":""2018-07-06 23:15:00"",""8. Time Zone"":""UTC""},""Time Series (Digital Currency Intraday)"":{""2018-07-06 23:15:00"":{""1a. price (EUR)"":""5614.25205722"",""1b. price (USD)"":""6598.71423375"",""2. volume"":""12054.88574590"",""3. market cap (USD)"":""79546746.15772399""},""2018-07-06 23:10:00"":{""1a. price (EUR)"":""5607.13276119"",""1b. price (USD)"":""6590.34656526"",""2. volume"":""12039.62198342"",""3. market cap (USD)"":""79345281.38542400""},""2018-07-06 23:05:00"":{""1a. price (EUR)"":""5609.58382787"",""1b. price (USD)"":""6593.22742783"",""2. volume"":""12045.28001062"",""3. market cap (USD)"":""79417270.54190400""}}}"; var client = new GenericApiClient(); //Act var materialized = client.DeserializeWithSettings <DigitalCurrencyIntraday>(responseJson); //Assert materialized.Data.Should().HaveCount(3); materialized.Data.Values.Should().BeEquivalentTo( new DigitalCurrencySpotData { Price = 5614.25205722m, PriceUSD = 6598.71423375m, Volume = 12054.88574590m, MarketCapUSD = 79546746.15772399m }, new DigitalCurrencySpotData { Price = 5607.13276119M, PriceUSD = 6590.34656526M, Volume = 12039.62198342M, MarketCapUSD = 79345281.38542400M }, new DigitalCurrencySpotData { Price = 5609.58382787M, PriceUSD = 6593.22742783M, Volume = 12045.28001062M, MarketCapUSD = 79417270.54190400M }); }
public void When_deserializing_all_sample_files(ApiFunction function) { //Arrange var methodInfos = ImplementationProgressTests.GetAllMethods.Value; var methodForThisFunction = methodInfos.Single(x => x.Name == function.ToString() || x.Name == ImplementationProgressTests.EnumNamePascalCase(function)); var returnTypeTask = methodForThisFunction.ReturnType; var returnType = returnTypeTask.GenericTypeArguments[0]; var client = new GenericApiClient(); var id = 0; for (; id < 5; id++) { var sampleFileContent = ReadFile(function, id); if (sampleFileContent == null) { break; } //Act var result = client.DeserializeWithSettings(sampleFileContent, returnType); //Assert // count all the non-default property values, if deserialization failed, the values should be defaults //TODO could also say number of default values should be BELOW a maximum (make sure one part of the model didn't stop working) var nonDefaultProperties = CountProperties(result, false); Console.WriteLine("Non-default property count: " + nonDefaultProperties); var allPropertiesCount = CountProperties(result, true); Console.WriteLine("Property count: " + allPropertiesCount); nonDefaultProperties.Should().BeGreaterOrEqualTo(GetMinimumExpectedProperties(function)); if (function == ApiFunction.STOCHRSI || function == ApiFunction.STOCHF || function == ApiFunction.AROON || function == ApiFunction.DIGITAL_CURRENCY_DAILY) { // Very lenient case nonDefaultProperties.Should().BeGreaterOrEqualTo((int)(allPropertiesCount * 0.5), "seems like an excessive number of default property values, even for these functions"); } else if (!function.ToString().Contains("ADJUSTED")) { // Default case nonDefaultProperties.Should().BeGreaterOrEqualTo(allPropertiesCount - 20, "seems like an excessive number of default property values"); } else { // Lenient case nonDefaultProperties.Should().BeGreaterOrEqualTo((int)(allPropertiesCount * 0.7), "even though adjusted, seems like an excessive number of default property values"); } } if (id == 0) { Assert.Warn("NO TEST DATA WAS FOUND"); } }
public void When_manually_built_test_of_type() { //Arrange var response = ReadFile(ApiFunction.SECTOR); var client = new GenericApiClient(); //Act var result = client.DeserializeWithSettings(response, typeof(Sector)); //Assert //TODO add some assertions here }
public void When_supplied_with_empty_dictionary() { //Arrange var mockResponse = new HttpResponseMessage(); mockResponse.Content = new StringContent("{'two': 'four'}"); var mockHandler = new MockHttpHandler(mockResponse); var httpClient = new HttpClient(mockHandler); var client = new GenericApiClient(httpClient); //Act var response = client.SendAsync <JObject>(HttpMethod.Get, new Uri("http://test.test.test"), new Dictionary <string, string>()); //Assert mockHandler.RequestUri.Should().Be("http://test.test.test"); response.Result.Should().Contain("two", JToken.FromObject("four")); }
public void When_supplied_with_parameters() { //Arrange var mockResponse = new HttpResponseMessage(); mockResponse.Content = new StringContent("{'two': 'four'}"); var mockHandler = new MockHttpHandler(mockResponse); var httpClient = new HttpClient(mockHandler); var client = new GenericApiClient(httpClient); //Act var response = client.SendGetAsync <TestRequest, JObject>(new Uri("http://test.test.test"), new TestRequest()); //Assert mockHandler.RequestUri.Should().Be("http://test.test.test?fiveAlive=string&one=THREE"); response.Result.Should().Contain("two", JToken.FromObject("four")); }
public void When_deserializing_metadata() { //Arrange var responseJson = @"{""Meta Data"":{""1. Information"":""Intraday (15min) prices and volumes"",""2. Symbol"":""MSFT"",""3. Last Refreshed"":""2018-07-06 16:00:00"",""4. Interval"":""15min"",""5. Output Size"":""Compact"",""6. Time Zone"":""US/Eastern""},""Time Series (15min)"":{""2018-07-06 16:00:00"":{""1. open"":""100.9850"",""2. high"":""101.2500"",""3. low"":""100.7100"",""4. close"":""101.1600"",""5. volume"":""4248932""},""2018-07-06 15:45:00"":{""1. open"":""101.4050"",""2. high"":""101.4300"",""3. low"":""101.0400"",""4. close"":""101.0400"",""5. volume"":""570066""},""2018-07-06 15:30:00"":{""1. open"":""101.2200"",""2. high"":""101.4200"",""3. low"":""101.2000"",""4. close"":""101.4000"",""5. volume"":""441079""}}}"; var client = new GenericApiClient(); //Act var materialized = client.DeserializeWithSettings <TimeSeriesIntraday>(responseJson); //Assert materialized.Data.Should().HaveCount(3); materialized.Metadata.Information.Should().Be("Intraday (15min) prices and volumes"); materialized.Metadata.Symbol.Should().Be("MSFT"); materialized.Metadata.LastRefreshed.Should().Be("2018-07-06 16:00:00"); materialized.Metadata.Interval.Should().Be("15min"); materialized.Metadata.OutputSize.Should().Be("Compact"); materialized.Metadata.TimeZone.Should().Be("US/Eastern"); materialized.Metadata.Notes.Should().BeNull(); }
public void When_deserializing_response_body() { var responseJson = @"{""Meta Data"":{""1. Information"":""Daily Prices (open, high, low, close) and Volumes"",""2. Symbol"":""MSFT"",""3. Last Refreshed"":""2018-07-06"",""4. Output Size"":""Compact"",""5. Time Zone"":""US/Eastern""},""Time Series (Daily)"":{""2018-07-06"":{""1. open"":""99.8850"",""2. high"":""101.4300"",""3. low"":""99.6700"",""4. close"":""101.1600"",""5. volume"":""18238379""},""2018-07-05"":{""1. open"":""99.5000"",""2. high"":""99.9200"",""3. low"":""99.0299"",""4. close"":""99.7600"",""5. volume"":""18583217""}}}"; var client = new GenericApiClient(); //Act var materialized = client.DeserializeWithSettings <TimeSeriesDaily>(responseJson); //Assert materialized.Data.Should().HaveCount(2); materialized.Data.First().Value.Close.Should().Be(101.1600m); materialized.Metadata.Information.Should().Be("Daily Prices (open, high, low, close) and Volumes"); materialized.Metadata.Symbol.Should().Be("MSFT"); materialized.Metadata.LastRefreshed.Should().Be("2018-07-06"); materialized.Metadata.Interval.Should().BeNull(); materialized.Metadata.OutputSize.Should().Be("Compact"); materialized.Metadata.TimeZone.Should().Be("US/Eastern"); materialized.Metadata.Notes.Should().BeNull(); }
public void When_appending_further_parameters() { //Arrange var mockResponse = new HttpResponseMessage(); mockResponse.Content = new StringContent("{'two': 'six'}"); var mockHandler = new MockHttpHandler(mockResponse); var httpClient = new HttpClient(mockHandler); var client = new GenericApiClient(httpClient); //Act var response = client.SendAsync <JObject>(HttpMethod.Get, new Uri("http://test.test.test?already=here&more=there"), new Dictionary <string, string> { { "and", "plus" }, { "even", "more" } }); //Assert mockHandler.RequestUri.Should().Be("http://test.test.test?already=here&more=there&and=plus&even=more"); response.Result.Should().Contain("two", JToken.FromObject("six")); }
public SectorPerformances(string apiKey, GenericApiClient apiClient = null) : base(apiKey, apiClient) { }
public ForeignExchange(string apiKey, GenericApiClient apiClient = null) : base(apiKey, apiClient) { }
protected BaseEndpointParameters(string apiKey, GenericApiClient apiClient = null) { _apiKey = apiKey; ApiClient = apiClient ?? new GenericApiClient(ConfigureClient); }
public TechnicalIndicators(string apiKey, GenericApiClient apiClient = null) : base(apiKey, apiClient) { }
public DigitalCryptoCurrencies(string apiKey, GenericApiClient apiClient = null) : base(apiKey, apiClient) { }
public StockTimeSeriesData(string apiKey, GenericApiClient apiClient = null) : base(apiKey, apiClient) { }