Added objects disposing to the tests.
authorBoris Kirzner <borisk@mono-cvs.ximian.com>
Mon, 5 Dec 2005 17:46:57 +0000 (17:46 -0000)
committerBoris Kirzner <borisk@mono-cvs.ximian.com>
Mon, 5 Dec 2005 17:46:57 +0000 (17:46 -0000)
svn path=/trunk/mcs/; revision=53936

mcs/class/System.DirectoryServices/Test/System.DirectoryServices/ChangeLog
mcs/class/System.DirectoryServices/Test/System.DirectoryServices/DirectoryServicesDirectoryEntryTest.cs
mcs/class/System.DirectoryServices/Test/System.DirectoryServices/DirectoryServicesDirectorySearcherTest.cs
mcs/class/System.DirectoryServices/Test/System.DirectoryServices/DirectoryServicesSearchResultTest.cs

index b455551a350e0250f515016a67fd54bb6f94e7ae..ea3a49fd0bd13e1926146350187edb53fc06bf15 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-05 Boris Kirzner <borisk@mainsoft.coim>
+       * DirectoryServicesDirectoryEntryTest.cs, 
+       DirectoryServicesDirectorySearcherTest.cs,
+       DirectoryServicesSearchResultTest.cs : added objects disposing to the tests
+
 2005-11-06 Boris Kirzner <borisk@mainsoft.coim>
        * TestConfiguration.cs: added. 
        Class to read tests configuration from app config.
index f006507d0462f9a2db891414acfeb06c5309c72b..e908935b831184347161800c8ca0c7cb95256322 100644 (file)
@@ -36,6 +36,8 @@ namespace MonoTests.System.DirectoryServices
                [TestFixtureTearDown]\r
                public void TestFixtureTearDown()\r
                {\r
+                       if (de != null)\r
+                               de.Dispose ();\r
                        de = null;\r
                }\r
 \r
@@ -214,16 +216,20 @@ namespace MonoTests.System.DirectoryServices
                [TearDown]\r
                public void TearDown()\r
                {\r
+                       if (de != null)\r
+                               de.Dispose ();\r
+\r
                        de = null;\r
 \r
-                       DirectoryEntry root = new DirectoryEntry(       configuration.ConnectionString,\r
+                       using (DirectoryEntry root = new DirectoryEntry(        configuration.ConnectionString,\r
                                                                                                                configuration.Username,\r
                                                                                                                configuration.Password,\r
-                                                                                                               configuration.AuthenticationType);\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
@@ -255,7 +261,7 @@ namespace MonoTests.System.DirectoryServices
                [Test]\r
                public void DirectoryEntry_DirectoryEntry_Str()\r
                {\r
-                       DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString);\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
                        Assert.AreEqual(de.Name,GetName (configuration.BaseDn));\r
@@ -264,6 +270,7 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,null);\r
+                       }\r
                }\r
 \r
 \r
@@ -273,10 +280,10 @@ namespace MonoTests.System.DirectoryServices
 \r
                        #region AuthenticationTypes.Anonymous\r
 \r
-                       DirectoryEntry de = new DirectoryEntry( configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(  configuration.ConnectionString,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       AuthenticationTypes.Anonymous);\r
+                                                                                                       AuthenticationTypes.Anonymous)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -287,15 +294,16 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.Anonymous\r
 \r
                        #region AuthenticationTypes.Delegation\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.Delegation);\r
+                                                                       AuthenticationTypes.Delegation)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -306,6 +314,7 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.Delegation\r
 \r
@@ -330,10 +339,10 @@ namespace MonoTests.System.DirectoryServices
 \r
                        #region AuthenticationTypes.FastBind\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.FastBind);\r
+                                                                       AuthenticationTypes.FastBind)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -344,15 +353,16 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.FastBind\r
 \r
                        #region AuthenticationTypes.None\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.None);\r
+                                                                       AuthenticationTypes.None)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -363,15 +373,16 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.None\r
 \r
                        #region AuthenticationTypes.ReadonlyServer\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.ReadonlyServer);\r
+                                                                       AuthenticationTypes.ReadonlyServer)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -382,15 +393,16 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.ReadonlyServer\r
 \r
                        #region AuthenticationTypes.Sealing\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.Sealing);\r
+                                                                       AuthenticationTypes.Sealing)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -401,6 +413,7 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.Sealing\r
 \r
