Ejemplo n.º 1
0
        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 static string EnumNamePascalCase(ApiFunction function)
        {
            var textInfo = CultureInfo.InvariantCulture.TextInfo;

            var enumNameTitleCase = textInfo.ToTitleCase(function.ToString().ToLowerInvariant()).Replace("_", "");

            return(enumNameTitleCase);
        }
        public void All_enum_values_should_be_implemented(ApiFunction function)
        {
            //Arrange
            var enumNameTitleCase = EnumNamePascalCase(function);

            //Act & Assert
            GetAllMethods.Value.Any(x => x.Name == function.ToString() || x.Name == enumNameTitleCase).Should().BeTrue();
        }
        private TechIndicatorDataPoint ComposeDataPoint(Dictionary <string, string> dataPointContent)
        {
            var isAdjusted = dataPointContent.Count > 6;

            var dataPoint = new TechIndicatorDataPoint();

            dataPoint.Time  = DateTime.Parse(dataPointContent[TimeStampKey]);
            dataPoint.Value = Decimal.Parse(dataPointContent[_function.ToString()], CultureInfo.InvariantCulture);

            return(dataPoint);
        }
Ejemplo n.º 5
0
        private HttpRequestMessage ComposeHttpRequest(string apiKey, ApiFunction function, IDictionary <string, string> query)
        {
            var fullQueryDict = new Dictionary <string, string>(query);

            fullQueryDict.Add(ApiConstants.ApiKeyQueryVar, apiKey);
            fullQueryDict.Add(ApiConstants.FunctionQueryVar, function.ToString());

            var urlWithQueryString = QueryHelpers.AddQueryString(ApiConstants.AlfaVantageUrl, fullQueryDict);
            var urlWithQuery       = new Uri(urlWithQueryString);

            var request = new HttpRequestMessage
            {
                RequestUri = urlWithQuery,
                Method     = HttpMethod.Get
            };

            return(request);
        }