private bool HandleInputParameters(string fileName, ref string errorReason, Dictionary <string, object> inputParams, string dataTablePath)
        {
            try
            {
                string path = fileName;

                if (_runCancelled())
                {
                    QTPTestCleanup();
                    KillQtp();
                    return(false);
                }

                _qtpApplication.Open(path, true, false);
                _qtpParamDefs  = _qtpApplication.Test.ParameterDefinitions;
                _qtpParameters = _qtpParamDefs.GetParameters();

                // handle all parameters (index starts with 1 !!!)
                for (int i = 1; i <= _qtpParamDefs.Count; i++)
                {
                    // input parameters
                    if (_qtpParamDefs[i].InOut == qtParameterDirection.qtParamDirIn)
                    {
                        string          paramName = _qtpParamDefs[i].Name;
                        qtParameterType type      = _qtpParamDefs[i].Type;

                        // if the caller supplies value for a parameter we set it
                        if (inputParams.ContainsKey(paramName))
                        {
                            // first verify that the type is correct
                            object paramValue = inputParams[paramName];
                            if (!VerifyParameterValueType(paramValue, type))
                            {
                                ConsoleWriter.WriteErrLine(string.Format("Illegal input parameter type (skipped). param: '{0}'. expected type: '{1}'. actual type: '{2}'", paramName, Enum.GetName(typeof(qtParameterType), type), paramValue.GetType()));
                            }
                            else
                            {
                                _qtpParameters[paramName].Value = paramValue;
                            }
                        }
                    }
                }

                // specify data table path
                if (dataTablePath != null)
                {
                    _qtpApplication.Test.Settings.Resources.DataTablePath = dataTablePath;
                    ConsoleWriter.WriteLine("Using external data table: " + dataTablePath);
                }
            }
            catch (Exception e)
            {
                errorReason = Resources.QtpRunError;
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public override int Go()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var name = "[" + SchemaName + "].[" + ProcedureName + "]";

            return(ParameterDefinitions.Any()
                ? StatementExecutor.ExecuteNonQueryStoredProcedure(name, ParameterDefinitions.ToArray())
                : StatementExecutor.ExecuteNonQueryStoredProcedure(name));
        }
        private void KillQtp()
        {
            try
            {
                KillQtpAutomation();
                KillQtpExe();
            }
            catch (Exception e)
            {
                // Ignore
            }

            _qtpParameters  = null;
            _qtpParamDefs   = null;
            _qtpApplication = null;
        }
Beispiel #4
0
        public override IEnumerable <TEntity> Go()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                ProcedureName = CustomAttributeHandle.DbTableName <TEntity>();
            }
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var name = "[" + SchemaName + "].[" + ProcedureName + "]";

            using (var reader = ParameterDefinitions.Any()
                ? StatementExecutor.ExecuteStoredProcedure(name, ParameterDefinitions.ToArray())
                : StatementExecutor.ExecuteStoredProcedure(name))
                return(_entityMapper.Map <TEntity>(reader));
        }
Beispiel #5
0
        public override void WriteTo(CodeWriter codeWriter, CodeWriterOptions options)
        {
            if (functionDefinition.Name is null)
            {
                return;
            }

            codeWriter.WriteUsingStatement(UsingNamespaces);

            var methodNamePrefix = functionDefinition.Type == ObjectType.PropertyGetterFunction ? "Get" : string.Empty;

            codeWriter.PublicMethods
            .WriteWithConverter(new CommentSummaryCodeConverter(functionDefinition.Description))
            .WriteWithConverters(ParameterDefinitions.Select(parameterDefinition => new CommentParamCodeSectionConverter(parameterDefinition.Name, parameterDefinition.Description)))
            .WriteWithConverter(ReturnDefinition is not null ? new CommentReturnsCodeConverter(ReturnDefinition.Description) : null)
            .WriteWithConverter(functionDefinition.IsDeprecated ? new AttributeObsoleteCodeConverter(functionDefinition.Deprecated) : null)
            .WriteLine($"{MethodReturnType} {methodNamePrefix}{functionDefinition.Name.ToCapitalCase()}({MethodArguments});");
        }
Beispiel #6
0
        public override async Task <int> GoAsync()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var procedureName = "[" + SchemaName + "].[" + ProcedureName + "]";
            int num;

            if (ParameterDefinitions.Any())
            {
                num = await StatementExecutor.ExecuteNonQueryStoredProcedureAsync(procedureName,
                                                                                  ParameterDefinitions.ToArray());
            }
            else
            {
                num = await StatementExecutor.ExecuteNonQueryStoredProcedureAsync(procedureName);
            }
            return(num);
        }
        /// <summary>
        /// stops and closes qtp test, to make sure nothing is left floating after run.
        /// </summary>
        private void QTPTestCleanup()
        {
            try
            {
                lock (_lockObject)
                {
                    if (_qtpApplication == null)
                    {
                        return;
                    }

                    var qtpTest = _qtpApplication.Test;
                    if (qtpTest != null)
                    {
                        if (_qtpApplication.GetStatus().Equals("Running") || _qtpApplication.GetStatus().Equals("Busy"))
                        {
                            try
                            {
                                _qtpApplication.Test.Stop();
                            }
                            catch (Exception)
                            {
                            }
                            finally
                            {
                            }
                        }

                        _qtpApplication.Test.Close();
                    }
                }
            }
            catch (Exception)
            {
            }

            _qtpParameters  = null;
            _qtpParamDefs   = null;
            _qtpApplication = null;
        }
