예제 #1
0
        public async Task WhenExecuteSearchRequest(string dn, int messageId)
        {
            var payload = LdapPacketBuilder.NewSearchRequest(messageId, dn, SearchRequestScopes.WholeSubtree, SearchRequestDeferAliases.NeverDerefAliases, 10, 10, false, new List <string> {
            }, (opt) =>
            {
                opt.SetPresentFilter("objectClass");
            }).Serialize().ToArray();
            await _stream.WriteAsync(payload);

            bool isSearchResultDone = false;
            int  i = 0;

            while (!isSearchResultDone)
            {
                var data = new byte[5000];
                await _stream.ReadAsync(data, 0, data.Length);

                var ldapPacket     = LdapPacket.Extract(data.ToList());
                var ldapPacketJSON = JObject.FromObject(ldapPacket);
                if (ldapPacket.ProtocolOperation.Operation is SearchResultDone)
                {
                    isSearchResultDone = true;
                    _scenarioContext.Set(ldapPacketJSON, "searchResultDone");
                }
                else
                {
                    _scenarioContext.Set(ldapPacketJSON, $"searchResultEntry-{i}");
                }

                i++;
            }
        }
        public void When_Serialize_SearchRequest()
        {
            var payload = LdapPacketBuilder.NewSearchRequest(1, "cn=system", SearchRequestScopes.BaseObject, SearchRequestDeferAliases.NeverDerefAliases, 10, 10, false, new List <string> {
            }, (opt) =>
            {
                opt.SetEqualFilter("name", "value");
            }).Serialize().ToList();
            var ldapPacket    = LdapPacket.Extract(payload);
            var searchRequest = ldapPacket.ProtocolOperation.Operation as SearchRequest;

            Assert.NotNull(searchRequest);
        }