@@ -444,10 +457,10 @@ namespace MonoTests.System.DirectoryServices
 \r
                        #region AuthenticationTypes.ServerBind\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.ServerBind);\r
+                                                                       AuthenticationTypes.ServerBind)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -458,15 +471,16 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.ServerBind\r
 \r
                        #region AuthenticationTypes.Signing\r
 \r
-                       de = new DirectoryEntry(configuration.ConnectionString,\r
+                       using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,\r
                                                                        configuration.Username,\r
                                                                        configuration.Password,\r
-                                                                       AuthenticationTypes.Signing);\r
+                                                                       AuthenticationTypes.Signing)){\r
                        \r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
                        //Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));\r
@@ -477,18 +491,18 @@ namespace MonoTests.System.DirectoryServices
                        Assert.AreEqual(de.SchemaClassName,"organization");\r
                        Assert.AreEqual(de.UsePropertyCache,true);\r
                        Assert.AreEqual(de.Username,configuration.Username);\r
+                       }\r
 \r
                        #endregion //AuthenticationTypes.Signing\r
-\r
                }\r
 \r
                [Test]\r
                public void DirectoryEntry_Dispose()\r
                {\r
-                       DirectoryEntry root = new DirectoryEntry(       configuration.ConnectionString,\r
+                       using (DirectoryEntry root = new DirectoryEntry(        configuration.ConnectionString,\r
                                                                                                                configuration.Username,\r
                                                                                                                configuration.Password,\r
-                                                                                                               configuration.AuthenticationType);\r
+                                                                                                               configuration.AuthenticationType)){\r
 \r
                        DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");\r
                        ouPeople.Properties["objectClass"].Value = "organizationalUnit";\r
@@ -496,12 +510,11 @@ namespace MonoTests.System.DirectoryServices
                        ouPeople.Properties["ou"].Value = "printers";\r
                        ouPeople.CommitChanges();\r
 \r
-                       //root.Dispose();\r
-\r
                        ouPeople.Rename("ou=anotherPrinters");\r
                        ouPeople.CommitChanges();\r
 \r
                        Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));\r
+                       }\r
                }\r
 \r
 \r
@@ -543,7 +556,6 @@ namespace MonoTests.System.DirectoryServices
                        de.AuthenticationType = AuthenticationTypes.Signing;\r
                        Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);\r
 \r
-\r
                        de = new DirectoryEntry(configuration.ConnectionString);\r
 \r
                        de.AuthenticationType = AuthenticationTypes.Anonymous;\r
@@ -639,22 +651,24 @@ namespace MonoTests.System.DirectoryServices
                        string newTelephoneNumber = "+972-3-6572345";\r
 \r
                        de.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
-                       DirectoryEntry barakTsabariDE = new DirectoryEntry(     barakTsabariDN,\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
 \r
                        Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
                        de.CommitChanges();\r
-                       barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                       }\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);\r
 \r
                        // restore object state\r
                        de.Properties["telephoneNumber"].Value = oldTelephoneNumber;\r
                        de.CommitChanges();\r
+                       }\r
 \r
                        #endregion // Check Properties\r
 \r
@@ -663,13 +677,14 @@ namespace MonoTests.System.DirectoryServices
                        // DeleteTree is not cached\r
                        de.DeleteTree();\r
                        try {\r
-                               barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                               using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                                barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
                                barakTsabariDE.CommitChanges();\r
                                Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");\r
+                               }\r
                        }\r
                        catch(AssertionException ae) {\r
                                throw ae;\r
@@ -679,11 +694,11 @@ namespace MonoTests.System.DirectoryServices
                        }\r
 \r
                        // restore object state\r
-                       DirectoryEntry ouHumanResources = new DirectoryEntry(   configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
-                       DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
+                                                                                                                                       configuration.AuthenticationType)){\r
+                       using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){\r
                        ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
                        ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
                        cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
@@ -693,6 +708,8 @@ namespace MonoTests.System.DirectoryServices
                        cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
                        cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
                        cnBarakTsabari.CommitChanges();\r
+                       }\r
+                       }\r
 \r
                        #endregion // Check DeleteTree\r
 \r
@@ -704,19 +721,20 @@ namespace MonoTests.System.DirectoryServices
                                                                        configuration.Password,\r
                                                                        configuration.AuthenticationType);\r
 \r
