public void NullCredentials() { SqlConnect DBTest = new SqlConnect(); Assert.Throws <System.NullReferenceException>(() => { DBTest.ConnectGCP("test", null, false); }); Assert.Throws <System.NullReferenceException>(() => { DBTest.ConnectGCP(null, null, false); }); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.ConnectGCP(null, "test", false); }); }
public void FakeCredentials() { SqlConnect DBTest = new SqlConnect(); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.ConnectGCP("test", "tes", false); }); Assert.Throws <Npgsql.NpgsqlException>(() => { DBTest.ConnectGCP("test", "", false); }); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.ConnectGCP("tes", "tes", false); }); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.ConnectGCP("", "tes", false); }); }
public void CheckPermissions() { SqlConnect DBTest = new SqlConnect(); String connString = DBTest.ConnectGCP("test", "test", false); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.CheckDate(connString, out DateTime date); }); }
public void JsonNull() { /// <remarks> /// Since data is often missing all fields are initialized to null if they do not have another value; /// </remarks> Json311 test = new Json311(); List <Json311> JList = new List <Json311>(); JList.Add(test); SqlConnect DBTest = new SqlConnect(); /// <remarks> /// Uses a test user who has only insert and select privelege in testtable /// </remarks> String connString = DBTest.ConnectGCP("test", "test", false); NpgsqlConnection conn = new NpgsqlConnection(connString); conn.Open(); /// <remarks> /// Check The connection /// </remarks> Assert.AreEqual(conn.State, System.Data.ConnectionState.Open); /// <remarks> /// Test the import, making sure the data is added to the right table /// and our date is not updated /// </remarks> DBTest.Import(JList, connString, "testtable", false); using (NpgsqlCommand checkValue = new NpgsqlCommand("SELECT * FROM testtable", conn)) using (NpgsqlDataReader reader = checkValue.ExecuteReader()) { while (reader.Read()) { /// <remarks> /// Since the column is empty, it will throw an invalid cast exception when /// attemption to convert it to a string /// </remarks> Assert.Throws <System.InvalidCastException>(() => { reader.GetString(0); }); } } conn.Close(); }
/// <summary> /// Checks to see which database the user wants to use, will be deprecated later on /// and switched to just GCP, local is just here for testing /// </summary> public void WhichDatabase() { SqlConnect connect = new SqlConnect(); Credentials creds = new Credentials(); String user = creds.GCPargs[0]; String pass = creds.GCPargs[1]; Application.Current.Resources["connString"] = connect.ConnectGCP(user, pass, false); /* * MessageBoxResult result = MessageBox.Show("Would you like to use the GCP database?" + * " \n If not it will use the local database", "Database Prompt", MessageBoxButton.YesNo); * switch (result) * { * case MessageBoxResult.Yes: * { * SqlConnect connect = new SqlConnect(); * Credentials creds = new Credentials(); * String user = creds.GCPargs[0]; * String pass = creds.GCPargs[1]; * Application.Current.Resources["connString"] = connect.ConnectGCP(user, pass, false); * } * break; * * case MessageBoxResult.No: * { * SqlConnect connect = new SqlConnect(); * Credentials creds = new Credentials(); * String user = creds.LocalArg[0]; * String pass = creds.LocalArg[1]; * Application.Current.Resources["connString"] = connect.ConnectLocal(user, pass, false); * } * break; * } */ }