Beispiel #1
0
        public ActionResult Database()
        {
            SQLTestData sd = new SQLTestData()
            {
                Advanced = CloudConfigurationManager.GetSetting("Advanced") == "true"
            };

            if (sd.Advanced)
            {
                sd.SQLConnection   = System.Configuration.ConfigurationManager.ConnectionStrings["CorpDataConnectionString"].ConnectionString;
                sd.MySQLConnection = System.Configuration.ConfigurationManager.ConnectionStrings["CustomerDataConnectionString"].ConnectionString;
            }
            ViewBag.Result = new DataTestResult();
            return(View(sd));
        }
Beispiel #2
0
        public DataTestResult TestMySQL(SQLTestData data)
        {
            DataTestResult result = new DataTestResult();

            try
            {
                MySqlConnection conn = new MySqlConnection(data.MySQLConnection);
                string          SQL  = "SELECT * FROM customer;";
                MySqlCommand    cmd  = new MySqlCommand(SQL, conn);
                conn.Open();
                try
                {
                    var rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        result.Customers.Add(new Customer {
                            id = (int)rdr["id"], name = rdr["name"].ToString()
                        });
                    }
                    if (result.Customers.Count == 0)
                    {
                        result.Passed = false;
                        result.Status = "The connection to MySQL is correct but returned no data";
                    }
                    else
                    {
                        result.Passed = true;
                        result.Status = "Passed all MySQL tests.";
                    }
                } finally
                {
                    conn.Close();
                }
            } catch (Exception ex)
            {
                result.Passed = false;
                result.Status = $"Encountered an error: {ex.Message}";
            }


            return(result);
        }
Beispiel #3
0
        public DataTestResult TestSQLServer(SQLTestData data)
        {
            DataTestResult result = new DataTestResult();

            try
            {
                using (var conn = new SqlConnection(data.SQLConnection))
                {
                    var SQL = "SELECT * FROM Sales.SalesPerson;";
                    var cmd = new SqlCommand(SQL, conn);
                    conn.Open();
                    var rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        result.SalesPeople.Add(new SalesPerson {
                            ID = (int)rdr["ID"], FirstName = rdr["FirstName"].ToString(), LastName = rdr["LastName"].ToString(), Phone = rdr["Phone"].ToString()
                        });
                    }
                    if (result.SalesPeople.Count == 0)
                    {
                        result.Passed = false;
                        result.Status = "The connection to SQL Server worked, but there was no data";
                    }
                    else
                    {
                        result.Passed = true;
                        result.Status = "Passed all SQL Server tests.";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Passed = false;
                result.Status = $"Encountered an error: {ex.Message}";
            }


            return(result);
        }
Beispiel #4
0
        public ActionResult Database(SQLTestData data)
        {
            var            test   = new TestProcessor();
            DataTestResult result = new DataTestResult();

            if (TestType.TestSQLServer && TestType.TestMySQL)
            {
                var sqlResult   = test.TestSQLServer(data);
                var mySqlResult = test.TestMySQL(data);
                result = new DataTestResult(sqlResult, mySqlResult);
            }
            else if (TestType.TestSQLServer)
            {
                result = test.TestSQLServer(data);
            }
            else
            {
                result = test.TestMySQL(data);
            }
            result.Ignore  = false;
            ViewBag.Result = result;
            return(View(data));
        }