-                       DirectoryEntry ouRnD = new DirectoryEntry(      configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouRnD = new DirectoryEntry(       configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                                configuration.Username,\r
                                                                                                                configuration.Password,\r
-                                                                                                               configuration.AuthenticationType);\r
+                                                                                                               configuration.AuthenticationType)){\r
                        de.MoveTo(ouRnD);\r
                        try {\r
-                               barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                               using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                                barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
                                barakTsabariDE.CommitChanges();\r
                                Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");\r
+                               }\r
                        }\r
                        catch(AssertionException ae) {\r
                                throw ae;\r
@@ -724,26 +742,29 @@ namespace MonoTests.System.DirectoryServices
                        catch (Exception e) {\r
                                // do nothing\r
                        }\r
+                       }\r
 \r
-\r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
+                       }\r
                        \r
 \r
                        // restore object state\r
-                       ouHumanResources = new DirectoryEntry(  configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                                                                                                                                       configuration.AuthenticationType)){\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        barakTsabariDE.MoveTo(ouHumanResources);\r
                        barakTsabariDE.CommitChanges();\r
+                       }\r
+                       }\r
 \r
                        #endregion // Check MoveTo\r
 \r
@@ -758,13 +779,14 @@ namespace MonoTests.System.DirectoryServices
                        de.Rename("cn=MyUser");\r
 \r
                        try {\r
-                               barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                               using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                                barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
                                barakTsabariDE.CommitChanges();\r
                                Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");\r
+                               }\r
                        }\r
                        catch(AssertionException ae) {\r
                                throw ae;\r
@@ -773,19 +795,21 @@ namespace MonoTests.System.DirectoryServices
                                // do nothing\r
                        }\r
 \r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
+                       }\r
 \r
                        // restore object state\r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        barakTsabariDE.Rename("cn=Barak Tsabari");\r
                        barakTsabariDE.CommitChanges();\r
+                       }\r
 \r
                        #endregion // Check Rename\r
 \r
@@ -801,10 +825,11 @@ namespace MonoTests.System.DirectoryServices
 \r
                        // Properties changes not cached\r
                        de.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
-                       barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
+                       }\r
 \r
                        //Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);\r
 \r
@@ -815,13 +840,14 @@ namespace MonoTests.System.DirectoryServices
                        // DeleteTree is not cached\r
                        de.DeleteTree();\r
                        try {\r
-                               barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                               using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                                barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
                                barakTsabariDE.CommitChanges();\r
                                Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");\r
+                               }\r
                        }\r
                        catch(AssertionException ae) {\r
                                throw ae;\r
@@ -831,11 +857,11 @@ namespace MonoTests.System.DirectoryServices
                        }\r
 \r
                        // restore object state\r
-                       ouHumanResources = new DirectoryEntry(  configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
-                       cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
+                                                                                                                                       configuration.AuthenticationType)){\r
+                       using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){\r
                        ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
                        ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
                        cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
@@ -845,6 +871,8 @@ namespace MonoTests.System.DirectoryServices
                        cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
                        cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
                        cnBarakTsabari.CommitChanges();\r
+                       }\r
+                       }\r
 \r
                        #endregion // Check DeleteTree\r
 \r
@@ -856,19 +884,21 @@ namespace MonoTests.System.DirectoryServices
                                                                        configuration.Password,\r
                                                                        configuration.AuthenticationType);\r
 \r
-                       ouRnD = new DirectoryEntry(     configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouRnD = new DirectoryEntry(       configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                configuration.Username,\r
                                                                                configuration.Password,\r
-                                                                               configuration.AuthenticationType);\r
+                                                                               configuration.AuthenticationType)){\r
                        de.MoveTo(ouRnD);\r
+                       }\r
                        try {\r
-                               barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                               using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                                barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
                                barakTsabariDE.CommitChanges();\r
                                Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");\r
+                               }\r
                        }\r
                        catch(AssertionException ae) {\r
                                throw ae;\r
@@ -878,24 +908,27 @@ namespace MonoTests.System.DirectoryServices
                        }\r
 \r
 \r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
+                       }\r
                        \r
 \r
                        // restore object state\r
-                       ouHumanResources = new DirectoryEntry(  configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                                                                                                                                       configuration.AuthenticationType)){\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        barakTsabariDE.MoveTo(ouHumanResources);\r
                        barakTsabariDE.CommitChanges();\r
+                       }\r
+                       }\r
 \r
                        #endregion // Check MoveTo\r
 \r
@@ -910,13 +943,14 @@ namespace MonoTests.System.DirectoryServices
                        de.Rename("cn=MyUser");\r
 \r
                        try {\r
-                               barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
+                               using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                                barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;\r
                                barakTsabariDE.CommitChanges();\r
                                Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");\r
+                               }\r
                        }\r
                        catch(AssertionException ae) {\r
                                throw ae;\r
@@ -925,19 +959,21 @@ namespace MonoTests.System.DirectoryServices
                                // do nothing\r
                        }\r
 \r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);\r
+                       }\r
 \r
                        // restore object state\r
-                       barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
                        barakTsabariDE.Rename("cn=Barak Tsabari");\r
                        barakTsabariDE.CommitChanges();\r
+                       }\r
 \r
                        #endregion // Check Rename\r
                }\r
@@ -1218,11 +1254,11 @@ namespace MonoTests.System.DirectoryServices
                        ((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";\r
 \r
                        // create the entry back again\r
-                       DirectoryEntry ouHumanResources = new DirectoryEntry(   configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
+                       using (DirectoryEntry ouHumanResources = new DirectoryEntry(    configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
-                       DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");\r
+                                                                                                                                       configuration.AuthenticationType)){\r
+                       using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){\r
                        ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");\r
                        ((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");\r
                        cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";\r
@@ -1232,6 +1268,8 @@ namespace MonoTests.System.DirectoryServices
                        cnBarakTsabari.Properties["sn"].Value = "Tsabari";\r
                        cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";\r
                        cnBarakTsabari.CommitChanges();\r
+                       }\r
+                       }\r
                        \r
                        // the local property chache is still accessible\r
                        Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Barbari");\r
@@ -1378,10 +1416,10 @@ namespace MonoTests.System.DirectoryServices
                public void DirectoryEntry_CommitChanges1()\r
                {\r
                        string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
-                       DirectoryEntry ouHumanResources = new DirectoryEntry(   humanResourcesDN,\r
+                       using (DirectoryEntry ouHumanResources = new DirectoryEntry(    humanResourcesDN,\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
+                                                                                                                                       configuration.AuthenticationType)){\r
 \r
                        // new entry\r
                        string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
@@ -1394,6 +1432,7 @@ namespace MonoTests.System.DirectoryServices
                        \r
                        de.CommitChanges();\r
                        Assert.IsTrue(DirectoryEntry.Exists(newEmployeeDN));\r
+                       }\r
 \r
                        // existing entry\r
                        string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
@@ -1410,23 +1449,25 @@ namespace MonoTests.System.DirectoryServices
                        ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = newTelephone;\r
                        Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,newTelephone);\r
 \r
-                       DirectoryEntry cnBarakTsabari = new DirectoryEntry(     barakTsabariDN,\r
+                       using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(      barakTsabariDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
 \r
                        //check that on server there is still an old value\r
                        Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);\r
 \r
                        de.CommitChanges();\r
+                       }\r
 \r
-                       cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
+                       using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
 \r
                        // check that new value is updated on the server\r
                        Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,newTelephone);\r
+                       }\r
 \r
                        // UsePropertyCache - false\r
                        de = new DirectoryEntry(barakTsabariDN,\r
@@ -1438,13 +1479,14 @@ namespace MonoTests.System.DirectoryServices
                        ((PropertyValueCollection)de.Properties["telephoneNumber"]).Value = oldTelephone;\r
                        Assert.AreEqual(((PropertyValueCollection)de.Properties["telephoneNumber"]).Value,oldTelephone);\r
 \r
-                       cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
+                       using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(barakTsabariDN,\r
                                                                                                configuration.Username,\r
                                                                                                configuration.Password,\r
-                                                                                               configuration.AuthenticationType);\r
+                                                                                               configuration.AuthenticationType)){\r
 \r
                        // check that new value is updated on the server\r
                        //Assert.AreEqual(((PropertyValueCollection)cnBarakTsabari.Properties["telephoneNumber"]).Value,oldTelephone);\r
+                       }\r
 \r
                        de.CommitChanges(); // this should do nothing\r
                }\r
@@ -1453,16 +1495,16 @@ namespace MonoTests.System.DirectoryServices
                public void DirectoryEntry_CommitChanges2()\r
                {\r
                        string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
-                       DirectoryEntry barakTsabariDE1 = new DirectoryEntry(barakTsabariDN,\r
+                       using (DirectoryEntry barakTsabariDE1 = new DirectoryEntry(barakTsabariDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
                        barakTsabariDE1.UsePropertyCache = true;\r
 \r
-                       DirectoryEntry barakTsabariDE2 = new DirectoryEntry(barakTsabariDN,\r
+                       using (DirectoryEntry barakTsabariDE2 = new DirectoryEntry(barakTsabariDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
                        barakTsabariDE2.UsePropertyCache = true;\r
 \r
                        string oldTelephone = (string)((PropertyValueCollection)barakTsabariDE1.Properties["telephoneNumber"]).Value;\r
@@ -1493,6 +1535,8 @@ namespace MonoTests.System.DirectoryServices
                                                                        configuration.AuthenticationType);\r
                        Assert.AreEqual(de.Properties["telephoneNumber"].Value,newTelephone);\r
                        Assert.AreEqual(de.Properties["facsimileTelephoneNumber"].Value,newFacsimilieTelephoneNumber2);\r
+                       }\r
+                       }\r
                }\r
 \r
 \r
@@ -1506,12 +1550,13 @@ namespace MonoTests.System.DirectoryServices
                                                                        configuration.Password,\r
                                                                        configuration.AuthenticationType);\r
 \r
-                       DirectoryEntry cnBarakTsabari = new DirectoryEntry(     barakTsabariDN,\r
+                       using (DirectoryEntry cnBarakTsabari = new DirectoryEntry(      barakTsabariDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
 \r
                        cnBarakTsabari.CopyTo(de);\r
+                       }\r
                }\r
 \r
 \r
@@ -1568,10 +1613,10 @@ namespace MonoTests.System.DirectoryServices
                                                                        configuration.Password,\r
                                                                        configuration.AuthenticationType);\r
 \r
-                       DirectoryEntry johnSmithDE = new DirectoryEntry(johnSmithDN,\r
+                       using (DirectoryEntry johnSmithDE = new DirectoryEntry(johnSmithDN,\r
                                                                                                                        configuration.Username,\r
                                                                                                                        configuration.Password,\r
-                                                                                                                       configuration.AuthenticationType);\r
+                                                                                                                       configuration.AuthenticationType)){\r
 \r
                        johnSmithDE.Properties["telephoneNumber"].Value = "+972 3 9999999";\r
 \r
@@ -1589,6 +1634,7 @@ namespace MonoTests.System.DirectoryServices
                        catch(Exception e) {\r
                                // do nothing\r
                        }\r
+                       }\r
                }\r
 \r
 \r
@@ -1613,17 +1659,17 @@ namespace MonoTests.System.DirectoryServices
                        string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
                        string barakTsabariDevQaDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry barakTsabariDE = new DirectoryEntry(     barakTsabariHumanResourcesDN,\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariHumanResourcesDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
 \r
                        string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
+                       using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
                                                                                                                configuration.Username,\r
                                                                                                                configuration.Password,\r
-                                                                                                               configuration.AuthenticationType);\r
+                                                                                                               configuration.AuthenticationType)){\r
 \r
                        barakTsabariDE.MoveTo(devQaDE);\r
                        barakTsabariDE.CommitChanges();\r
@@ -1632,15 +1678,18 @@ namespace MonoTests.System.DirectoryServices
 \r
                        string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry humanResourcesDE = new DirectoryEntry(   humanRwsourcesOU,\r
+                       using (DirectoryEntry humanResourcesDE = new DirectoryEntry(    humanRwsourcesOU,\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
+                                                                                                                                       configuration.AuthenticationType)){\r
 \r
                        barakTsabariDE.MoveTo(humanResourcesDE);\r
                        barakTsabariDE.CommitChanges();\r
 \r
                        Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));\r
+                       }\r
+                       }\r
+                       }\r
                }\r
 \r
 \r
