public void HandlePagedRequest_NullPagedRequest_CreatesPagedRequestFromOptions() { //prepare _options.Setup(o => o.Filter) .Returns("filter"); _options.Setup(o => o.PagingOptions) .Returns(new PagingOptions(1, null)); _options.Setup(o => o.GetEnumerator(It.IsAny <SearchResultEntryCollection>())) .Returns(new SearchResponseEnumerable <object>(new Mock <IResultTransformer>().Object, new List <SearchResultEntry>())); _options.Setup(o => o.GetEnumeratorReturnType()) .Returns(typeof(object)); var xmlNode = new XmlDocument(); object[] parameters; #if (!NET35 && !NET40 && !NET45) parameters = new object[] { "", new System.DirectoryServices.Protocols.DirectoryControl[0], System.DirectoryServices.Protocols.ResultCode.Success, "", new System.Uri[0] }; #else parameters = new object[] { xmlNode }; #endif var response = typeof(SearchResponse).Create <SearchResponse>(parameters); #if (NET35 || NET40 || NET45) response.SetFieldValue("result", ResultCode.Success); #endif var connection = new MockLdapConnection(new Dictionary <Type, DirectoryResponse> { { typeof(SearchRequest), response } }); var command = new MockStandardQueryCommand(_options.Object, _mapping.Object) .DisableStandardRequest(); command.ResponseControlsToSearch = new DirectoryControl[] { DirectoryControlFactory.CreatePageResponse(new byte[] { 1, 2 }, new byte[0]) }; //act var obj = command.HandlePagedRequest(connection, null, null); //assert command.GetRequest().Controls.OfType <PageResultRequestControl>().Should().Have.Count.EqualTo(1); obj.Should().Be.InstanceOf <LdapPage <object> >(); obj.As <LdapPage <object> >().PageSize.Should().Be.EqualTo(1); obj.As <LdapPage <object> >().NextPage.Should().Have.SameSequenceAs(new byte[] { 1, 2 }); obj.As <LdapPage <object> >().Filter.Should().Be.EqualTo("filter"); }
public void HandlePagedRequest_ExistingPagedRequest_IgnoresPagedRequestFromOptions() { //prepare _options.Setup(o => o.Filter) .Returns("filter"); _options.Setup(o => o.GetEnumerator(It.IsAny <SearchResultEntryCollection>())) .Returns(new SearchResponseEnumerable <object>(new Mock <IResultTransformer>().Object, new List <SearchResultEntry>())); _options.Setup(o => o.GetEnumeratorReturnType()) .Returns(typeof(object)); var xmlNode = new XmlDocument(); var response = typeof(SearchResponse).Create <SearchResponse>(xmlNode); response.SetFieldValue("result", ResultCode.Success); var connection = new MockLdapConnection(new Dictionary <Type, DirectoryResponse> { { typeof(SearchRequest), response } }); var command = new MockStandardQueryCommand(_options.Object, _mapping.Object) .DisableStandardRequest(); command.ResponseControlsToSearch = new DirectoryControl[] { DirectoryControlFactory.CreatePageResponse(new byte[] { 1, 2 }, new byte[0]) }; //act var obj = command.HandlePagedRequest(connection, new PageResultRequestControl(2), null); //assert command.GetRequest().Controls.OfType <PageResultRequestControl>() .Should().Have.Count.EqualTo(0); obj.Should().Be.InstanceOf <LdapPage <object> >(); obj.As <LdapPage <object> >().PageSize.Should().Be.EqualTo(2); obj.As <LdapPage <object> >().NextPage.Should().Have.SameSequenceAs(new byte[] { 1, 2 }); obj.As <LdapPage <object> >().Filter.Should().Be.EqualTo("filter"); }