Skip to content

Instantly share code, notes, and snippets.

@drewchapin
Created December 13, 2016 15:26
Show Gist options
  • Save drewchapin/8cdd93bbf45faa54c90cbc6cf57bbc07 to your computer and use it in GitHub Desktop.
Save drewchapin/8cdd93bbf45faa54c90cbc6cf57bbc07 to your computer and use it in GitHub Desktop.
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