@@ -1650,17 +1699,17 @@ namespace MonoTests.System.DirectoryServices
                        string barakTsabariHumanResourcesDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
                        string barakTsabariDevQaDN = configuration.ServerRoot + "cn=My Name,ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry barakTsabariDE = new DirectoryEntry(     barakTsabariHumanResourcesDN,\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariHumanResourcesDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
 \r
                        string devQaOU = configuration.ServerRoot + "ou=DevQA,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
+                       using (DirectoryEntry devQaDE = new DirectoryEntry(devQaOU,\r
                                                                                                                configuration.Username,\r
                                                                                                                configuration.Password,\r
-                                                                                                               configuration.AuthenticationType);\r
+                                                                                                               configuration.AuthenticationType)){\r
 \r
                        barakTsabariDE.MoveTo(devQaDE,"cn=My Name");\r
                        barakTsabariDE.CommitChanges();\r
@@ -1669,15 +1718,18 @@ namespace MonoTests.System.DirectoryServices
 \r
                        string humanRwsourcesOU = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry humanResourcesDE = new DirectoryEntry(   humanRwsourcesOU,\r
+                       using (DirectoryEntry humanResourcesDE = new DirectoryEntry(    humanRwsourcesOU,\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
+                                                                                                                                       configuration.AuthenticationType)){\r
 \r
                        barakTsabariDE.MoveTo(humanResourcesDE,"cn=Barak Tsabari");\r
                        barakTsabariDE.CommitChanges();\r
 \r
                        Assert.IsTrue(DirectoryEntry.Exists(barakTsabariHumanResourcesDN));\r
+                       }\r
+                       }\r
+                       }\r
                }\r
 \r
                [Test]\r
