The new LDAP component comes with a code to send LDAP queries. The sample code is below:

using System;
using StresStimulus.Extensibility;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.DirectoryServices;

class MyLDAPComponent : ActionComponent //Do not rename Class
{
	public MyLDAPComponent() {
		//Do not edit this section.
	}

#region Start/Stop Test

	/// <summary>
	/// Fired when test started.
	/// </summary>
	public override void OnTestStart() {

	}

	/// <summary>
	/// Fired when test ends.
	/// </summary>
	public override void OnTestEnd() {

	}

#endregion

	/////////////////////////////////////////////////////////////////////////////////////////////
	//
	//  1.  Enter you LDAP PAth
	//	2.  Enter LDAP search query
	//
	/////////////////////////////////////////////////////////////////////////////////////////////

	const string LDAP_PATH = ""; //Your LDAP Path
	const string LDAP_QUERY = ""; //Your LDAP search query

	static DirectoryEntry createDirectoryEntry() {
		// create and return new LDAP connection with desired settings  

		DirectoryEntry ldapConnection = new DirectoryEntry();
		ldapConnection.Path = LDAP_PATH;
		ldapConnection.AuthenticationType = AuthenticationTypes.Secure;

		return ldapConnection;
	}

	public void QueryLDAP(ActionArgs arg) {
		try {
			// create LDAP connection object  

			DirectoryEntry myLdapConnection = createDirectoryEntry();

			// create search object which operates on LDAP connection object  
			// and set search object to only find the user specified  

			DirectorySearcher search = new DirectorySearcher(myLdapConnection);
			search.Filter = LDAP_QUERY;

			// create results objects from search object  

			SearchResultCollection result = search.FindAll();
		}
		catch (Exception ex) {
			arg.IsError = true;
			arg.ErrorMessage = ex.Message;
		}
	}
}

Add the following to the code:

  1. The LDAP path
  2. The LDAP search query


  • No labels