public void NullCredentials() { SqlConnect DBTest = new SqlConnect(); Assert.Throws <System.NullReferenceException>(() => { DBTest.Connect("test", null, false); }); Assert.Throws <System.NullReferenceException>(() => { DBTest.Connect(null, null, false); }); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.Connect(null, "test", false); }); }
public void FakeCredentials() { SqlConnect DBTest = new SqlConnect(); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.Connect("test", "tes", false); }); Assert.Throws <Npgsql.NpgsqlException>(() => { DBTest.Connect("test", "", false); }); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.Connect("tes", "tes", false); }); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.Connect("", "tes", false); }); }
public DataTable GetDataTable(StringBuilder sql) { DataTable dtReqItemDic; try { using (SqlConnection dbCon = SqlConnect.Connect()) { SqlTransaction dbTran = dbCon.BeginTransaction(); CreateSqlDBTransaction(dbCon, dbTran); try { SvrRmlisSqlDal svrRmlisSqlDal = new SvrRmlisSqlDal(); dtReqItemDic = svrRmlisSqlDal.GetDataTable(sql); dbTran.Commit(); } catch (Exception ex) { dbTran.Rollback(); throw ex; } } } catch (Exception ex) { return(null); } return(dtReqItemDic); }
public void CheckPermissions() { SqlConnect DBTest = new SqlConnect(); String connString = DBTest.Connect("test", "test", false); Assert.Throws <Npgsql.PostgresException>(() => { DBTest.CheckDate(connString); }); }
/// <summary> /// our main method /// </summary> /// <param name="args">we should never really need arguments passed to main, however we may later decide to /// modify the program to accept the db name, ip address, username and password as command line arguments /// </param> static void Main(string[] args) { SqlConnect dBConnect = new SqlConnect(); String connString = dBConnect.Connect(); dBConnect.CheckDate(connString); DataFormat test = new DataFormat(); Dictionary <string, object>[] rarr = test.getData(); List <Json311> forDB = new List <Json311>(); forDB = test.parseData(rarr); dBConnect.Import(forDB, connString); Console.ReadKey(); }
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.Connect("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(); }