2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.DirectoryServices / Test / System.DirectoryServices / TestConfiguration.cs
blob7de8f05cb9c611c0590c83fbc33a745f978b338c
1 using System;
2 using System.DirectoryServices;
3 using System.Collections.Specialized;
4 using System.Configuration;
6 namespace MonoTests.System.DirectoryServices
8 public class TestConfiguration
10 #region Fields
12 private string _serverRoot;
13 private string _username;
14 private string _password;
15 private string _baseDn;
16 private AuthenticationTypes _authenticationType;
18 #endregion // Fields
20 #region Constructors
22 public TestConfiguration()
24 NameValueCollection config = (NameValueCollection) ConfigurationSettings.GetConfig ("System.DirectoryServices.Test/Settings");
25 if (config != null) {
26 string servername = config ["servername"];
27 string port = config ["port"];
28 _serverRoot = "LDAP://" + servername + (port.Equals ("389") ? String.Empty : (":" + port)) + "/";
30 _baseDn = config ["basedn"];
32 _username = config ["username"];
33 _password = config ["password"];
35 string authType = config ["authenticationtype"];
37 string [] authTypes = authType.Split (new char[] { '|' });
39 _authenticationType = (AuthenticationTypes) 0;
41 foreach (string s in authTypes)
42 foreach (AuthenticationTypes type in Enum.GetValues (typeof (AuthenticationTypes)))
43 if (s.Trim ().Equals (type.ToString ()))
44 _authenticationType |= type;
47 //Console.WriteLine ("Connecting to {0} with credentials {1}:{2} and security {3}",ConnectionString,Username,Password,AuthenticationType);
50 #endregion // Constructors
52 #region Properties
54 public string ServerRoot
56 get { return _serverRoot; }
59 public string BaseDn
61 get { return ((_baseDn == null) ? String.Empty : _baseDn); }
64 public string ConnectionString
66 get { return ServerRoot + ((BaseDn.Length == 0) ? String.Empty : BaseDn); }
69 public string Username
71 get{ return _username; }
74 public string Password
76 get { return _password; }
79 public AuthenticationTypes AuthenticationType
81 get { return _authenticationType; }
84 #endregion // Properties