public void SemVerLevel2IsCorrectTest(Document doc, bool expectedToBeSemVer2)
 {
     Assert.Equal(LatestListedHandler.IsSemVer2(doc), expectedToBeSemVer2);
 }
 public void ListedIsCorrectTest(Document doc, bool expectedToBeListed)
 {
     Assert.Equal(LatestListedHandler.GetListed(doc), expectedToBeListed);
 }
        public void DocumentsAreFilteredTest(
            bool includeUnlisted,
            bool includePrerelease,
            bool includeSemVer2,
            string readerName,
            string id,
            Document[] documents,
            NuGetVersion[] versions,
            int numSubReadersToFake,
            int expectedNumDocsInResult)
        {
            // Arrange
            var handler    = new LatestListedHandler(includeUnlisted, includePrerelease, includeSemVer2);
            var fakeReader = MockObjectFactory.CreateMockIndexReader(5, numberOfSubReaders: numSubReadersToFake).Object;

            // Act
            handler.Begin(fakeReader);
            // Pick a random subreader for each document
            var docNumber = 0;
            var rnd       = new Random(10000);

            for (var i = 0; i < documents.Length; i++)
            {
                handler.Process(indexReader: fakeReader,
                                readerName: Constants.SegmentReaderPrefix + rnd.Next(numSubReadersToFake),
                                perSegmentDocumentNumber: docNumber,
                                perIndexDocumentNumber: docNumber,
                                document: documents[i],
                                id: id + docNumber,
                                version: versions[i]);
                docNumber++;
            }

            handler.End(fakeReader);
            var resultFilter = handler.Result;

            // Assert
            var docsInResult = new HashSet <int>();
            var listReaders  = fakeReader.GetSequentialSubReaders();

            foreach (var reader in listReaders)
            {
                var bitSet         = resultFilter.GetDocIdSet(reader);
                var bitSetIterator = bitSet.Iterator();
                if (bitSetIterator != DocIdSet.EMPTY_DOCIDSET.Iterator() && bitSetIterator != null)
                {
                    if (bitSetIterator.DocID() == -1)
                    {
                        // we aren't on a doc yet, so call NextDoc to advance to the first doc
                        bitSetIterator.NextDoc();
                    }

                    while (bitSetIterator.DocID() != DocIdSetIterator.NO_MORE_DOCS)
                    {
                        docsInResult.Add(bitSetIterator.DocID());
                        bitSetIterator.NextDoc();
                    }
                }
            }

            Assert.Equal(expectedNumDocsInResult, docsInResult.Count);
        }