private T QueryOne <T>(string searchBase, Dictionary <string, string> conditions) where T : class, ILdapEntry { var filter = LdapHelps.BuildFilter(conditions); using (var ldapConnection = GetConnection()) { var search = ldapConnection.Search(searchBase, LdapConnection.SCOPE_SUB, filter, _attributes, false, null, null); LdapMessage message; while ((message = search.getResponse()) != null) { if (!(message is LdapSearchResult searchResultMessage)) { continue; } var entry = searchResultMessage.Entry; if (typeof(T) == typeof(LdapOrganization)) { return(new LdapOrganization(entry.getAttributeSet()) as T); } if (typeof(T) == typeof(LdapUser)) { return(new LdapUser(entry.getAttributeSet()) as T); } return(null); } } return(null); }
public void BuildCondition_With_Value() { // act var res = LdapHelps.BuildCondition("objectClass", "testNameA"); // assert res.ShouldBe("(objectClass=testNameA)"); }
public void BuildFilter_With_Empty_Condition() { // act var res = LdapHelps.BuildFilter(new Dictionary <string, string>()); // assert res.ShouldBe("(&(objectClass=*))"); }
public void BuildFilter_With_Null_Condition() { // act var res = LdapHelps.BuildFilter(null); // assert res.ShouldBe("(&(objectClass=*))"); }
public void BuildCondition_With_WhiteSpace_Value() { // act var res = LdapHelps.BuildCondition("objectClass", " "); // assert res.ShouldBeEmpty(); }
public void BuildCondition_With_Null_Value() { // act var res = LdapHelps.BuildCondition("objectClass", null); // assert res.ShouldBeEmpty(); }
public void BuildFilter_With_Condition() { // act var conditions = new Dictionary <string, string> { { "objectClass", "testClassA" }, { "objectCategory", "testCategoryA" }, { "name", null } }; var res = LdapHelps.BuildFilter(conditions); // assert res.ShouldBe("(&(objectClass=testClassA)(objectCategory=testCategoryA))"); }