Beispiel #8
0
        public override async Task <IEnumerable <TEntity> > GoAsync()
        {
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                ProcedureName = CustomAttributeHandle.DbTableName <TEntity>();
            }
            if (string.IsNullOrWhiteSpace(ProcedureName))
            {
                throw new MissingProcedureNameException();
            }
            var         procedureName = "[" + SchemaName + "].[" + ProcedureName + "]";
            IDataReader dataReader;

            if (ParameterDefinitions.Any())
            {
                dataReader =
                    await StatementExecutor.ExecuteStoredProcedureAsync(procedureName, ParameterDefinitions.ToArray());
            }
            else
            {
                dataReader = await StatementExecutor.ExecuteStoredProcedureAsync(procedureName);
            }
            var reader = dataReader;

            dataReader = null;
            IEnumerable <TEntity> entities;

            try
            {
                entities = entityMapper.Map <TEntity>(reader);
            }
            finally
            {
                reader?.Dispose();
            }

            return(entities);
        }
        public bool TryGetParameterDefinition(string name, out ITemplateParameter parameter)
        {
            parameter = ParameterDefinitions.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));

            if (parameter != null)
            {
                return(true);
            }

            parameter = new TemplateParameter
            {
                Documentation = string.Empty,
                Name          = name,
                Priority      = TemplateParameterPriority.Optional,
                Type          = "string",
                IsName        = false,
                DefaultValue  = string.Empty,
                DataType      = "string",
                Choices       = null
            };

            return(true);
        }
Beispiel #10
0
        private bool HandleInputParameters(string fileName, ref string errorReason)
        {
            try
            {
                string path = fileName;

                if (_runCancelled())
                {
                    QTPTestCleanup();
                    KillQtp();
                    return(false);
                }

                _qtpApplication.Open(path, true, false);
                _qtpParamDefs  = _qtpApplication.Test.ParameterDefinitions;
                _qtpParameters = _qtpParamDefs.GetParameters();
            }
            catch (Exception e)
            {
                errorReason = Resources.QtpRunError;
                return(false);
            }
            return(true);
        }
Beispiel #11
0
        public override void WriteTo(CodeWriter codeWriter, CodeWriterOptions options)
        {
            if (functionDefinition.Name is null)
            {
                return;
            }

            if (functionDefinition.Name is null)
            {
                return;
            }

            codeWriter.WriteUsingStatement(UsingNamespaces);

            codeWriter.PublicMethods
            .WriteWithConverter(new CommentSummaryCodeConverter(functionDefinition.Description))
            .WriteWithConverters(ParameterDefinitions.Select(parameterDefinition => new CommentParamCodeSectionConverter(parameterDefinition.Name, parameterDefinition.Description)))
            .WriteWithConverter(ReturnDefinition is not null ? new CommentReturnsCodeConverter(ReturnDefinition.Description) : null)
            .WriteWithConverter(functionDefinition.IsDeprecated ? new AttributeObsoleteCodeConverter(functionDefinition.Deprecated) : null)
            .WriteLine($"public virtual {MethodReturnType} {functionDefinition.Name.ToCapitalCase()}({MethodArguments})")
            .WriteStartBlock()
            .WriteLine($"return {ClientMethodInvoke}(\"{functionDefinition.Name}\"{ClientMethodInvokeArguments});")
            .WriteEndBlock();
        }
