[bcl] Remove the ValueAdd and InetAccess NUnit categories (#2212)
[mono.git] / mcs / class / System.DirectoryServices / Test / System.DirectoryServices / DirectoryServicesSearchResultTest.cs
index 6be79186fb7d42a994a53d43d1b1090284f91c37..21aa253301b5a73722d6a4fa817cd9516535528e 100644 (file)
@@ -13,15 +13,11 @@ using System.DirectoryServices;
 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
@@ -33,18 +29,19 @@ namespace MonoTests.System.DirectoryServices
                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
@@ -56,10 +53,10 @@ namespace MonoTests.System.DirectoryServices
 \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
@@ -187,6 +184,7 @@ namespace MonoTests.System.DirectoryServices
                        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
@@ -223,17 +221,25 @@ namespace MonoTests.System.DirectoryServices
                [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
@@ -252,36 +258,39 @@ namespace MonoTests.System.DirectoryServices
                [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
@@ -315,7 +324,7 @@ namespace MonoTests.System.DirectoryServices
                        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
@@ -323,7 +332,8 @@ namespace MonoTests.System.DirectoryServices
 \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