public async Task CanSearch(string filter, string dn) { using (var client = new LdapClient(Hostname)) { var result = await client.SearchAsync("dc=example,dc=com", SearchScope.SingleLevel, filter, CancellationToken.None); var entry = Assert.Single(result.Entries); Assert.Equal(dn, entry.ObjectName.ToString()); Assert.Empty(result.References); result = await client.SearchAsync("dc=example,dc=com", SearchScope.BaseObject, filter, CancellationToken.None); Assert.Empty(result.Entries); Assert.Empty(result.References); } }
public async Task CanReadEntry() { using (var client = new LdapClient(Hostname)) { var result = await client.SearchAsync("uid=tesla,dc=example,dc=com", SearchScope.BaseObject, null, CancellationToken.None); var entry = Assert.Single(result.Entries); Assert.Equal("uid=tesla,dc=example,dc=com", entry.ObjectName.ToString()); Assert.Empty(result.References); } }
public async Task CanSearchWithAttributes(string filter, string dn, string attributeName, string attribute, string expectedAttributeName = null) { using (var client = new LdapClient(Hostname)) { var result = await client.SearchAsync("dc=example,dc=com", SearchScope.SingleLevel, filter, new [] { attributeName }, CancellationToken.None); var entry = Assert.Single(result.Entries); Assert.Equal(dn, entry.ObjectName.ToString()); Assert.Empty(result.References); if (!String.IsNullOrEmpty(attribute)) { var attr = Assert.Single(entry.Attributes); Assert.Equal(expectedAttributeName ?? attributeName, attr.Type.ToString()); var attrValue = Assert.Single(attr.Values); Assert.Equal(attribute, Encoding.UTF8.GetString(attrValue.Span)); } else { Assert.Empty(entry.Attributes); } } }