2 // ConnectionConfig.cs - Holds information on a specific connection and
3 // corresponding engine to test.
6 // Gert Driesen (drieseng@users.sourceforge.net
8 // Copyright (c) 2008 Gert Driesen
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Configuration;
33 using System.Globalization;
36 namespace MonoTests.System.Data
38 internal sealed class ConnectionConfig
40 private readonly string name;
41 private readonly string factory;
42 private readonly string connectionString;
43 private readonly EngineConfig engine;
45 private ConnectionConfig (string name, string factory, string connectionString, EngineConfig engine)
48 this.factory = factory;
49 this.connectionString = connectionString;
53 internal static ConnectionConfig FromXml (XmlNode connNode, Hashtable engines)
55 return new ConnectionConfig (
56 GetAttribValue (connNode, "name", true),
57 GetAttribValue (connNode, "factory", true),
58 GetAttribValue (connNode, "connectionString", true),
59 GetEngine (connNode, engines));
66 public string Factory {
67 get { return factory; }
70 public string ConnectionString {
71 get { return connectionString; }
74 public EngineConfig Engine {
75 get { return engine; }
78 static string GetAttribValue (XmlNode node, string name, bool required)
80 XmlAttribute attr = node.Attributes [name];
83 throw CreateAttributeMissingException (name, node);
89 static EngineConfig GetEngine (XmlNode connNode, Hashtable engines)
91 XmlAttribute engineAttr = connNode.Attributes ["engine"];
92 if (engineAttr == null)
93 throw CreateAttributeMissingException ("engine", connNode);
95 string engineName = engineAttr.Value;
96 EngineConfig engine = (EngineConfig) engines [engineName];
98 string msg = string.Format (CultureInfo.InvariantCulture,
99 "Engine '{0}' does not exist.", engineName);
100 throw new ConfigurationErrorsException (msg, engineAttr);
105 static Exception CreateAttributeMissingException (string name, XmlNode node)
107 string msg = string.Format (CultureInfo.InvariantCulture,
108 "Missing '{0}' attribute.", name);
109 throw new ConfigurationErrorsException (msg, node);