namespace MonoTests.System.DirectoryServices \r
{\r
[TestFixture]\r
- [Category ("InetAccess")]\r
public class DirectoryServicesSearchResultTest\r
{\r
#region Fields\r
\r
- static string LDAPServerRoot;\r
- static string LDAPServerConnectionString;\r
- static string LDAPServerUsername;\r
- static string LDAPServerPassword;\r
+ static TestConfiguration configuration;\r
static DirectoryEntry de;\r
static DirectorySearcher ds;\r
\r
public void TestFixtureSetUp()\r
{\r
de = null;\r
- string ldapServerName = Environment.GetEnvironmentVariable("MONO_LDAP_TEST_SERVER");\r
- Assert.IsFalse((ldapServerName == null || ldapServerName == String.Empty),"This test fixture requires environment variable MONO_LDAP_TEST_SERVER to be set up to LDAP server name.");\r
- LDAPServerRoot = "LDAP://" + ldapServerName + "/";\r
- LDAPServerConnectionString = LDAPServerRoot + "dc=myhosting,dc=example";\r
- LDAPServerUsername = "cn=Manager,dc=myhosting,dc=example";\r
- LDAPServerPassword = "secret";\r
+ configuration = new TestConfiguration ();\r
+\r
+ if (String.IsNullOrEmpty (configuration.ConnectionString))\r
+ Assert.Ignore ("No configuration");\r
}\r
\r
\r
[TestFixtureTearDown]\r
public void TestFixtureTearDown()\r
{\r
+ if (de != null)\r
+ de.Dispose ();\r
+\r
de = null;\r
}\r
\r
\r
#region Initialize basics\r
\r
- DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
- LDAPServerUsername,\r
- LDAPServerPassword,\r
- AuthenticationTypes.ServerBind);\r
+ DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,\r
+ configuration.Username,\r
+ configuration.Password,\r
+ configuration.AuthenticationType);\r
\r
DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");\r
ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");\r
cnManager.Properties["objectClass"].Value = "organizationalRole";\r
cnManager.Properties["cn"].Value = "Manager";\r
+ cnManager.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1238";\r
cnManager.CommitChanges();\r
\r
DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");\r
[TearDown]\r
public void TearDown()\r
{\r
+ if (ds != null)\r
+ ds.Dispose ();\r
+ \r
ds = null;\r
+ \r
+ if (de != null)\r
+ de.Dispose ();\r
+\r
de = null;\r
\r
- DirectoryEntry root = new DirectoryEntry( LDAPServerConnectionString,\r
- LDAPServerUsername,\r
- LDAPServerPassword,\r
- AuthenticationTypes.ServerBind);\r
+ using (DirectoryEntry root = new DirectoryEntry( configuration.ConnectionString,\r
+ configuration.Username,\r
+ configuration.Password,\r
+ configuration.AuthenticationType)){\r
\r
foreach(DirectoryEntry child in root.Children) {\r
DeleteTree_DFS(child);\r
- } \r
+ } \r
+ }\r
}\r
\r
private void DeleteTree_DFS(DirectoryEntry de)\r
[Test]\r
public void SearchResult_Path()\r
{\r
- de = new DirectoryEntry(LDAPServerConnectionString,\r
- LDAPServerUsername,\r
- LDAPServerPassword,\r
- AuthenticationTypes.ServerBind);\r
+ de = new DirectoryEntry(configuration.ConnectionString,\r
+ configuration.Username,\r
+ configuration.Password,\r
+ configuration.AuthenticationType);\r
\r
ds = new DirectorySearcher(de);\r
\r
SearchResultCollection results = ds.FindAll();\r
\r
- Assert.AreEqual(results[0].Path,LDAPServerRoot + "dc=myhosting,dc=example");\r
+ // MS works only with "LDAP" while RFC2255 states "ldap"\r
+ Assert.AreEqual(results[0].Path.ToLower(),(configuration.ServerRoot + configuration.BaseDn).ToLower());\r
Assert.AreEqual(results[0].Path,results[0].GetDirectoryEntry().Path);\r
\r
- Assert.AreEqual(results[1].Path,LDAPServerRoot + "ou=people,dc=myhosting,dc=example");\r
+ // MS works only with "LDAP" while RFC2255 states "ldap"\r
+ Assert.AreEqual(results[1].Path.ToLower(),(configuration.ServerRoot + "ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());\r
Assert.AreEqual(results[1].Path,results[1].GetDirectoryEntry().Path);\r
\r
- Assert.AreEqual(results[2].Path,LDAPServerRoot + "ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ // MS works only with "LDAP" while RFC2255 states "ldap"\r
+ Assert.AreEqual(results[2].Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());\r
Assert.AreEqual(results[2].Path,results[2].GetDirectoryEntry().Path);\r
\r
- Assert.AreEqual(results[3].Path,LDAPServerRoot + "cn=John Smith,ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ // MS works only with "LDAP" while RFC2255 states "ldap"\r
+ Assert.AreEqual(results[3].Path.ToLower(),(configuration.ServerRoot + "cn=John Smith,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());\r
Assert.AreEqual(results[3].Path,results[3].GetDirectoryEntry().Path);\r
}\r
\r
[Test]\r
public void SearchResult_Properties()\r
{\r
- de = new DirectoryEntry(LDAPServerConnectionString,\r
- LDAPServerUsername,\r
- LDAPServerPassword,\r
- AuthenticationTypes.ServerBind);\r
-\r
+ de = new DirectoryEntry(configuration.ConnectionString,\r
+ configuration.Username,\r
+ configuration.Password,\r
+ configuration.AuthenticationType);\r
ds = new DirectorySearcher(de);\r
\r
ds.PropertiesToLoad.Add("cn");\r
ds.Filter = "(objectClass=person)";\r
result = ds.FindOne();\r
\r
- // Properties that does not exists are not loaded\r
+ // Properties that do not exist are not loaded\r
Assert.AreEqual(result.Properties.Count,3);\r
Assert.IsTrue(result.Properties.Contains("cn"));\r
Assert.IsTrue(result.Properties.Contains("objectClass"));\r
\r
Assert.AreEqual(((ResultPropertyValueCollection)result.Properties["cn"])[0],"Barak Tsabari");\r
Assert.AreEqual(((ResultPropertyValueCollection)result.Properties["objectClass"])[0],"person");\r
- Assert.AreEqual(((ResultPropertyValueCollection)result.Properties["AdsPath"])[0],LDAPServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people,dc=myhosting,dc=example");\r
+ // MS works only with "LDAP" while RFC2255 states "ldap"\r
+ Assert.AreEqual(((string)((ResultPropertyValueCollection)result.Properties["AdsPath"])[0]).ToLower(),(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());\r
}\r
\r
#endregion Tests\r