title: Unit test exception handling
body: <p>A seemingly simple one here. How can I test the exception handling of this code block using a unit test? </p>
  
  <pre><code>    public DbFactoryResponseType Close()
      {
          DbFactoryResponseType dbFactoryResponse = new DbFactoryResponseType();
          try
          {
              if (m_isConnected)
              {
                  m_isConnected = false;
  
                  if (m_hasRecordSet)
                  {
                      m_hasRecordSet = false;
  
                      m_dbFactoryDatabaseDataReader.Close();
                      m_dbFactoryDatabaseDataReader.Dispose();
                  }
  
                  m_dbFactoryDatabaseCommand.Dispose();
                  m_dbFactoryDatabaseConnection.Close();
                  m_dbFactoryDatabaseConnection.Dispose();
  
              }
  
              dbFactoryResponse.ExceptionMessage = "";
              dbFactoryResponse.Success = true;
              dbFactoryResponse.UserFriendlyMessage = "OK";
  
              return dbFactoryResponse;
          }
          catch (Exception ex)
          {
              dbFactoryResponse.ExceptionMessage = ex.Message;
              dbFactoryResponse.Success = false;
              dbFactoryResponse.UserFriendlyMessage = "Error: Error while attempting to close the database connection.";
  
              return dbFactoryResponse;
          }
      }
  </code></pre>
  
  <p>Here is what I have so far but I do not know how to make the exception fire allowing me to test the output.  </p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Test method to test closing a PosgreSQL database connection.
      /// &lt;/summary&gt;
      [TestMethod]
      public void TestClosePostgreSQLConnectionException()
      {
          const string connectionString = "Server=myIp;Port=myPort;Database=myDatabase;User Id=myUser;Password=myPassword;";
  
          const string provider = "Npgsql";
  
          DbProviderFactoryConnection aDbProviderFactoryConnection = new DbProviderFactoryConnection(connectionString, provider);
  
          DbFactoryResponseType dbFactoryResponseType = aDbProviderFactoryConnection.Close();
  
          Assert.IsNotNull(dbFactoryResponseType);
  
          Assert.AreEqual(false, dbFactoryResponseType.Success);
      }  
  </code></pre>