public void TestRetrieveDataTypes() { DataTypeDefinitions result = _reader.GetColumnType(); string[] expectedDataTypes = new string[] { "System.Int32", "System.Int32", "System.String", "System.String", "System.String", "System.String", "System.String", "System.String", "System.String", "System.Int32", "System.String", "System.Int32", "System.Int32", "System.String", "System.String", "System.String", "System.String", "System.String" }; result.DataTypes.Should().BeEquivalentTo(expectedDataTypes); }
/// <summary> /// Method to evaluate all the conditions in the query /// </summary> /// <param name="queryParameter">The query parameter containing properties of the query</param> /// <param name="rowValues">The field values of a row</param> /// <returns>True or false based on whether the condition saitisfies or fails</returns> public static bool EvaluateExpression(QueryParameter queryParameter, List <string> rowValues) { ///If the file name is different than previous file name then recalculate all the properties related to it if (!string.Equals(_file, queryParameter.File)) { _file = queryParameter.File; _queryProcessor = new CsvQueryProcessor(queryParameter.File); _headers = _queryProcessor.GetHeader().Headers.ToList(); _dataTypes = _queryProcessor.GetColumnType().DataTypes.ToList(); } ///Find the column positions that are being referred by the where clause List <int> fieldPositions = queryParameter.Restrictions .Select(restriction => _headers.IndexOf(restriction.propertyname)).ToList(); ///List containing the result of each conditions List <bool> conditions = new List <bool>(); ///Find the result of each result for (int i = 0; i < queryParameter.Restrictions.Count; i++) { conditions.Add(PerformEvaluation(rowValues[fieldPositions[i]], queryParameter.Restrictions[i].propertyValue, _dataTypes[fieldPositions[i]], queryParameter.Restrictions[i].condition)); } ///After finding the result of each condition logical operators should be applied if any if (queryParameter.LogicalOperators != null) { List <string> logicalOperators = queryParameter.LogicalOperators.ToList(); ///Execute all and conditions first due to priority PerformSpecificLogicalOperations("and", conditions, logicalOperators); ///Execute or conditions after and PerformSpecificLogicalOperations("or", conditions, logicalOperators); } ///The last value in the condition bool list will be the resulting bool return(conditions.Last()); }