Ejemplo n.º 1
0
        /// <summary>
        /// Gets full path to the data file and create the connection string.
        /// </summary>
        /// <param name="fileName">Data file name.</param>
        /// <returns>Connection string.</returns>
        public static string CreateDataConnectionStrng(string fileName)
        {
            var directory = DataDrivenHelpMethods.GetDirectory();
            var path = Path.GetFullPath(Path.Combine(directory, Constants.PartialExcelPath + fileName));
            var connectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = {0}; Extended Properties=Excel 12.0;", path);

            return connectionString;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// GetTestData takes all data from excel file by a parameter.
        /// </summary>
        /// <typeparam name="T">Generic type.</typeparam>
        /// <param name="keyName">Parameter name specifying the test case.</param>
        /// <param name="keyValue">Parameter value specifying the test case.</param>
        /// <param name="sheetName">Data sheet name.</param>
        /// <param name="fileName">Data file name.</param>
        /// <returns>Generic type value.</returns>
        public static T GetTestData <T>(string keyName, string keyValue, string sheetName, string fileName)
        {
            using (var connection = new OleDbConnection(DataDrivenHelpMethods.CreateDataConnectionStrng(fileName)))
            {
                connection.Open();

                var query = string.Format("select * from [{0}$] where {1} = '{2}'", sheetName, keyName, keyValue);
                var value = connection.Query <T>(query).FirstOrDefault();

                connection.Close();

                return(value);
            }
        }