From 57f4729eeaa377f74681bd3d0bbb999680c72441 Mon Sep 17 00:00:00 2001 From: AlexRa Date: Sun, 23 May 2010 12:46:33 +0300 Subject: Ensured that tests are skipped for wrong conn string, also m_log chng The base test class now tries to connect to DB, ignores all tests in the class if unable to. Also m_log changed to instance field (which in this case shouldn't cause any problems), to avoid having to define it separately in each derived class. Here I touched things that I don't understand well (using log4net), so please review this commit. --- OpenSim/Data/Tests/BasicDataServiceTest.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/Tests/BasicDataServiceTest.cs b/OpenSim/Data/Tests/BasicDataServiceTest.cs index 4c7cf28..c261126 100644 --- a/OpenSim/Data/Tests/BasicDataServiceTest.cs +++ b/OpenSim/Data/Tests/BasicDataServiceTest.cs @@ -27,7 +27,10 @@ namespace OpenSim.Data.Tests private string m_file; // TODO: Is this in the right place here? - protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // Later: apparently it's not, but does it matter here? +// protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected ILog m_log; // doesn't matter here that it's not static, init to correct type in instance .ctor public BasicDataServiceTest() : this("") @@ -38,6 +41,7 @@ namespace OpenSim.Data.Tests { m_connStr = !String.IsNullOrEmpty(conn) ? conn : DefaultTestConns.Get(typeof(TConn)); + m_log = LogManager.GetLogger(this.GetType()); OpenSim.Tests.Common.TestLogging.LogToConsole(); // TODO: Is that right? } @@ -72,10 +76,27 @@ namespace OpenSim.Data.Tests if (String.IsNullOrEmpty(m_connStr)) { string msg = String.Format("Connection string for {0} is not defined, ignoring tests", typeof(TConn).Name); - m_log.Error(msg); + m_log.Warn(msg); Assert.Ignore(msg); } + // Try the connection, ignore tests if Open() fails + using (TConn conn = new TConn()) + { + conn.ConnectionString = m_connStr; + try + { + conn.Open(); + conn.Close(); + } + catch + { + string msg = String.Format("{0} is unable to connect to the database, ignoring tests", typeof(TConn).Name); + m_log.Warn(msg); + Assert.Ignore(msg); + } + } + // If we manage to connect to the database with the user // and password above it is our test database, and run // these tests. If anything goes wrong, ignore these -- cgit v1.1