public static void Attach(this IList<IAttributeDefinition> attributes, string attributeName, bool excludeFromNameSearch) { if(!string.IsNullOrEmpty(attributeName)) { var definition = attributes.FirstOrDefault(a => string.Equals(a.Name, attributeName, StringComparison.InvariantCultureIgnoreCase)); if(definition != null) { attributes.Remove(definition); } definition = new AttributeDefinition(attributeName, excludeFromNameSearch); attributes.Add(definition); } }
public void FindUsersByName_OneUserAttributeThatShallBeIncludedInSearchConfigured_SearcherHasUserFilterWithAttributeForSearch() { var searcher = A.Fake<IDirectorySearcher>(); A.CallTo(() => ldapConfig.Users.Filter).Returns("usersfilter"); A.CallTo(() => ldapConfig.Users.RdnAttribute).Returns("rdnattribute"); var attribute1 = new AttributeDefinition("includedInSearch", false); var attribute2 = new AttributeDefinition("excludedInSearch", true); var attributes = new List<IAttributeDefinition>(); attributes.Add(attribute1); attributes.Add(attribute2); A.CallTo(() => ldapConfig.Users.Attributes).Returns(attributes); A.CallTo(() => searcherFactory.CreateSearcher(A<IEntry>.Ignored, SearchScope.Subtree, ldapConfig.Users)).Returns(searcher); int totalRecords; adapter.FindUsersByName("username", 0, 1, out totalRecords); Assert.AreEqual("(&usersfilter(|(rdnattribute=username)(includedInSearch=username)))", searcher.Filter); }