@@ -1700,12 +1752,12 @@ namespace MonoTests.System.DirectoryServices
                        string newEmployeeDN = configuration.ServerRoot + "cn=New Employee,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
                        string humanResourcesDN = configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry humanResourcesDE = new DirectoryEntry(   humanResourcesDN,\r
+                       using (DirectoryEntry humanResourcesDE = new DirectoryEntry(    humanResourcesDN,\r
                                                                                                                                        configuration.Username,\r
                                                                                                                                        configuration.Password,\r
-                                                                                                                                       configuration.AuthenticationType);\r
+                                                                                                                                       configuration.AuthenticationType)){\r
 \r
-                       DirectoryEntry newEmployeeDE = humanResourcesDE.Children.Add("cn=New Employee","Class");\r
+                       using (DirectoryEntry newEmployeeDE = humanResourcesDE.Children.Add("cn=New Employee","Class")){\r
                        Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,null);\r
 \r
                        ((PropertyValueCollection)newEmployeeDE.Properties["objectClass"]).Add("person");\r
@@ -1735,6 +1787,8 @@ namespace MonoTests.System.DirectoryServices
                        newEmployeeDE.RefreshCache();\r
 \r
                        Assert.AreEqual(newEmployeeDE.Properties["cn"].Value,"New Employee");\r
+                       }\r
+                       }\r
                }\r
 \r
                [Test]\r
@@ -1771,10 +1825,10 @@ namespace MonoTests.System.DirectoryServices
                        string barakTsabariOldDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
                        string barakTsabariNewDN = configuration.ServerRoot + "cn=My Name,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));\r
 \r
-                       DirectoryEntry barakTsabariDE = new DirectoryEntry(     barakTsabariOldDN,\r
+                       using (DirectoryEntry barakTsabariDE = new DirectoryEntry(      barakTsabariOldDN,\r
                                                                                                                                configuration.Username,\r
                                                                                                                                configuration.Password,\r
-                                                                                                                               configuration.AuthenticationType);\r
+                                                                                                                               configuration.AuthenticationType)){\r
 \r
                        barakTsabariDE.Rename("cn=My Name");\r
                        barakTsabariDE.CommitChanges();\r
@@ -1785,6 +1839,7 @@ namespace MonoTests.System.DirectoryServices
                        barakTsabariDE.CommitChanges();\r
 \r
                        Assert.IsTrue(DirectoryEntry.Exists(barakTsabariOldDN));\r
+                       }\r
                }\r
 \r
                #endregion Tests\r
index f10f300731b52f017219ecb21b9b2d77759a6440..7052de91d78a14304fb8268973dd7ffb13c5e2e0 100644 (file)
@@ -39,7 +39,14 @@ namespace MonoTests.System.DirectoryServices
                [TestFixtureTearDown]\r
                public void TestFixtureTearDown()\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
 \r
