File: TestConfiguration.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (86 lines) | stat: -rw-r--r-- 2,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.DirectoryServices;
using System.Collections.Specialized;
using System.Configuration;

namespace MonoTests.System.DirectoryServices 
{
	public class TestConfiguration
	{
		#region Fields

		private string _serverRoot;
		private string _username;
		private string _password;
		private string _baseDn;
		private AuthenticationTypes _authenticationType;

		#endregion // Fields

		#region Constructors

		public TestConfiguration()
		{
			NameValueCollection config = (NameValueCollection) ConfigurationSettings.GetConfig ("System.DirectoryServices.Test/Settings");
			if (config != null) {
				string servername = config ["servername"];
				string port = config ["port"];
				_serverRoot = "LDAP://" + servername + (port.Equals ("389") ? String.Empty : (":" + port)) + "/";

				_baseDn = config ["basedn"];

				_username = config ["username"];
				_password = config ["password"];

				string authType = config ["authenticationtype"];

				string [] authTypes = authType.Split (new char[] { '|' });

				_authenticationType = (AuthenticationTypes) 0;

				foreach (string s in authTypes)
					foreach (AuthenticationTypes type in Enum.GetValues (typeof (AuthenticationTypes)))
						if (s.Trim ().Equals (type.ToString ()))
							_authenticationType |= type;	
			}

			//Console.WriteLine ("Connecting to {0} with credentials {1}:{2} and security {3}",ConnectionString,Username,Password,AuthenticationType);
		}

		#endregion // Constructors

		#region Properties

		public string ServerRoot
		{
			get { return _serverRoot; }
		}

		public string BaseDn
		{
			get { return ((_baseDn == null) ? String.Empty : _baseDn); }
		}

		public string ConnectionString
		{ 
			get { return ServerRoot + ((BaseDn.Length == 0) ? String.Empty : BaseDn); }
		}

		public string Username
		{
			get{ return _username; }
		}

		public string Password
		{
			get { return _password; }
		}

		public AuthenticationTypes AuthenticationType
		{
			get { return _authenticationType; }
		}

		#endregion // Properties
	}
}