Ejemplo n.º 1
0
        public DataSet GetDataSet(IEnumerable <string> tableNames)
        {
            var dataSet = new DataSet();

            DbCommand = new SqlCommand(ProcedureName, DbConnection)
            {
                CommandType = CommandType.StoredProcedure
            };

            if (Parameters.Count > 0)
            {
                DbCommand.Parameters.AddRange(Parameters.ToArray());
            }

            try
            {
                DbCommand.CommandTimeout = Timeout;
                DbCommand.Connection.Open();
                var dataAdapter = new SqlDataAdapter(DbCommand);

                foreach (string tableName in tableNames)
                {
                    dataSet.Tables.Add(tableName);
                    dataAdapter.Fill(dataSet, tableName);
                }
            }
            catch (Exception exception)
            {
                Dispose();
                Log4NetLogger.LogEntry(GetType(), "GetDataSet", "GetDataSetError", LoggerLevel.Error, exception);
                throw;
            }

            return(dataSet);
        }
Ejemplo n.º 2
0
        public DataTable GetDataTable()
        {
            var dtResults = new DataTable();

            DbCommand = new SqlCommand(ProcedureName, DbConnection)
            {
                CommandType = CommandType.StoredProcedure
            };

            if (Parameters.Count > 0)
            {
                DbCommand.Parameters.AddRange(Parameters.ToArray());
            }

            try
            {
                DbCommand.CommandTimeout = Timeout;
                DbCommand.Connection.Open();
                var dataAdapter = new SqlDataAdapter(DbCommand);
                dataAdapter.Fill(dtResults);
            }
            catch (Exception exception)
            {
                Log4NetLogger.LogEntry(GetType(), "GetDataTable", "GetDataTableError", LoggerLevel.Error, exception);
            }
            finally
            {
                Dispose();
            }

            return(dtResults);
        }
Ejemplo n.º 3
0
        public void Execute()
        {
            DbCommand = new SqlCommand(ProcedureName, DbConnection)
            {
                CommandType = CommandType.StoredProcedure
            };

            if (Parameters.Count > 0)
            {
                DbCommand.Parameters.AddRange(Parameters.ToArray());
            }

            try
            {
                DbCommand.CommandTimeout = Timeout;
                DbCommand.Connection.Open();
                DbCommand.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                Log4NetLogger.LogEntry(GetType(), "Execute", "ExecuteError", LoggerLevel.Error, exception);
            }
            finally
            {
                Dispose();
            }
        }
Ejemplo n.º 4
0
        public object GetScalar()
        {
            object value = null;

            DbCommand = new SqlCommand(ProcedureName, DbConnection)
            {
                CommandType = CommandType.StoredProcedure
            };

            if (Parameters.Count > 0)
            {
                DbCommand.Parameters.AddRange(Parameters.ToArray());
            }

            try
            {
                DbCommand.CommandTimeout = Timeout;
                DbCommand.Connection.Open();
                value = DbCommand.ExecuteScalar();
            }
            catch (Exception exception)
            {
                Log4NetLogger.LogEntry(GetType(), "GetScalar", "GetScalarError", LoggerLevel.Error, exception);
            }
            finally
            {
                Dispose();
            }
            return(value);
        }
