Do you think that this is a good way for testing exceptions and throwing? Any suggestions?
This are my code witch I wold like to test the exception:
public void EstablishConnection(string user, string pass)
{
try{
string connstring = String.Format("Server=" + CONNECTION_HOST + ";Port=" + CONNECTION_PORT + ";Database=" + CONNECTION_DATABASE + ";User Id=" + user + ";Password='" + pass + "';" + CONNECTION_OPTIONS);
connection = new NpgsqlConnection(connstring);
connection.Open();
if (connection.State != ConnectionState.Open)
{
IsConnected = false;
}
IsConnected = true;
}catch (Exception e)
{
throw;
}
}
Unit testing code that I used for testing:
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void EstablishEndGetConnectionTest()
{
DbRepository core = null;
core = DbRepository.GetInstance();
core.EstablishConnection("postgres", "1234");
Assert.IsTrue(core.IsConnected);
}