PageRenderTime 79ms CodeModel.GetById 3ms app.highlight 65ms RepoModel.GetById 1ms app.codeStats 1ms

/mcs/class/System.DirectoryServices/Test/System.DirectoryServices/DirectoryServicesDirectoryEntryTest.cs

https://github.com/ztfuqingvip/mono
C# | 1900 lines | 1373 code | 401 blank | 126 comment | 70 complexity | 515d56f6b0cab2ffd3007124e396e5cb MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1//
   2// DirectoryServicesDirectoryEntryTest.cs -
   3//	NUnit Test Cases for DirectoryServices.DirectoryEntry
   4//
   5// Author:
   6//	Boris Kirzner  <borisk@mainsoft.com>
   7//
   8
   9using NUnit.Framework;
  10using System;
  11using System.DirectoryServices;
  12
  13namespace MonoTests.System.DirectoryServices 
  14{
  15	[TestFixture]
  16	[Category ("InetAccess")]
  17	public class DirectoryServicesDirectoryEntryTest
  18	{
  19		#region Fields
  20
  21		static TestConfiguration configuration;
  22		static DirectoryEntry de;
  23
  24		#endregion // Fields
  25
  26		#region SetUp and TearDown
  27
  28		[TestFixtureSetUp]
  29		public void TestFixtureSetUp()
  30		{
  31			de = null;
  32			configuration = new TestConfiguration ();
  33		}
  34
  35
  36		[TestFixtureTearDown]
  37		public void TestFixtureTearDown()
  38		{
  39			if (de != null)
  40				de.Dispose ();
  41			de = null;
  42		}
  43
  44
  45		[SetUp]
  46		public void SetUp()
  47		{
  48			TearDown();
  49
  50			#region Initialize basics
  51
  52			DirectoryEntry root = new DirectoryEntry(	configuration.ConnectionString,
  53														configuration.Username,
  54														configuration.Password,
  55														configuration.AuthenticationType);
  56			DirectoryEntry ouPeople = root.Children.Add("ou=people","Class");
  57			ouPeople.Properties["objectClass"].Value = "organizationalUnit";
  58			ouPeople.Properties["description"].Value = "All people in organisation";
  59			ouPeople.Properties["ou"].Value = "people";
  60			ouPeople.CommitChanges();
  61
  62			#endregion // Initialize basics
  63
  64			#region Human Resources
  65 
  66			DirectoryEntry ouHumanResources = ouPeople.Children.Add("ou=Human Resources","Class");
  67			ouHumanResources.Properties["objectClass"].Value = "organizationalUnit";
  68			ouHumanResources.Properties["ou"].Value = "Human Resources";
  69			ouHumanResources.CommitChanges();
  70
  71			DirectoryEntry cnJohnSmith = ouHumanResources.Children.Add("cn=John Smith","Class");
  72			cnJohnSmith.Properties["objectClass"].Value = "organizationalRole";
  73			cnJohnSmith.Properties["cn"].Value = "John Smith";
  74			cnJohnSmith.Properties["description"].Value = "Very clever person";
  75			cnJohnSmith.Properties["ou"].Value = "Human Resources";
  76			cnJohnSmith.Properties["telephoneNumber"].Value = "1 801 555 1212";
  77			cnJohnSmith.CommitChanges();
  78
  79			DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class");
  80			((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
  81			((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
  82			cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
  83			cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
  84			((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
  85			((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
  86			cnBarakTsabari.Properties["sn"].Value = "Tsabari";
  87			cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
  88			cnBarakTsabari.CommitChanges();
  89
  90			#endregion // Human Resources
  91
  92			#region R&D
  93
  94			DirectoryEntry ouRnD = ouPeople.Children.Add("ou=R&D","Class");
  95			ouRnD.Properties["objectClass"].Value = "organizationalUnit";
  96			ouRnD.Properties["ou"].Value = "R&D";
  97			ouRnD.CommitChanges();
  98
  99			DirectoryEntry cnYossiCohen = ouRnD.Children.Add("cn=Yossi Cohen","Class");
 100			((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("person");
 101			((PropertyValueCollection)cnYossiCohen.Properties["objectClass"]).Add("organizationalPerson");
 102			cnYossiCohen.Properties["cn"].Value = "Yossi Cohen";
 103			cnYossiCohen.Properties["facsimileTelephoneNumber"].Value = "+1 503 777 4498";
 104			((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("R&D");
 105			((PropertyValueCollection)cnYossiCohen.Properties["ou"]).Add("People");
 106			cnYossiCohen.Properties["sn"].Value = "Cohen";
 107			cnYossiCohen.Properties["telephoneNumber"].Value = "+1 503 777 4499";
 108			cnYossiCohen.CommitChanges();
 109
 110			DirectoryEntry cnUziCohen = ouRnD.Children.Add("cn=Uzi Cohen","Class");
 111			((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("person");
 112			((PropertyValueCollection)cnUziCohen.Properties["objectClass"]).Add("organizationalPerson");
 113			cnUziCohen.Properties["cn"].Value = "Uzi Cohen";
 114			cnUziCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";
 115			((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("R&D");
 116			((PropertyValueCollection)cnUziCohen.Properties["ou"]).Add("People");
 117			cnUziCohen.Properties["sn"].Value = "Cohen";
 118			cnUziCohen.Properties["telephoneNumber"].Value = "+1 602 333 1233";
 119			cnUziCohen.CommitChanges();
 120
 121			DirectoryEntry cnDanielCohen = ouRnD.Children.Add("cn=Daniel Cohen","Class");
 122			((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("person");
 123			((PropertyValueCollection)cnDanielCohen.Properties["objectClass"]).Add("organizationalPerson");
 124			cnDanielCohen.Properties["cn"].Value = "Daniel Cohen";
 125			cnDanielCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1235";
 126			((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("R&D");
 127			((PropertyValueCollection)cnDanielCohen.Properties["ou"]).Add("People");
 128			cnDanielCohen.Properties["sn"].Value = "Cohen";
 129			cnDanielCohen.Properties["telephoneNumber"].Value = "+1 602 333 1236";
 130			cnDanielCohen.CommitChanges();
 131
 132			DirectoryEntry cnSaraCohen = ouRnD.Children.Add("cn=Sara Cohen","Class");
 133			((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("person");
 134			((PropertyValueCollection)cnSaraCohen.Properties["objectClass"]).Add("organizationalPerson");
 135			cnSaraCohen.Properties["cn"].Value = "Sara Cohen";
 136			cnSaraCohen.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1244";
 137			((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("R&D");
 138			((PropertyValueCollection)cnSaraCohen.Properties["ou"]).Add("People");
 139			cnSaraCohen.Properties["sn"].Value = "Cohen";
 140			cnSaraCohen.Properties["telephoneNumber"].Value = "+1 602 333 1243";
 141			cnSaraCohen.CommitChanges();
 142
 143			#endregion // R&D
 144
 145			#region DevQA
 146
 147			DirectoryEntry ouDevQA = ouPeople.Children.Add("ou=DevQA","Class");
 148			ouDevQA.Properties["objectClass"].Value = "organizationalUnit";
 149			ouDevQA.Properties["ou"].Value = "DevQA";
 150			ouDevQA.CommitChanges();
 151
 152			DirectoryEntry cnDanielSmith = ouDevQA.Children.Add("cn=Daniel Smith","Class");
 153			((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("person");
 154			((PropertyValueCollection)cnDanielSmith.Properties["objectClass"]).Add("organizationalPerson");
 155			cnDanielSmith.Properties["cn"].Value = "Daniel Smith";
 156			cnDanielSmith.Properties["facsimileTelephoneNumber"].Value = "+1 408 555 3372";
 157			cnDanielSmith.Properties["l"].Value = "Santa Clara";
 158			((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("DevQA");
 159			((PropertyValueCollection)cnDanielSmith.Properties["ou"]).Add("People");
 160			cnDanielSmith.Properties["sn"].Value = "Smith";
 161			cnDanielSmith.Properties["telephoneNumber"].Value = "+1 408 555 9519";
 162			cnDanielSmith.CommitChanges();
 163
 164			DirectoryEntry cnDanielMorgan = ouDevQA.Children.Add("cn=Daniel Morgan","Class");
 165			((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("person");
 166			((PropertyValueCollection)cnDanielMorgan.Properties["objectClass"]).Add("organizationalPerson");
 167			cnDanielMorgan.Properties["cn"].Value = "Daniel Morgan";
 168			cnDanielMorgan.Properties["facsimileTelephoneNumber"].Value = "+1 805 666 5645";
 169			((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("DevQA");
 170			((PropertyValueCollection)cnDanielMorgan.Properties["ou"]).Add("People");
 171			cnDanielMorgan.Properties["sn"].Value = "Morgan";
 172			cnDanielMorgan.Properties["telephoneNumber"].Value = "+1 805 666 5644";
 173			cnDanielMorgan.CommitChanges();
 174
 175			#endregion // DevQA
 176
 177			#region Manager
 178
 179			DirectoryEntry cnManager = root.Children.Add("cn=Manager","Class");
 180			cnManager.Properties["objectClass"].Value = "organizationalRole";
 181			cnManager.Properties["cn"].Value = "Manager";
 182			cnManager.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1238";
 183			cnManager.CommitChanges();
 184
 185			DirectoryEntry cnUziCohen_ = cnManager.Children.Add("cn=Uzi Cohen","Class");
 186			((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("person");
 187			((PropertyValueCollection)cnUziCohen_.Properties["objectClass"]).Add("organizationalPerson");
 188			cnUziCohen_.Properties["cn"].Value = "Uzi Cohen";
 189			cnUziCohen_.Properties["facsimileTelephoneNumber"].Value = "+1 602 333 1234";
 190			((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("R&D");
 191			((PropertyValueCollection)cnUziCohen_.Properties["ou"]).Add("People");
 192			cnUziCohen_.Properties["sn"].Value = "Cohen";
 193			cnUziCohen_.Properties["telephoneNumber"].Value = "+1 602 333 1233";
 194			cnUziCohen_.CommitChanges();
 195
 196			#endregion // Manager
 197						
 198			cnJohnSmith.Dispose();
 199			cnBarakTsabari.Dispose();
 200			ouHumanResources.Dispose();
 201			cnUziCohen.Dispose();
 202			cnYossiCohen.Dispose();
 203			cnDanielCohen.Dispose();
 204			cnSaraCohen.Dispose();
 205			ouRnD.Dispose();
 206			cnDanielSmith.Dispose();
 207			cnDanielMorgan.Dispose();
 208			ouDevQA.Dispose();
 209			cnUziCohen_.Dispose();
 210			cnManager.Dispose();
 211			ouPeople.Dispose();
 212			root.Dispose();
 213		}
 214
 215
 216		[TearDown]
 217		public void TearDown()
 218		{
 219			if (de != null)
 220				de.Dispose ();
 221
 222			de = null;
 223
 224			using (DirectoryEntry root = new DirectoryEntry(	configuration.ConnectionString,
 225														configuration.Username,
 226														configuration.Password,
 227														configuration.AuthenticationType)) {
 228			
 229			foreach(DirectoryEntry child in root.Children) {
 230				DeleteTree_DFS(child);
 231			}
 232			}
 233		}
 234
 235		private void DeleteTree_DFS(DirectoryEntry de)
 236		{
 237			foreach(DirectoryEntry child in de.Children) {
 238				DeleteTree_DFS(child);
 239			}
 240			de.DeleteTree();
 241			de.CommitChanges();
 242		}
 243
 244		#endregion //SetUp and TearDown
 245
 246		#region Tests
 247
 248		[Test]
 249		public void DirectoryEntry_DirectoryEntry()
 250		{
 251			de = new DirectoryEntry();
 252
 253			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
 254#if !NET_2_0
 255			Assert.AreEqual (de.Password, null);
 256#endif
 257			Assert.AreEqual(de.Path,String.Empty);
 258			Assert.AreEqual(de.UsePropertyCache,true);
 259			Assert.AreEqual(de.Username,null);		
 260		}
 261
 262
 263		[Test]
 264		public void DirectoryEntry_DirectoryEntry_Str()
 265		{
 266			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString)) {
 267			
 268			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
 269			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 270#if !NET_2_0
 271			Assert.AreEqual(de.Password,null);
 272#endif
 273			Assert.AreEqual(de.Path,configuration.ConnectionString);
 274			Assert.AreEqual(de.SchemaClassName,"organization");
 275			Assert.AreEqual(de.UsePropertyCache,true);
 276			Assert.AreEqual(de.Username,null);
 277			}
 278		}
 279
 280
 281		[Test]
 282		public void DirectoryEntry_DirectoryEntry_StrStrStrAuth()
 283		{
 284			if ((configuration.AuthenticationType != AuthenticationTypes.ServerBind) && 
 285				(configuration.AuthenticationType != AuthenticationTypes.None) && 
 286				(configuration.AuthenticationType != AuthenticationTypes.Anonymous))
 287				return;
 288
 289			#region AuthenticationTypes.Anonymous
 290
 291			using (DirectoryEntry de = new DirectoryEntry(	configuration.ConnectionString,
 292													configuration.Username,
 293													configuration.Password,
 294													AuthenticationTypes.Anonymous)){
 295			
 296			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
 297			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 298			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 299			//Assert.AreEqual(de.NativeGuid,null);
 300#if !NET_2_0
 301			Assert.AreEqual(de.Password,configuration.Password);
 302#endif
 303			Assert.AreEqual(de.Path,configuration.ConnectionString);
 304			Assert.AreEqual(de.SchemaClassName,"organization");
 305			Assert.AreEqual(de.UsePropertyCache,true);
 306			Assert.AreEqual(de.Username,configuration.Username);
 307			}
 308
 309			#endregion //AuthenticationTypes.Anonymous
 310
 311			#region AuthenticationTypes.Delegation
 312
 313			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 314									configuration.Username,
 315									configuration.Password,
 316									AuthenticationTypes.Delegation)){
 317			
 318			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
 319			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 320			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 321			//Assert.AreEqual(de.NativeGuid,null);
 322#if !NET_2_0
 323			Assert.AreEqual(de.Password,configuration.Password);
 324#endif
 325			Assert.AreEqual(de.Path,configuration.ConnectionString);
 326			Assert.AreEqual(de.SchemaClassName,"organization");
 327			Assert.AreEqual(de.UsePropertyCache,true);
 328			Assert.AreEqual(de.Username,configuration.Username);
 329			}
 330
 331			#endregion //AuthenticationTypes.Delegation
 332
 333			#region AuthenticationTypes.Encryption
 334
 335			//			de = new DirectoryEntry(	configuration.ConnectionString,
 336			//													configuration.Username,
 337			//													configuration.Password,
 338			//													AuthenticationTypes.Encryption);
 339			//			
 340			//			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
 341			//			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 342			//			Assert.AreEqual(de.Name,"dc=myhosting");
 343			//			//Assert.AreEqual(de.NativeGuid,null);
 344			//			Assert.AreEqual(de.Password,configuration.Password);
 345			//			Assert.AreEqual(de.Path,configuration.ConnectionString);
 346			//			Assert.AreEqual(de.SchemaClassName,"organization");
 347			//			Assert.AreEqual(de.UsePropertyCache,true);
 348			//			Assert.AreEqual(de.Username,configuration.Username);
 349
 350			#endregion //AuthenticationTypes.Encryption
 351
 352			#region AuthenticationTypes.FastBind
 353
 354			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 355									configuration.Username,
 356									configuration.Password,
 357									AuthenticationTypes.FastBind)){
 358			
 359			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
 360			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 361			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 362			//Assert.AreEqual(de.NativeGuid,null);
 363#if !NET_2_0
 364			Assert.AreEqual(de.Password,configuration.Password);
 365#endif
 366			Assert.AreEqual(de.Path,configuration.ConnectionString);
 367			Assert.AreEqual(de.SchemaClassName,"organization");
 368			Assert.AreEqual(de.UsePropertyCache,true);
 369			Assert.AreEqual(de.Username,configuration.Username);
 370			}
 371
 372			#endregion //AuthenticationTypes.FastBind
 373
 374			#region AuthenticationTypes.None
 375
 376			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 377									configuration.Username,
 378									configuration.Password,
 379									AuthenticationTypes.None)){
 380			
 381			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
 382			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 383			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 384			//Assert.AreEqual(de.NativeGuid,null);
 385#if !NET_2_0
 386			Assert.AreEqual(de.Password,configuration.Password);
 387#endif
 388			Assert.AreEqual(de.Path,configuration.ConnectionString);
 389			Assert.AreEqual(de.SchemaClassName,"organization");
 390			Assert.AreEqual(de.UsePropertyCache,true);
 391			Assert.AreEqual(de.Username,configuration.Username);
 392			}
 393
 394			#endregion //AuthenticationTypes.None
 395
 396			#region AuthenticationTypes.ReadonlyServer
 397
 398			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 399									configuration.Username,
 400									configuration.Password,
 401									AuthenticationTypes.ReadonlyServer)){
 402			
 403			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
 404			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 405			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 406			//Assert.AreEqual(de.NativeGuid,null);
 407#if !NET_2_0
 408			Assert.AreEqual(de.Password,configuration.Password);
 409#endif
 410			Assert.AreEqual(de.Path,configuration.ConnectionString);
 411			Assert.AreEqual(de.SchemaClassName,"organization");
 412			Assert.AreEqual(de.UsePropertyCache,true);
 413			Assert.AreEqual(de.Username,configuration.Username);
 414			}
 415
 416			#endregion //AuthenticationTypes.ReadonlyServer
 417
 418			#region AuthenticationTypes.Sealing
 419
 420			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 421									configuration.Username,
 422									configuration.Password,
 423									AuthenticationTypes.Sealing)){
 424			
 425			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
 426			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 427			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 428			//Assert.AreEqual(de.NativeGuid,null);
 429#if !NET_2_0
 430			Assert.AreEqual(de.Password,configuration.Password);
 431#endif
 432			Assert.AreEqual(de.Path,configuration.ConnectionString);
 433			Assert.AreEqual(de.SchemaClassName,"organization");
 434			Assert.AreEqual(de.UsePropertyCache,true);
 435			Assert.AreEqual(de.Username,configuration.Username);
 436			}
 437
 438			#endregion //AuthenticationTypes.Sealing
 439
 440			#region AuthenticationTypes.Secure
 441
 442			//			de = new DirectoryEntry(configuration.ConnectionString,
 443			//									configuration.Username,
 444			//									configuration.Password,
 445			//									AuthenticationTypes.Secure);
 446			//			
 447			//			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
 448			//			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 449			//			Assert.AreEqual(de.Name,"dc=myhosting");
 450			//			//Assert.AreEqual(de.NativeGuid,null);
 451			//			Assert.AreEqual(de.Password,configuration.Password);
 452			//			Assert.AreEqual(de.Path,configuration.ConnectionString);
 453			//			Assert.AreEqual(de.SchemaClassName,"organization");
 454			//			Assert.AreEqual(de.UsePropertyCache,true);
 455			//			Assert.AreEqual(de.Username,configuration.Username);
 456
 457			#endregion //AuthenticationTypes.Secure
 458
 459			#region AuthenticationTypes.SecureSocketsLayer
 460
 461			//			de = new DirectoryEntry(configuration.ConnectionString,
 462			//									configuration.Username,
 463			//									configuration.Password,
 464			//									AuthenticationTypes.SecureSocketsLayer);
 465			//			
 466			//			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
 467			//			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 468			//			Assert.AreEqual(de.Name,"dc=myhosting");
 469			//			//Assert.AreEqual(de.NativeGuid,null);
 470			//			Assert.AreEqual(de.Password,configuration.Password);
 471			//			Assert.AreEqual(de.Path,configuration.ConnectionString);
 472			//			Assert.AreEqual(de.SchemaClassName,"organization");
 473			//			Assert.AreEqual(de.UsePropertyCache,true);
 474			//			Assert.AreEqual(de.Username,configuration.Username);
 475
 476			#endregion //AuthenticationTypes.SecureSocketsLayer
 477
 478			#region AuthenticationTypes.ServerBind
 479
 480			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 481									configuration.Username,
 482									configuration.Password,
 483									AuthenticationTypes.ServerBind)){
 484			
 485			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
 486			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 487			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 488			//Assert.AreEqual(de.NativeGuid,null);
 489#if !NET_2_0
 490			Assert.AreEqual(de.Password,configuration.Password);
 491#endif
 492			Assert.AreEqual(de.Path,configuration.ConnectionString);
 493			Assert.AreEqual(de.SchemaClassName,"organization");
 494			Assert.AreEqual(de.UsePropertyCache,true);
 495			Assert.AreEqual(de.Username,configuration.Username);
 496			}
 497
 498			#endregion //AuthenticationTypes.ServerBind
 499
 500			#region AuthenticationTypes.Signing
 501
 502			using (DirectoryEntry de = new DirectoryEntry(configuration.ConnectionString,
 503									configuration.Username,
 504									configuration.Password,
 505									AuthenticationTypes.Signing)){
 506			
 507			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
 508			//Assert.AreEqual(de.Guid,new Guid("0b045012-1d97-4f94-9d47-87cbf6dada46"));
 509			Assert.AreEqual(de.Name,GetName (configuration.BaseDn));
 510			//Assert.AreEqual(de.NativeGuid,null);
 511#if !NET_2_0
 512			Assert.AreEqual(de.Password,configuration.Password);
 513#endif
 514			Assert.AreEqual(de.Path,configuration.ConnectionString);
 515			Assert.AreEqual(de.SchemaClassName,"organization");
 516			Assert.AreEqual(de.UsePropertyCache,true);
 517			Assert.AreEqual(de.Username,configuration.Username);
 518			}
 519
 520			#endregion //AuthenticationTypes.Signing
 521		}
 522
 523		[Test]
 524		public void DirectoryEntry_Dispose()
 525		{
 526			using (DirectoryEntry root = new DirectoryEntry(	configuration.ConnectionString,
 527														configuration.Username,
 528														configuration.Password,
 529														configuration.AuthenticationType)){
 530
 531			DirectoryEntry ouPeople = root.Children.Add("ou=printers","Class");
 532			ouPeople.Properties["objectClass"].Value = "organizationalUnit";
 533			ouPeople.Properties["description"].Value = "All printers in organisation";
 534			ouPeople.Properties["ou"].Value = "printers";
 535			ouPeople.CommitChanges();
 536
 537			ouPeople.Rename("ou=anotherPrinters");
 538			ouPeople.CommitChanges();
 539
 540			Assert.IsTrue(DirectoryEntry.Exists(configuration.ServerRoot + "ou=anotherPrinters" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))));
 541			}
 542		}
 543
 544
 545		[Test]
 546		public void DirectoryEntry_AuthenticationType()
 547		{
 548			de = new DirectoryEntry();
 549
 550			de.AuthenticationType = AuthenticationTypes.Anonymous;
 551			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
 552
 553			de.AuthenticationType = AuthenticationTypes.Delegation;
 554			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
 555
 556			de.AuthenticationType = AuthenticationTypes.Encryption;
 557			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
 558
 559			de.AuthenticationType = AuthenticationTypes.FastBind;
 560			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
 561
 562			de.AuthenticationType = AuthenticationTypes.None;
 563			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
 564
 565			de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
 566			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
 567
 568			de.AuthenticationType = AuthenticationTypes.Sealing;
 569			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
 570
 571			de.AuthenticationType = AuthenticationTypes.Secure;
 572			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
 573
 574			de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
 575			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
 576
 577			de.AuthenticationType = AuthenticationTypes.ServerBind;
 578			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
 579
 580			de.AuthenticationType = AuthenticationTypes.Signing;
 581			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
 582
 583			de = new DirectoryEntry(configuration.ConnectionString);
 584
 585			de.AuthenticationType = AuthenticationTypes.Anonymous;
 586			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
 587
 588			de.AuthenticationType = AuthenticationTypes.Delegation;
 589			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
 590
 591			de.AuthenticationType = AuthenticationTypes.Encryption;
 592			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
 593
 594			de.AuthenticationType = AuthenticationTypes.FastBind;
 595			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
 596
 597			de.AuthenticationType = AuthenticationTypes.None;
 598			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
 599
 600			de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
 601			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
 602
 603			de.AuthenticationType = AuthenticationTypes.Sealing;
 604			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
 605
 606			de.AuthenticationType = AuthenticationTypes.Secure;
 607			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
 608
 609			de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
 610			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
 611
 612			de.AuthenticationType = AuthenticationTypes.ServerBind;
 613			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
 614
 615			de.AuthenticationType = AuthenticationTypes.Signing;
 616			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
 617
 618			de = new DirectoryEntry(configuration.ConnectionString,
 619									configuration.Username,
 620									configuration.Password,
 621									AuthenticationTypes.None);
 622
 623			de.AuthenticationType = AuthenticationTypes.Anonymous;
 624			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Anonymous);
 625
 626			de.AuthenticationType = AuthenticationTypes.Delegation;
 627			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Delegation);
 628
 629			de.AuthenticationType = AuthenticationTypes.Encryption;
 630			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Encryption);
 631
 632			de.AuthenticationType = AuthenticationTypes.FastBind;
 633			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.FastBind);
 634
 635			de.AuthenticationType = AuthenticationTypes.None;
 636			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.None);
 637
 638			de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
 639			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ReadonlyServer);
 640
 641			de.AuthenticationType = AuthenticationTypes.Sealing;
 642			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Sealing);
 643
 644			de.AuthenticationType = AuthenticationTypes.Secure;
 645			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Secure);
 646
 647			de.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
 648			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.SecureSocketsLayer);
 649
 650			de.AuthenticationType = AuthenticationTypes.ServerBind;
 651			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.ServerBind);
 652
 653			de.AuthenticationType = AuthenticationTypes.Signing;
 654			Assert.AreEqual(de.AuthenticationType,AuthenticationTypes.Signing);
 655		}
 656
 657		
 658		[Test]
 659		public void DirectoryEntry_UsePropertyCache()
 660		{
 661			string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
 662			de = new DirectoryEntry(barakTsabariDN,
 663									configuration.Username,
 664									configuration.Password,
 665									configuration.AuthenticationType);
 666
 667			// UsePropertyCache = true
 668			de.UsePropertyCache = true;
 669			Assert.AreEqual(de.UsePropertyCache,true);
 670
 671			#region Check Properties
 672
 673			// Properties changes are cached
 674			string oldTelephoneNumber = (string)de.Properties["telephoneNumber"].Value;
 675			string newTelephoneNumber = "+972-3-6572345";
 676
 677			de.Properties["telephoneNumber"].Value = newTelephoneNumber;
 678			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(	barakTsabariDN,
 679																configuration.Username,
 680																configuration.Password,
 681																configuration.AuthenticationType)){
 682
 683			Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
 684			de.CommitChanges();
 685			}
 686			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 687												configuration.Username,
 688												configuration.Password,
 689												configuration.AuthenticationType)){
 690			Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
 691
 692			// restore object state
 693			de.Properties["telephoneNumber"].Value = oldTelephoneNumber;
 694			de.CommitChanges();
 695			}
 696
 697			#endregion // Check Properties
 698
 699			#region Check DeleteTree
 700
 701			// DeleteTree is not cached
 702			de.DeleteTree();
 703			try {
 704				using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 705													configuration.Username,
 706													configuration.Password,
 707													configuration.AuthenticationType)){
 708				barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
 709				barakTsabariDE.CommitChanges();
 710				Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
 711				}
 712			}
 713			catch(AssertionException ae) {
 714				throw ae;
 715			}
 716			catch (Exception e) {
 717				// do nothing
 718			}
 719
 720			// restore object state
 721			using (DirectoryEntry ouHumanResources = new DirectoryEntry(	configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 722																	configuration.Username,
 723																	configuration.Password,
 724																	configuration.AuthenticationType)){
 725			using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
 726			((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
 727			((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
 728			cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
 729			cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
 730			((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
 731			((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
 732			cnBarakTsabari.Properties["sn"].Value = "Tsabari";
 733			cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
 734			cnBarakTsabari.CommitChanges();
 735			}
 736			}
 737
 738			#endregion // Check DeleteTree
 739
 740			#region Check MoveTo
 741
 742			// Move to is not cached
 743			de = new DirectoryEntry(barakTsabariDN,
 744									configuration.Username,
 745									configuration.Password,
 746									configuration.AuthenticationType);
 747
 748			using (DirectoryEntry ouRnD = new DirectoryEntry(	configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 749														configuration.Username,
 750														configuration.Password,
 751														configuration.AuthenticationType)){
 752			de.MoveTo(ouRnD);
 753			try {
 754				using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 755													configuration.Username,
 756													configuration.Password,
 757													configuration.AuthenticationType)){
 758				barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
 759				barakTsabariDE.CommitChanges();
 760				Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
 761				}
 762			}
 763			catch(AssertionException ae) {
 764				throw ae;
 765			}
 766			catch (Exception e) {
 767				// do nothing
 768			}
 769			}
 770
 771			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 772												configuration.Username,
 773												configuration.Password,
 774												configuration.AuthenticationType)){
 775			Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
 776			}
 777			
 778
 779			// restore object state
 780			using (DirectoryEntry ouHumanResources = new DirectoryEntry(	configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 781																	configuration.Username,
 782																	configuration.Password,
 783																	configuration.AuthenticationType)){
 784			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 785												configuration.Username,
 786												configuration.Password,
 787												configuration.AuthenticationType)){
 788			barakTsabariDE.MoveTo(ouHumanResources);
 789			barakTsabariDE.CommitChanges();
 790			}
 791			}
 792
 793			#endregion // Check MoveTo
 794
 795			#region Check Rename
 796
 797			// Rename not chached
 798			de = new DirectoryEntry(barakTsabariDN,
 799									configuration.Username,
 800									configuration.Password,
 801									configuration.AuthenticationType);
 802
 803			de.Rename("cn=MyUser");
 804
 805			try {
 806				using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 807													configuration.Username,
 808													configuration.Password,
 809													configuration.AuthenticationType)){
 810				barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
 811				barakTsabariDE.CommitChanges();
 812				Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
 813				}
 814			}
 815			catch(AssertionException ae) {
 816				throw ae;
 817			}
 818			catch (Exception e) {
 819				// do nothing
 820			}
 821
 822			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 823												configuration.Username,
 824												configuration.Password,
 825												configuration.AuthenticationType)){
 826			Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
 827			}
 828
 829			// restore object state
 830			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 831												configuration.Username,
 832												configuration.Password,
 833												configuration.AuthenticationType)){
 834			barakTsabariDE.Rename("cn=Barak Tsabari");
 835			barakTsabariDE.CommitChanges();
 836			}
 837
 838			#endregion // Check Rename
 839
 840			// UsePropertyCache = false	
 841			de = new DirectoryEntry(barakTsabariDN,
 842									configuration.Username,
 843									configuration.Password,
 844									configuration.AuthenticationType);
 845			de.UsePropertyCache = false;
 846			Assert.AreEqual(de.UsePropertyCache,false);
 847
 848			#region Check Properties
 849
 850			// Properties changes not cached
 851			de.Properties["telephoneNumber"].Value = newTelephoneNumber;
 852			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 853												configuration.Username,
 854												configuration.Password,
 855												configuration.AuthenticationType)){
 856			}
 857
 858			//Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,newTelephoneNumber);
 859
 860			#endregion // Check Properties
 861
 862			#region Check DeleteTree
 863
 864			// DeleteTree is not cached
 865			de.DeleteTree();
 866			try {
 867				using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 868													configuration.Username,
 869													configuration.Password,
 870													configuration.AuthenticationType)){
 871				barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
 872				barakTsabariDE.CommitChanges();
 873				Assert.Fail("Object " + barakTsabariDN + " was not deleted from server.");
 874				}
 875			}
 876			catch(AssertionException ae) {
 877				throw ae;
 878			}
 879			catch (Exception e) {
 880				// do nothing
 881			}
 882
 883			// restore object state
 884			using (DirectoryEntry ouHumanResources = new DirectoryEntry(	configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 885																	configuration.Username,
 886																	configuration.Password,
 887																	configuration.AuthenticationType)){
 888			using (DirectoryEntry cnBarakTsabari = ouHumanResources.Children.Add("cn=Barak Tsabari","Class")){
 889			((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("person");
 890			((PropertyValueCollection)cnBarakTsabari.Properties["objectClass"]).Add("organizationalPerson");
 891			cnBarakTsabari.Properties["cn"].Value = "Barak Tsabari";
 892			cnBarakTsabari.Properties["facsimileTelephoneNumber"].Value = "+1 906 777 8853";
 893			((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("Human Resources");
 894			((PropertyValueCollection)cnBarakTsabari.Properties["ou"]).Add("People");
 895			cnBarakTsabari.Properties["sn"].Value = "Tsabari";
 896			cnBarakTsabari.Properties["telephoneNumber"].Value = "+1 906 777 8854";
 897			cnBarakTsabari.CommitChanges();
 898			}
 899			}
 900
 901			#endregion // Check DeleteTree
 902
 903			#region Check MoveTo
 904
 905			// Move to is not cached
 906			de = new DirectoryEntry(barakTsabariDN,
 907									configuration.Username,
 908									configuration.Password,
 909									configuration.AuthenticationType);
 910
 911			using (DirectoryEntry ouRnD = new DirectoryEntry(	configuration.ServerRoot + "ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 912										configuration.Username,
 913										configuration.Password,
 914										configuration.AuthenticationType)){
 915			de.MoveTo(ouRnD);
 916			}
 917			try {
 918				using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 919													configuration.Username,
 920													configuration.Password,
 921													configuration.AuthenticationType)){
 922				barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
 923				barakTsabariDE.CommitChanges();
 924				Assert.Fail("Object " + barakTsabariDN + " was not moved from old location on the server.");
 925				}
 926			}
 927			catch(AssertionException ae) {
 928				throw ae;
 929			}
 930			catch (Exception e) {
 931				// do nothing
 932			}
 933
 934
 935			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 936												configuration.Username,
 937												configuration.Password,
 938												configuration.AuthenticationType)){
 939			Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
 940			}
 941			
 942
 943			// restore object state
 944			using (DirectoryEntry ouHumanResources = new DirectoryEntry(	configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 945																	configuration.Username,
 946																	configuration.Password,
 947																	configuration.AuthenticationType)){
 948			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=R&D,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 949												configuration.Username,
 950												configuration.Password,
 951												configuration.AuthenticationType)){
 952			barakTsabariDE.MoveTo(ouHumanResources);
 953			barakTsabariDE.CommitChanges();
 954			}
 955			}
 956
 957			#endregion // Check MoveTo
 958
 959			#region Check Rename
 960
 961			// Rename not chached
 962			de = new DirectoryEntry(barakTsabariDN,
 963									configuration.Username,
 964									configuration.Password,
 965									configuration.AuthenticationType);
 966
 967			de.Rename("cn=MyUser");
 968
 969			try {
 970				using (DirectoryEntry barakTsabariDE = new DirectoryEntry(barakTsabariDN,
 971													configuration.Username,
 972													configuration.Password,
 973													configuration.AuthenticationType)){
 974				barakTsabariDE.Properties["telephoneNumber"].Value = newTelephoneNumber;
 975				barakTsabariDE.CommitChanges();
 976				Assert.Fail("Object " + barakTsabariDN + " was not renamed on the server.");
 977				}
 978			}
 979			catch(AssertionException ae) {
 980				throw ae;
 981			}
 982			catch (Exception e) {
 983				// do nothing
 984			}
 985
 986			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 987												configuration.Username,
 988												configuration.Password,
 989												configuration.AuthenticationType)){
 990			Assert.AreEqual(barakTsabariDE.Properties["telephoneNumber"].Value,oldTelephoneNumber);
 991			}
 992
 993			// restore object state
 994			using (DirectoryEntry barakTsabariDE = new DirectoryEntry(configuration.ServerRoot + "cn=MyUser,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)),
 995												configuration.Username,
 996												configuration.Password,
 997												configuration.AuthenticationType)){
 998			barakTsabariDE.Rename("cn=Barak Tsabari");
 999			barakTsabariDE.CommitChanges();
1000			}
1001
1002			#endregion // Check Rename
1003		}
1004
1005		[Test]
1006		[Category("NotWorking")]
1007		public void DirectoryEntry_Children()
1008		{
1009			de = new DirectoryEntry();
1010			DirectoryEntries children = de.Children;
1011			//Assert.AreEqual(children.SchemaFilter.Count,0);	
1012
1013
1014			de = new DirectoryEntry(configuration.ConnectionString);
1015			children = de.Children;
1016
1017			//Assert.AreEqual(children.SchemaFilter.Count,0);
1018
1019			int childrenCount = 0;
1020			foreach(DirectoryEntry childDe in children) {
1021				childrenCount++;
1022			}
1023			Assert.AreEqual(childrenCount,2);
1024			Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
1025			Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
1026
1027
1028			de = new DirectoryEntry(configuration.ConnectionString,
1029									configuration.Username,
1030									configuration.Password,
1031									configuration.AuthenticationType);
1032			children = de.Children;
1033
1034			//Assert.AreEqual(children.SchemaFilter.Count,0);
1035
1036			childrenCount = 0;
1037			foreach(DirectoryEntry childDe in children) {
1038				childrenCount++;
1039			}
1040			Assert.AreEqual(childrenCount,2);
1041			Assert.AreEqual(children.Find("ou=people").Name,"ou=people");
1042			Assert.AreEqual(children.Find("cn=Manager").Name,"cn=Manager");
1043
1044			de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
1045									configuration.Username,
1046									configuration.Password,
1047									configuration.AuthenticationType);
1048			children = de.Children;
1049
1050			Assert.AreEqual(children.Find("cn=Barak Tsabari").Name,"cn=Barak Tsabari");
1051			Assert.AreEqual(children.Find("cn=John Smith").Name,"cn=John Smith");
1052		}
1053
1054		[Test]
1055		public void DirectoryEntry_Name()
1056		{
1057			de = new DirectoryEntry(configuration.ConnectionString);
1058
1059			de = new DirectoryEntry(configuration.ConnectionString,
1060									configuration.Username,
1061									configuration.Password,
1062									configuration.AuthenticationType);
1063
1064			de = new DirectoryEntry(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
1065									configuration.Username,
1066									configuration.Password,
1067									configuration.AuthenticationType);
1068			Assert.AreEqual(de.Name,"ou=Human Resources");
1069
1070			de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
1071									configuration.Username,
1072									configuration.Password,
1073									configuration.AuthenticationType);
1074			Assert.AreEqual(de.Name,"cn=Barak Tsabari");
1075		}
1076		
1077
1078		[Test]
1079		public void DirectoryEntry_Parent()
1080		{
1081			de = new DirectoryEntry(configuration.ConnectionString);
1082
1083			// MS works only with "LDAP" while RFC2255 states "ldap"
1084			Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
1085
1086			de = new DirectoryEntry(configuration.ConnectionString,
1087									configuration.Username,
1088									configuration.Password,
1089									configuration.AuthenticationType);
1090
1091			// MS works only with "LDAP" while RFC2255 states "ldap"
1092			Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + GetParentDN (configuration.BaseDn)).ToLower());
1093
1094			de = new DirectoryEntry(configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn)) ,
1095									configuration.Username,
1096									configuration.Password,
1097									configuration.AuthenticationType);
1098
1099			// MS works only with "LDAP" while RFC2255 states "ldap"
1100			Assert.AreEqual(de.Parent.Path.ToLower(),(configuration.ServerRoot + "ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn))).ToLower());
1101		}
1102
1103#if !NET_2_0
1104		[Test]
1105		public void DirectoryEntry_Password()
1106		{
1107			string wrongPassword = "some wrong password";
1108
1109			de = new DirectoryEntry();
1110
1111			Assert.AreEqual(de.Password,null);
1112
1113			de.Password = configuration.Password;
1114			Assert.AreEqual(de.Password,configuration.Password);
1115
1116			de.Password = "";
1117			Assert.AreEqual(de.Password,String.Empty);
1118			
1119			de.Password = wrongPassword;
1120			Assert.AreEqual(de.Password,wrongPassword);
1121
1122
1123			de = new DirectoryEntry(configuration.ConnectionString);
1124
1125			de.Password = configuration.Password;
1126			Assert.AreEqual(de.Password,configuration.Password);
1127
1128			de.Password = "";
1129			Assert.AreEqual(de.Password,String.Empty);
1130
1131			de.Password = wrongPassword;
1132			Assert.AreEqual(de.Password,wrongPassword);
1133
1134			
1135			de = new DirectoryEntry(configuration.ConnectionString,
1136									configuration.Username,
1137									configuration.Password,
1138									configuration.AuthenticationType);
1139
1140			de.Password = configuration.Password;
1141			Assert.AreEqual(de.Password,configuration.Password);
1142
1143			de.Password = "";
1144			Assert.AreEqual(de.Password,String.Empty);
1145
1146			de.Password = wrongPassword;
1147			Assert.AreEqual(de.Password,wrongPassword);
1148		}
1149#endif
1150
1151		[Test]
1152		public void DirectoryEntry_Path()
1153		{
1154			string wrongPath = "something that is not LDAP path";
1155
1156			de = new DirectoryEntry();
1157
1158			Assert.AreEqual(de.Path,String.Empty);
1159
1160			de.Path = configuration.ConnectionString;
1161			Assert.AreEqual(de.Path,configuration.ConnectionString);
1162
1163			de.Path = "";
1164			Assert.AreEqual(de.Path,String.Empty);
1165			
1166			de.Path = wrongPath;
1167			Assert.AreEqual(de.Path,wrongPath);
1168
1169
1170			de = new DirectoryEntry(configuration.ConnectionString);
1171
1172			de.Path = configuration.ConnectionString;
1173			Assert.AreEqual(de.Path,configuration.ConnectionString);
1174
1175			de.Path = "";
1176			Assert.AreEqual(de.Path,String.Empty);
1177
1178			de.Path = wrongPath;
1179			Assert.AreEqual(de.Path,wrongPath);
1180
1181			
1182			de = new DirectoryEntry(configuration.ConnectionString,
1183									configuration.Username,
1184									configuration.Password,
1185									configuration.AuthenticationType);
1186
1187			de.Path = configuration.ConnectionString;
1188			Assert.AreEqual(de.Path,configuration.ConnectionString);
1189
1190			de.Path = "";
1191			Assert.AreEqual(de.Path,String.Empty);
1192
1193			de.Path = wrongPath;
1194			Assert.AreEqual(de.Path,wrongPath);
1195
1196			de = new DirectoryEntry("ldap://myhost:389/ou=people",null,null,AuthenticationTypes.None);
1197			Assert.AreEqual(de.Path,"ldap://myhost:389/ou=people");
1198
1199			de.Path = null;
1200			Assert.AreEqual(de.Path,String.Empty);
1201		}
1202
1203
1204		[Test]
1205		public void DirectoryEntry_Properties1()
1206		{
1207			de = new DirectoryEntry(configuration.ConnectionString);
1208
1209			Assert.AreEqual(de.Properties.Count,3);
1210			Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
1211			Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
1212
1213			
1214			de = new DirectoryEntry(configuration.ConnectionString,
1215									configuration.Username,
1216									configuration.Password,
1217									configuration.AuthenticationType);
1218
1219			Assert.AreEqual(de.Properties.Count,3);
1220			Assert.AreEqual(((PropertyValueCollection)de.Properties["dc"]).Value,"example");
1221			Assert.AreEqual(((PropertyValueCollection)de.Properties["description"]).Value,null);
1222
1223			// ensure that properties are not accessible after removing an entry from the server
1224			string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
1225			de = new DirectoryEntry(barakTsabariDN,
1226									configuration.Username,
1227									configuration.Password,
1228									configuration.AuthenticationType);
1229			
1230			de.DeleteTree();
1231			
1232			try {
1233				int i = de.Properties.Count;
1234				Assert.Fail("Properties should not be accessible after deleting an entry from the server");
1235			}
1236			catch(AssertionException ae) {
1237				throw ae;
1238			}
1239			catch(Exception e) {
1240				// supress exception
1241			}
1242
1243			try {
1244				string s = (string)((PropertyValueCollection)de.Properties["dc"]).Value;
1245				Assert.Fail("Properties should not be accessible after deleting an entry from the server");
1246			}
1247			catch(AssertionException ae) {
1248				throw ae;
1249			}
1250			catch(Exception e) {
1251				// supress exception
1252			}
1253		}
1254
1255		[Test]
1256		public void DirectoryEntry_Properties2()
1257		{
1258			// delete entry, create a new one (the same) and access properties of the old object
1259			string barakTsabariDN = configuration.ServerRoot + "cn=Barak Tsabari,ou=Human Resources,ou=people" + ((configuration.BaseDn.Length == 0) ? String.Empty : ("," + configuration.BaseDn));
1260			de = new DirectoryEntry(barakTsabariDN,
1261									configuration.Username,
1262									configuration.Password,
1263									configuration.AuthenticationType);
1264
1265			// cause to properties loading
1266			Assert.AreEqual(de.Properties.Count,6);
1267			Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
1268
1269			// delete entry
1270			de.DeleteTree();
1271
1272			// the local property chache is still accessible
1273			Assert.AreEqual(de.Properties.Count,6);
1274			Assert.AreEqual(((PropertyValueCollection)de.Properties["sn"]).Value,"Tsabari");
1275
1276			de.CommitChanges();
1277
1278			// the local property chache is still accessible
1279			((PropertyValueCollection)de.Properties["sn"]).Value = "Barbari";
1280
1281			// create the entry back again
1282			using (DirectoryEntry ouHumanResources = new DirectoryEntry(	configuration.ServerRoot + "ou=Human Resources,ou=…

Large files files are truncated, but you can click here to view the full file