Created
December 13, 2016 15:26
-
-
Save drewchapin/8cdd93bbf45faa54c90cbc6cf57bbc07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using System.DirectoryServices; | |
using System.DirectoryServices.ActiveDirectory; | |
namespace ActiveDirectoryExTest | |
{ | |
[TestClass] | |
public class DomainControllerTest | |
{ | |
[TestMethod] | |
public void TestMethod1() | |
{ | |
DirectoryContext context = new DirectoryContext(DirectoryContextType.DirectoryServer,"BERPGWLOCALDC11"); | |
using( DomainController domainController = DomainController.GetDomainController(context) ) | |
using( DirectorySearcher searcher = domainController.GetDirectorySearcher() ) | |
{ | |
searcher.Filter = "(&(sAMAccountName=glsp168))"; | |
SearchResult result = searcher.FindOne(); | |
if( result != null ) | |
{ | |
Assert.AreEqual("Chapin, Drew",(string)result.Properties["displayName"][0]); | |
Assert.AreEqual("LDAP://berPGWlocalDC11.pgw.local/CN=Chapin\\, Drew,OU=Users,OU=BER,DC=pgw,DC=local",result.Path); | |
} | |
else | |
throw new ActiveDirectoryObjectNotFoundException("Account for glsp168 not found."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment