aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests/DefaultTestConns.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/Tests/DefaultTestConns.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/OpenSim/Data/Tests/DefaultTestConns.cs b/OpenSim/Data/Tests/DefaultTestConns.cs
new file mode 100644
index 0000000..7b52af5
--- /dev/null
+++ b/OpenSim/Data/Tests/DefaultTestConns.cs
@@ -0,0 +1,63 @@
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Reflection;
6using System.IO;
7using Nini.Config;
8
9namespace OpenSim.Data.Tests
10{
11 /// <summary>This static class looks for TestDataConnections.ini file in the /bin directory to obtain
12 /// a connection string for testing one of the supported databases.
13 /// The connections must be in the section [TestConnections] with names matching the connection class
14 /// name for the specific database, e.g.:
15 ///
16 /// [TestConnections]
17 /// MySqlConnection="..."
18 /// SqlConnection="..."
19 /// SqliteConnection="..."
20 ///
21 /// Note that the conn string may also be set explicitly in the [TestCase()] attribute of test classes
22 /// based on BasicDataServiceTest.cs.
23 /// </summary>
24
25 static class DefaultTestConns
26 {
27 private static Dictionary<Type, string> conns = new Dictionary<Type, string>();
28
29 public static string Get(Type connType)
30 {
31 string sConn;
32
33 if (conns.TryGetValue(connType, out sConn))
34 return sConn;
35
36 Assembly asm = Assembly.GetExecutingAssembly();
37 string sType = connType.Name;
38
39 // Note: when running from NUnit, the DLL is located in some temp dir, so how do we get
40 // to the INI file? Ok, so put it into the resources!
41 // string iniName = Path.Combine(Path.GetDirectoryName(asm.Location), "TestDataConnections.ini");
42
43 string[] allres = asm.GetManifestResourceNames();
44 string sResFile = Array.Find(allres, s => s.Contains("TestDataConnections.ini"));
45
46 if (String.IsNullOrEmpty(sResFile))
47 throw new Exception(String.Format("Please add resource TestDataConnections.ini, with section [TestConnections] and settings like {0}=\"...\"",
48 sType));
49
50 using (Stream resource = asm.GetManifestResourceStream(sResFile))
51 {
52 IConfigSource source = new IniConfigSource(resource);
53 var cfg = source.Configs["TestConnections"];
54 sConn = cfg.Get(sType, "");
55 }
56
57 if (!String.IsNullOrEmpty(sConn))
58 conns[connType] = sConn;
59
60 return sConn;
61 }
62 }
63}