public void ConnectionStringTest()
 {
     MSConnector target = new MSConnector(new Connection()); // TODO: Initialize to an appropriate value
     string expected = "test"; // TODO: Initialize to an appropriate value
     string actual;
     target.ConnectionString = expected;
     actual = target.ConnectionString;
     Assert.AreEqual(expected, actual);
 }
Example #2
0
 /// <summary>
 /// Dient zur Abfrage der SQL Datenbank
 /// In der Connections Liste wird die entsprechende Id gesucht
 /// Danach wird anhand des Typs der Datenbank (Microsoft SQL oder MySQL) ein neues Objekt für die Datenbankabfrage instaziiert
 /// Nach dem das Datenbank Objekt instanziiert wurde wird die Abfrage durchgeführt und in der Content Eigenschaft geschrieben
 /// Falls die Abfrage eine Exception geworfen hat, wird diese gefangen und weitergeleitet.
 /// </summary>
 public void getContent(List<Connection> connections)
 {
     Connection connection;
     try
     {
         connection = connections.Single(s => s.Id == Id);
     }
     catch (InvalidOperationException)
     {
         throw;
     }
     Connector connector;
     if (connection.Type == "MSSQL")
         connector = new MSConnector(connection);
     else
         connector = new MyConnector(connection);
     try
     {
         connector.Connect();
         Content = connector.loadTable(Text);
         connector.Close();
     }
     catch (System.Data.SqlClient.SqlException)
     {
         throw;
     }
     catch (MySql.Data.MySqlClient.MySqlException)
     {
         throw;
     }
 }
 /// <summary>
 /// Setzen der Parameter für eine ungültige Datenbankverbindung (unbekannter Benutzername)
 /// </summary>
 public void InitializeFailedUserName()
 {
     Connection connection = new Connection();
     connection.Server = "localhost";
     connection.Database = "school_example";
     connection.Username = "******";
     connection.Password = "******";
     connector = new MSConnector(connection);
 }
 /// <summary>
 /// Setzen der Parameter für eine ungültige Datenbankverbindung (unbekannte Datenbank)
 /// </summary>
 public void InitializeFailedDatabase()
 {
     Connection connection = new Connection();
     connection.Server = "localhost";
     connection.Database = "..";
     connection.Username = "******";
     connection.Password = "******";
     connector = new MSConnector(connection);
 }
 /// <summary>
 /// Setzen der Parameter für eine ungültige Datenbankverbindung (unbekannter Server)
 /// </summary>
 public void InitializeFailedConnection()
 {
     Connection connection = new Connection();
     connection.Server = "1.1.1.1";
     connection.Database = "school_example";
     connection.Username = "******";
     connection.Password = "******";
     connector = new MSConnector(connection);
 }
 /// <summary>
 /// Setzen der Parameter für eine gültige Datenbankverbindung
 /// </summary>
 public void InitalizeConnection()
 {
     Connection connection = new Connection();
     connection.Server = "localhost\\SQLExpress";
     connection.Database = "school_example";
     connection.Username = "******";
     connection.Password = "******";
     connector = new MSConnector(connection);
 }
Example #7
0
        /// <summary>
        /// Zuerst wird die richtige Datenbankverbindung anhand der ID ausgefiltert. Falls die ID nicht existiert, wird eine Exception geworfen und weitergeleitet.
        /// Als nächstes wird überprüft, ob der Datenbankserver ein Microsoft SQL Server ist oder ein MySQL Server.
        /// Danach wird das Resultat mit Hilfe der Datenbankklassen ausgewertet.
        /// Bei einem Fehler wird eine Exception gefangen und weitergeleitet.
        /// </summary>
        /// <param name="connections">Liste aller verfügbaren Datenbankverbindungen</param>
        /// <returns></returns>
        public string getSqlContent(List<Connection> connections)
        {
            Connector connector;
            Connection connection;
            try
            {
                connection = connections.Single(s => s.Id == Id);
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            if (connection.Type == "MSSQL")
                connector = new MSConnector(connection);
            else
                connector = new MyConnector(connection);
            try
            {
                connector.Connect();
                string result = connector.Result(Text);
                connector.Close();
                return result;

            }
            catch (Exception)
            {
                throw;
            }
        }