Beispiel #12
0
        private bool HandleInputParameters(string fileName, ref string errorReason, Dictionary <string, object> inputParams, TestInfo testInfo)
        {
            try
            {
                string path = fileName;

                if (_runCancelled())
                {
                    QTPTestCleanup();
                    KillQtp();
                    return(false);
                }

                _qtpApplication.Open(path, true, false);
                _qtpParamDefs  = _qtpApplication.Test.ParameterDefinitions;
                _qtpParameters = _qtpParamDefs.GetParameters();

                // handle all parameters (index starts with 1 !!!)
                for (int i = 1; i <= _qtpParamDefs.Count; i++)
                {
                    // input parameters
                    if (_qtpParamDefs[i].InOut == qtParameterDirection.qtParamDirIn)
                    {
                        string          paramName = _qtpParamDefs[i].Name;
                        qtParameterType type      = _qtpParamDefs[i].Type;

                        // if the caller supplies value for a parameter we set it
                        if (inputParams.ContainsKey(paramName))
                        {
                            // first verify that the type is correct
                            object paramValue = inputParams[paramName];
                            if (!VerifyParameterValueType(paramValue, type))
                            {
                                ConsoleWriter.WriteErrLine(string.Format("Illegal input parameter type (skipped). param: '{0}'. expected type: '{1}'. actual type: '{2}'", paramName, Enum.GetName(typeof(qtParameterType), type), paramValue.GetType()));
                            }
                            else
                            {
                                _qtpParameters[paramName].Value = paramValue;
                            }
                        }
                    }
                }

                // specify data table path
                if (testInfo.DataTablePath != null)
                {
                    _qtpApplication.Test.Settings.Resources.DataTablePath = testInfo.DataTablePath;
                    ConsoleWriter.WriteLine("Using external data table: " + testInfo.DataTablePath);
                }

                // specify iteration mode
                if (testInfo.IterationInfo != null)
                {
                    try
                    {
                        IterationInfo ii = testInfo.IterationInfo;
                        if (!IterationInfo.AvailableTypes.Contains(ii.IterationMode))
                        {
                            throw new ArgumentException(String.Format("Illegal iteration mode '{0}'. Available modes are : {1}", ii.IterationMode, string.Join(", ", IterationInfo.AvailableTypes)));
                        }

                        bool rangeMode = IterationInfo.RANGE_ITERATION_MODE.Equals(ii.IterationMode);
                        if (rangeMode)
                        {
                            int start = Int32.Parse(ii.StartIteration);
                            int end   = Int32.Parse(ii.EndIteration);

                            _qtpApplication.Test.Settings.Run.StartIteration = start;
                            _qtpApplication.Test.Settings.Run.EndIteration   = end;
                        }

                        _qtpApplication.Test.Settings.Run.IterationMode = testInfo.IterationInfo.IterationMode;

                        ConsoleWriter.WriteLine("Using iteration mode: " + testInfo.IterationInfo.IterationMode +
                                                (rangeMode ? " " + testInfo.IterationInfo.StartIteration + "-" + testInfo.IterationInfo.EndIteration : ""));
                    }
                    catch (Exception e)
                    {
                        String msg = "Failed to parse 'Iterations' element . Using default iteration settings. Error : " + e.Message;
                        ConsoleWriter.WriteLine(msg);
                    }
                }
            }
            catch (Exception)
            {
                errorReason = Resources.QtpRunError;
                return(false);
            }
            return(true);
        }
 public void AddParameterDefinition(AvorionServerCommandParameterDefinition definition)
 {
     ParameterDefinitions.Add(definition);
 }
        /// <summary>
        /// stops and closes qtp test, to make sure nothing is left floating after run.
        /// </summary>
        private void QTPTestCleanup()
        {
            try
            {
                lock (_lockObject)
                {
                    if (_qtpApplication == null)
                    {
                        return;
                    }

                    var qtpTest = _qtpApplication.Test;
                    if (qtpTest != null)
                    {
                        if (_qtpApplication.GetStatus().Equals("Running") || _qtpApplication.GetStatus().Equals("Busy"))
                        {
                            try
                            {
                                _qtpApplication.Test.Stop();
                            }
                            catch (Exception e)
                            {
                            }
                            finally
                            {

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            _qtpParameters = null;
            _qtpParamDefs = null;
            _qtpApplication = null;
        }
        private bool HandleInputParameters(string fileName, ref string errorReason)
        {
            try
            {
                string path = fileName;

                if (_runCancelled())
                {
                    QTPTestCleanup();
                    KillQtp();
                    return false;
                }

                _qtpApplication.Open(path, true, false);
                _qtpParamDefs = _qtpApplication.Test.ParameterDefinitions;
                _qtpParameters = _qtpParamDefs.GetParameters();
            }
            catch (Exception e)
            {
                errorReason = Resources.QtpRunError;
                return false;
            }
            return true;
        }
        private bool HandleInputParameters(string fileName, ref string errorReason, Dictionary<string, object> inputParams)
        {
            try
            {
                string path = fileName;

                if (_runCancelled())
                {
                    QTPTestCleanup();
                    KillQtp();
                    return false;
                }

                _qtpApplication.Open(path, true, false);
                _qtpParamDefs = _qtpApplication.Test.ParameterDefinitions;
                _qtpParameters = _qtpParamDefs.GetParameters();

                // handle all parameters (index starts with 1 !!!)
                for (int i = 1; i <= _qtpParamDefs.Count; i++)
                {
                    // input parameters
                    if (_qtpParamDefs[i].InOut == qtParameterDirection.qtParamDirIn)
                    {
                        string paramName = _qtpParamDefs[i].Name;
                        qtParameterType type = _qtpParamDefs[i].Type;

                        // if the caller supplies value for a parameter we set it
                        if (inputParams.ContainsKey(paramName))
                        {
                            // first verify that the type is correct
                            object paramValue = inputParams[paramName];
                            if (!VerifyParameterValueType(paramValue, type))
                            {
                                ConsoleWriter.WriteErrLine(string.Format("Illegal input parameter type (skipped). param: '{0}'. expected type: '{1}'. actual type: '{2}'", paramName, Enum.GetName(typeof(qtParameterType), type), paramValue.GetType()));
                            }
                            else
                            {
                                _qtpParameters[paramName].Value = paramValue;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errorReason = Resources.QtpRunError;
                return false;
            }
            return true;
        }