Ejemplo n.º 5
0
        public SqlDataReader GetDataReader()
        {
            SqlDataReader dataReader;

            DbCommand = new SqlCommand(ProcedureName, DbConnection)
            {
                CommandType = CommandType.StoredProcedure
            };

            if (Parameters.Count > 0)
            {
                DbCommand.Parameters.AddRange(Parameters.ToArray());
            }

            try
            {
                DbCommand.CommandTimeout = Timeout;
                DbCommand.Connection.Open();
                dataReader = DbCommand.ExecuteReader();
            }
            catch (Exception exception)
            {
                Dispose();
                Log4NetLogger.LogEntry(GetType(), "GetDataReader", "GetDataReaderError", LoggerLevel.Error, exception);
                throw;
            }

            return(dataReader);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Log4NetLogger.LogEntry(typeof(Program), "Application_Start", "ApplicationStarted", LoggerLevel.Info);
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

            var container          = IoC.Bind();
            var assemblyScanner    = container.GetInstance <IAssemblyScanner>();
            var parallelTestRunner = container.GetInstance <IParallelTestRunner>();

            var beginTest = parallelTestRunner.GetSettingsFromArgs(args);

            if (beginTest.TypeOfTestRun != TypeOfTestRun.Performance)
            {
                var errors = parallelTestRunner.GetErrorsFromBeginTestIfAny(beginTest);

                if (errors.Length > 0)
                {
                    Console.WriteLine(errors);
                    throw new Exception("The required paramaters to run a test were not provided.");
                }

                var testLibraryContainer = assemblyScanner.GetTestLibraryContainer(beginTest.Dll);
                var listOfTestToRuns     = assemblyScanner.GetTestsToRun(testLibraryContainer, beginTest.Dll,
                                                                         beginTest.ProjectName, beginTest.Namespaces);
                var i = 0;
                foreach (var listOfTestToRun in listOfTestToRuns)
                {
                    Console.WriteLine(i);
                    Console.WriteLine(listOfTestToRun.Arguments[0]);
                    i++;
                }

                if (beginTest.Namespaces != null)
                {
                    foreach (var name in beginTest.Namespaces)
                    {
                        Console.WriteLine("namespace= {0}", name);
                    }
                }

                var testRun = parallelTestRunner.Execute(listOfTestToRuns, beginTest.ProjectName,
                                                         beginTest.EnvironmentUrl);
                Console.WriteLine("The Test Run Id is {0}", testRun.Id);
                Console.WriteLine("The Test Run Start date is {0}", testRun.TestRunStart);
                Console.WriteLine("The Test Run End date is {0}", testRun.TestRunEnd);
                Console.WriteLine("{0} Ran", testRun.TestCount);
                Console.WriteLine(
                    "The Url to view the test results is http://testdata-app.fourth.cloud/api/testrunapi/{0}",
                    testRun.Id);
                Log4NetLogger.LogEntry(typeof(Program), "Application_End", "ApplicationEnded", LoggerLevel.Info);
            }
            else
            {
                var errors = parallelTestRunner.GetErrorsFromBeginTestIfAny(beginTest);
                if (errors.Length > 0)
                {
                    Console.WriteLine(errors);
                    throw new Exception("The required paramaters to run a test were not provided.");
                }
                var testLibraryContainer = assemblyScanner.GetTestLibraryContainer(beginTest.Dll);
                var listOfTestToRuns     = assemblyScanner.GetTestsToRun(testLibraryContainer, beginTest.Dll,
                                                                         beginTest.ProjectName, beginTest.Namespaces);
                var i = 0;
                foreach (var listOfTestToRun in listOfTestToRuns)
                {
                    Console.WriteLine(i);
                    Console.WriteLine(listOfTestToRun.Arguments[0]);
                    i++;
                }
                if (beginTest.Namespaces != null)
                {
                    foreach (var name in beginTest.Namespaces)
                    {
                        Console.WriteLine("namespace= {0}", name);
                    }
                }
                var testRunIdentifier = Guid.NewGuid();
                var projectName       = parallelTestRunner.GetTestRunNameFromListOfTestsToRun(listOfTestToRuns);
                var testRun           = new TestRun()
                {
                    TestRunIdentifier = testRunIdentifier,
                    Project           = beginTest.ProjectName,
                    EnvrionmentUrl    = beginTest.EnvironmentUrl,
                    ShortName         = GetProjectNameStringFromString(projectName),
                    Name         = projectName,
                    TestRunStart = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    TestCount    = listOfTestToRuns.Count
                };

                var testRunnerResultManager = container.GetInstance <ITestRunnerResultManager>();
                testRunnerResultManager.SaveTestRun(testRun);

                if (!string.IsNullOrWhiteSpace(beginTest.RampUpPeriodInMinutes))
                {
                    RunSectionOfTest(beginTest.RampUpPeriodInMinutes, beginTest.RampUpUsers, beginTest.EnvironmentUrl, beginTest.ProjectName, listOfTestToRuns, parallelTestRunner, testRun);
                }

                //if (!string.IsNullOrWhiteSpace(beginTest.PeakPeriodInMinutes))
                //{
                //    RunSectionOfTest(beginTest.PeakPeriodInMinutes, beginTest.PeakUsers, beginTest.EnvironmentUrl, beginTest.ProjectName, listOfTestToRuns, parallelTestRunner, testRun);
                //}

                //if (!string.IsNullOrWhiteSpace(beginTest.WindDownPeriodInMinutes))
                //{
                //    RunSectionOfTest(beginTest.WindDownPeriodInMinutes, beginTest.WindDownUsers, beginTest.EnvironmentUrl, beginTest.ProjectName, listOfTestToRuns, parallelTestRunner, testRun);
                //}

                //testRun = testRunnerResultManager.GetTestRun(testRunIdentifier);
                //testRun.TestRunEnd = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //testRunnerResultManager.UpdateTestRun(testRun);


                Console.WriteLine("The Test Run Id is {0}", testRun.Id);
                Console.WriteLine("The Test Run Start date is {0}", testRun.TestRunStart);
                Console.WriteLine("The Test Run End date is {0}", testRun.TestRunEnd);
                Console.WriteLine("{0} Ran", testRun.TestCount);
                Console.WriteLine(
                    "The Url to view the test results is http://testdata-app.fourth.cloud/api/testrunapi/{0}",
                    testRun.Id);
                Log4NetLogger.LogEntry(typeof(Program), "Application_End", "ApplicationEnded", LoggerLevel.Info);
            }
        }