@@ -219,17 +226,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(       configuration.ConnectionString,\r
+                       using (DirectoryEntry root = new DirectoryEntry(        configuration.ConnectionString,\r
                                                                                                        configuration.Username,\r
                                                                                                        configuration.Password,\r
-                                                                                                       configuration.AuthenticationType);\r
+                                                                                                       configuration.AuthenticationType)){\r
                        \r
                        foreach(DirectoryEntry child in root.Children) {\r
                                DeleteTree_DFS(child);\r
-                       }               \r
+                       }\r
+                       }\r
                }\r
 \r
 \r
@@ -393,41 +408,48 @@ namespace MonoTests.System.DirectoryServices
                        ds = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
                        ds.CacheResults = true;\r
 \r
-                       SearchResult result = ds.FindOne();\r
-                       DirectoryEntry resultDE = result.GetDirectoryEntry();\r
-\r
-                       string oldValue = (string)((PropertyValueCollection)resultDE.Properties["description"]).Value;\r
+                       string oldValue;\r
                        string newValue = "New Description";\r
 \r
+                       SearchResult result = ds.FindOne();\r
+                       SearchResult secondResult;\r
+                       using (DirectoryEntry resultDE = result.GetDirectoryEntry()){\r
+\r
+                       oldValue = (string)((PropertyValueCollection)resultDE.Properties["description"]).Value;\r
                        ((PropertyValueCollection)resultDE.Properties["description"]).Value = newValue;\r
                        Assert.AreEqual(((PropertyValueCollection)resultDE.Properties["description"]).Value,newValue);\r
 \r
-                       DirectorySearcher secondDs = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
-                       SearchResult secondResult = secondDs.FindOne();\r
-                       DirectoryEntry secondResultDE = secondResult.GetDirectoryEntry();\r
+                       using (DirectorySearcher secondDs = new DirectorySearcher(de,"(cn=Barak Tsabari)")){\r
+                       secondResult = secondDs.FindOne();\r
+                       using (DirectoryEntry secondResultDE = secondResult.GetDirectoryEntry()){\r
 \r
                        Assert.AreEqual(((PropertyValueCollection)secondResultDE.Properties["description"]).Value,oldValue);\r
 \r
                        ((PropertyValueCollection)resultDE.Properties["description"]).Value = oldValue;\r
-                       \r
+                       }\r
+                       }\r
+                       }\r
                        \r
                        ds = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
                        ds.CacheResults = false;\r
                        result = ds.FindOne();\r
-                       resultDE = result.GetDirectoryEntry();\r
+                       using (DirectoryEntry resultDE = result.GetDirectoryEntry()){\r
 \r
                        ((PropertyValueCollection)resultDE.Properties["description"]).Value = newValue;\r
                        Assert.AreEqual(((PropertyValueCollection)resultDE.Properties["description"]).Value,newValue);\r
 \r
-                       secondDs = new DirectorySearcher(de,"(cn=Barak Tsabari)");\r
+                       using (DirectorySearcher secondDs = new DirectorySearcher(de,"(cn=Barak Tsabari)")){\r
                        secondResult = secondDs.FindOne();\r
-                       secondResultDE = secondResult.GetDirectoryEntry();\r
+                       using (DirectoryEntry secondResultDE = secondResult.GetDirectoryEntry()){\r
 \r
                        // LAMESPEC : according to documentation, the value retrieved should be the new one,\r
                        // but actually it is an old one\r
                        Assert.AreEqual(((PropertyValueCollection)secondResultDE.Properties["description"]).Value,oldValue);\r
 \r
-                       ((PropertyValueCollection)resultDE.Properties["description"]).Value = oldValue;                 \r
+                       ((PropertyValueCollection)resultDE.Properties["description"]).Value = oldValue; \r
+                       }\r
+                       }\r
+                       }\r
                }\r
 \r
        \r
index b61be728a7ff9298c672e9ffc34b6cfd28231bdc..487bdbcd1604ae2bb5ef9cfb1ae0c37a887b9e1a 100644 (file)
@@ -37,6 +37,9 @@ namespace MonoTests.System.DirectoryServices
                [TestFixtureTearDown]\r
                public void TestFixtureTearDown()\r
                {\r
+                       if (de != null)\r
+                               de.Dispose ();\r
+\r
                        de = null;\r
                }\r
 \r
@@ -216,17 +219,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(       configuration.ConnectionString,\r
+                       using (DirectoryEntry root = new DirectoryEntry(        configuration.ConnectionString,\r
                                                                                                                configuration.Username,\r
                                                                                                                configuration.Password,\r
-                                                                                                               configuration.AuthenticationType);\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