[gbrainy] Fix unit tests
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Fix unit tests
- Date: Wed, 2 Mar 2011 19:54:09 +0000 (UTC)
commit 322c7884a1735dc610909d0e6c522fcc1efa2bd0
Author: Jordi Mas <jmas softcatala org>
Date: Wed Mar 2 20:55:49 2011 +0100
Fix unit tests
src/Core/Services/MemoryConfiguration.cs | 11 ++++++-
tests/Clients/Classical/CommandLineTest.cs | 4 +-
tests/Core/AnalogiesFactoryTest.cs | 3 +-
tests/Core/GameManagerTest.cs | 3 +-
tests/Core/GameSessionTest.cs | 4 +-
tests/Core/GameTest.cs | 4 +-
tests/Core/GameXmlFactoryTest.cs | 4 +-
tests/Core/PlayerHistoryTest.cs | 3 +-
tests/Core/PlayerPersonalRecordTest.cs | 3 +-
tests/Games/Logic/PuzzleNumericRelationTest.cs | 4 +-
tests/Makefile.am | 3 ++
tests/TestSupport/UnitTestSupport.cs | 40 ++++++++++++++++++++++++
12 files changed, 71 insertions(+), 15 deletions(-)
---
diff --git a/src/Core/Services/MemoryConfiguration.cs b/src/Core/Services/MemoryConfiguration.cs
index 1c1c07c..bbcb836 100644
--- a/src/Core/Services/MemoryConfiguration.cs
+++ b/src/Core/Services/MemoryConfiguration.cs
@@ -17,6 +17,7 @@
* Boston, MA 02111-1307, USA.
*/
+using System;
using System.Collections.Generic;
namespace gbrainy.Core.Services
@@ -32,7 +33,15 @@ namespace gbrainy.Core.Services
public T Get <T> (ConfigurationKeys key)
{
- return (T) keys [key];
+ try
+ {
+ return (T) keys [key];
+ }
+
+ catch (KeyNotFoundException e)
+ {
+ throw new KeyNotFoundException (String.Format ("MemoryConfiguration.Get. Key '{0}' not found", key));
+ }
}
public void Set <T> (ConfigurationKeys key, T val)
diff --git a/tests/Clients/Classical/CommandLineTest.cs b/tests/Clients/Classical/CommandLineTest.cs
index 49d414e..f64e361 100644
--- a/tests/Clients/Classical/CommandLineTest.cs
+++ b/tests/Clients/Classical/CommandLineTest.cs
@@ -27,12 +27,12 @@ using gbrainy.Core.Main;
namespace gbrainyTest
{
[TestFixture]
- public class GameTest
+ public class CommandLineTest : UnitTestSupport
{
[TestFixtureSetUp]
public void Construct ()
{
-
+ RegisterDefaultServices ();
}
[Test]
diff --git a/tests/Core/AnalogiesFactoryTest.cs b/tests/Core/AnalogiesFactoryTest.cs
index 41f5787..aef2bf7 100644
--- a/tests/Core/AnalogiesFactoryTest.cs
+++ b/tests/Core/AnalogiesFactoryTest.cs
@@ -26,11 +26,12 @@ using gbrainy.Core.Main.Verbal;
namespace gbrainyTest
{
[TestFixture]
- public class AnalogiesFactoryTest
+ public class AnalogiesFactoryTest : UnitTestSupport
{
[TestFixtureSetUp]
public void Construct ()
{
+ RegisterDefaultServices ();
AnalogiesFactory.Read ("test_analogies.xml");
}
diff --git a/tests/Core/GameManagerTest.cs b/tests/Core/GameManagerTest.cs
index 0ef78b1..44b71fc 100644
--- a/tests/Core/GameManagerTest.cs
+++ b/tests/Core/GameManagerTest.cs
@@ -26,13 +26,14 @@ using gbrainy.Core.Main;
namespace gbrainyTest
{
[TestFixture]
- public class GameManagerTest
+ public class GameManagerTest : UnitTestSupport
{
GameManager manager;
[TestFixtureSetUp]
public void Construct ()
{
+ RegisterDefaultServices ();
manager = new GameManager ();
}
diff --git a/tests/Core/GameSessionTest.cs b/tests/Core/GameSessionTest.cs
index 0935a20..ebad671 100644
--- a/tests/Core/GameSessionTest.cs
+++ b/tests/Core/GameSessionTest.cs
@@ -26,12 +26,12 @@ using gbrainy.Core.Main;
namespace gbrainyTest
{
[TestFixture]
- public class GameSessionTest
+ public class GameSessionTest : UnitTestSupport
{
[TestFixtureSetUp]
public void Construct ()
{
-
+ RegisterDefaultServices ();
}
GameSession PrepareSession ()
diff --git a/tests/Core/GameTest.cs b/tests/Core/GameTest.cs
index cac290d..d35f0c0 100644
--- a/tests/Core/GameTest.cs
+++ b/tests/Core/GameTest.cs
@@ -48,12 +48,12 @@ namespace gbrainyTest
}
[TestFixture]
- public class GameTest
+ public class GameTest : UnitTestSupport
{
[TestFixtureSetUp]
public void Construct ()
{
-
+ RegisterDefaultServices ();
}
// Test individual attributes (MatchAll follows a different logic path)
diff --git a/tests/Core/GameXmlFactoryTest.cs b/tests/Core/GameXmlFactoryTest.cs
index 187f683..72c7763 100644
--- a/tests/Core/GameXmlFactoryTest.cs
+++ b/tests/Core/GameXmlFactoryTest.cs
@@ -28,7 +28,7 @@ namespace gbrainyTest
{
[TestFixture]
- public class GameXmlFactoryTest
+ public class GameXmlFactoryTest : UnitTestSupport
{
GamesXmlFactory factory;
List <GameXmlDefinition> definitions;
@@ -37,7 +37,7 @@ namespace gbrainyTest
[TestFixtureSetUp]
public void Construct ()
{
-
+ RegisterDefaultServices ();
}
[Test]
diff --git a/tests/Core/PlayerHistoryTest.cs b/tests/Core/PlayerHistoryTest.cs
index 74856c7..104a1f1 100644
--- a/tests/Core/PlayerHistoryTest.cs
+++ b/tests/Core/PlayerHistoryTest.cs
@@ -26,13 +26,14 @@ using gbrainy.Core.Main;
namespace gbrainyTest
{
[TestFixture]
- public class PlayerHistoryTest
+ public class PlayerHistoryTest : UnitTestSupport
{
PlayerHistory history;
[TestFixtureSetUp]
public void Construct ()
{
+ RegisterDefaultServices ();
// Ignore gbrainy instance preferences
Preferences.LoadDefaultValues ();
}
diff --git a/tests/Core/PlayerPersonalRecordTest.cs b/tests/Core/PlayerPersonalRecordTest.cs
index c9ebf93..aca384c 100644
--- a/tests/Core/PlayerPersonalRecordTest.cs
+++ b/tests/Core/PlayerPersonalRecordTest.cs
@@ -26,11 +26,12 @@ using gbrainy.Core.Main;
namespace gbrainyTest
{
[TestFixture]
- public class PlayerPersonalRecordTest
+ public class PlayerPersonalRecordTest : UnitTestSupport
{
[TestFixtureSetUp]
public void Construct ()
{
+ RegisterDefaultServices ();
// Ignore gbrainy instance preferences
Preferences.LoadDefaultValues ();
}
diff --git a/tests/Games/Logic/PuzzleNumericRelationTest.cs b/tests/Games/Logic/PuzzleNumericRelationTest.cs
index cc15433..7d7d8ee 100644
--- a/tests/Games/Logic/PuzzleNumericRelationTest.cs
+++ b/tests/Games/Logic/PuzzleNumericRelationTest.cs
@@ -25,12 +25,12 @@ using gbrainy.Games.Logic;
namespace gbrainyTest.Games.Logic
{
[TestFixture]
- public class PuzzleNumericRelationTest
+ public class PuzzleNumericRelationTest : UnitTestSupport
{
[TestFixtureSetUp]
public void Construct ()
{
-
+ RegisterDefaultServices ();
}
[Test]
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d08c63b..125220d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,6 +8,7 @@ CSFLAGS = \
-target:library
CSFILES_CORE = \
+ $(srcdir)/TestSupport/UnitTestSupport.cs \
$(srcdir)/Core/AnalogiesFactoryTest.cs \
$(srcdir)/Core/PlayerHistoryTest.cs \
$(srcdir)/Core/PlayerPersonalRecordTest.cs \
@@ -17,9 +18,11 @@ CSFILES_CORE = \
$(srcdir)/Core/GameXmlFactoryTest.cs
CSFILES_CLASSICAL = \
+ $(srcdir)/TestSupport/UnitTestSupport.cs \
$(srcdir)/Clients/Classical/CommandLineTest.cs
CSFILES_GAMES = \
+ $(srcdir)/TestSupport/UnitTestSupport.cs \
$(srcdir)/Games/Logic/PuzzleNumericRelationTest.cs
if ENABLE_TESTS
diff --git a/tests/TestSupport/UnitTestSupport.cs b/tests/TestSupport/UnitTestSupport.cs
new file mode 100644
index 0000000..3338edc
--- /dev/null
+++ b/tests/TestSupport/UnitTestSupport.cs
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using NUnit.Framework;
+
+using gbrainy.Core.Main;
+using gbrainy.Core.Services;
+
+namespace gbrainyTest
+{
+ public class UnitTestSupport
+ {
+ public void RegisterDefaultServices ()
+ {
+ // Register services
+ ServiceLocator.Instance.RegisterService <ITranslations> (new TranslationsCatalog ());
+ ServiceLocator.Instance.RegisterService <IConfiguration> (new MemoryConfiguration ());
+
+ // Configuration
+ ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.AssembliesDir, "../src/");
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]