Ejemplo n.º 7
0
 static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
 {
     Log4NetLogger.LogEntry(typeof(Program), "Application_Error", "Caught exception in Global Asax", LoggerLevel.Fatal, (Exception)e.ExceptionObject);
     Console.WriteLine(e.ToString());
 }
Ejemplo n.º 8
0
        public void Test()
        {
            var comparisonConfiguration = new ComparisonConfiguration
            {
                SourceServerName  = "SomeServerNameOrIp",
                SoureDatabaseName = "SomeDatabaseName",
                SourcePassword    = "******",
                SourceUserName    = "******",
                TargetServerName  = "SomeServerNameOrIp",
                TargetDatabasName = "SomeDatabaseName",
                TargetPassword    = "******",
                TargetUserName    = "******"
            };


            using (Database stagingDb = new Database(), productionDb = new Database())
            {
                var sourceConnectionProperties =
                    new ConnectionProperties(comparisonConfiguration.SourceServerName,
                                             comparisonConfiguration.SoureDatabaseName, comparisonConfiguration.SourceUserName,
                                             comparisonConfiguration.SourcePassword);

                var targetConnectionProperties = new ConnectionProperties(
                    comparisonConfiguration.TargetServerName, comparisonConfiguration.TargetDatabasName,
                    comparisonConfiguration.TargetUserName, comparisonConfiguration.TargetPassword);

                // Connect to the two databases and read the schema
                try
                {
                    Console.WriteLine("Registering database " + sourceConnectionProperties.DatabaseName);
                    stagingDb.Register(sourceConnectionProperties, Options.Default);
                }
                catch (SqlException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(@"
Cannot connect to database '{0}' on server '{1}'. The most common causes of this error are:
        o The sample databases are not installed
        o ServerName not set to the location of the target database
        o For sql server authentication, username and password incorrect or not supplied in ConnectionProperties constructor
        o Remote connections not enabled", sourceConnectionProperties.DatabaseName,
                                      sourceConnectionProperties.ServerName);
                    return;
                }
                try
                {
                    Console.WriteLine("Registering database " + targetConnectionProperties.DatabaseName);
                    productionDb.Register(targetConnectionProperties, Options.Default);
                }
                catch (SqlException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(@"
Cannot connect to database '{0}' on server '{1}'. The most common causes of this error are:
        o The sample databases are not installed
        o ServerName not set to the location of the target database
        o For sql server authentication, username and password incorrect or not supplied in ConnectionProperties constructor
        o Remote connections not enabled", targetConnectionProperties.DatabaseName,
                                      targetConnectionProperties.ServerName);
                    return;
                }

                // Compare WidgetStaging against WidgetProduction
                Differences stagingVsProduction = stagingDb.CompareWith(productionDb, Options.Default);
                Log4NetLogger.LogEntry(GetType(), "SqlCompareResult",
                                       string.Format("Total Differences = {0}", stagingVsProduction.Count(x => x.Type != DifferenceType.Equal)), LoggerLevel.Info);
                // Display the results on the console
                foreach (Difference difference in stagingVsProduction)
                {
                    if (difference.Type != DifferenceType.Equal)
                    {
                        Log4NetLogger.LogEntry(GetType(), "SqlCompareResult",
                                               string.Format("{0} {1} {2}", difference.Type, difference.DatabaseObjectType, difference.Name),
                                               LoggerLevel.Info);
                    }
                }
                Log4NetLogger.LogEntry(GetType(), "SqlCompareResult", string.Format("Finished writing differences"),
                                       LoggerLevel.Info);
            }
        }