Exemple #1
0
        public void CreateIndexer()
        {
            TestUtils.InitializeDefaultExtensionPoints();

            _indexerPath = Path.GetTempPath() + "luceneindexer";
            Directory.CreateDirectory(_indexerPath);
            _solutionKey = new SolutionKey(Guid.NewGuid(), "C:/SolutionPath");
            ServiceLocator.RegisterInstance(_solutionKey);
            ServiceLocator.RegisterInstance <Analyzer>(new SimpleAnalyzer());
            _indexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
            ServiceLocator.RegisterInstance(_indexer);

            ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement(
                accessLevel: AccessLevel.Public,
                definitionLineNumber: 11,
                extendedClasses: "SimpleClassBase",
                fullFilePath: "C:/Projects/SimpleClass.cs",
                implementedInterfaces: "IDisposable",
                name: "SimpleName",
                namespaceName: "Sanod.Indexer.UnitTests"
                );
            SandoDocument sandoDocument = DocumentFactory.Create(classElement);

            _indexer.AddDocument(sandoDocument);
            MethodElement methodElement = SampleProgramElementFactory.GetSampleMethodElement(
                accessLevel: AccessLevel.Protected,
                name: "SimpleName",
                returnType: "Void",
                fullFilePath: "C:/stuff"
                );

            sandoDocument = DocumentFactory.Create(methodElement);
            _indexer.AddDocument(sandoDocument);
        }
        public void CustomDocumentToLuceneDocument()
        {
            //test AddDocumentFields
            var customSandoDocument            = new SandoDocument(MyCustomProgramElementForTesting.GetProgramElement());
            var luceneDocumentWithCustomFields = customSandoDocument.GetDocument();

            Assert.IsTrue(luceneDocumentWithCustomFields != null);
        }
 public void DocumentFactory_CreateThrowsContractExceptionIfUnsportedProgramElementSubclassObjectPassed()
 {
     try
     {
         SandoDocument sandoDocument = DocumentFactory.Create(new TestElement("name", 12, -1000, "full path", "snippet"));
     }
     catch
     {
         //contract exception catched here
     }
     Assert.True(contractFailed, "Contract should fail!");
 }
 public void DocumentFactory_CreateThrowsContractExceptionIfProgramElementIsNull()
 {
     try
     {
         SandoDocument sandoDocument = DocumentFactory.Create(null);
     }
     catch
     {
         //contract exception catched here
     }
     Assert.True(contractFailed, "Contract should fail!");
 }
 public void DocumentFactory_CreateReturnsMethodDocumentForValidMethodElement()
 {
     try
     {
         ProgramElement programElement = SampleProgramElementFactory.GetSampleMethodElement();
         SandoDocument  sandoDocument  = DocumentFactory.Create(programElement);
         Assert.True(sandoDocument != null, "Null returned from DocumentFactory!");
         Assert.True(sandoDocument is MethodDocument, "MethodDocument must be returned for MethodElement object!");
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemple #6
0
 public void DocumentIndexer_AddDocumentDoesNotThrowWhenValidData()
 {
     try
     {
         _documentIndexer = new DocumentIndexer();
         ClassElement  classElement  = SampleProgramElementFactory.GetSampleClassElement();
         SandoDocument sandoDocument = DocumentFactory.Create(classElement);
         Assert.NotNull(sandoDocument);
         Assert.NotNull(sandoDocument.GetDocument());
         _documentIndexer.AddDocument(sandoDocument);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemple #7
0
        public virtual void AddDocument(SandoDocument sandoDocument)
        {
            Contract.Requires(sandoDocument != null, "DocumentIndexer:AddDocument - sandoDocument cannot be null!");

            Document tempDoc = sandoDocument.GetDocument();

            IndexWriter.AddDocument(tempDoc);
            lock (_lock)
            {
                if (_synchronousCommits)
                {
                    CommitChanges();
                }
                else
                if (!_hasIndexChanged)     //if _hasIndexChanged is false, then turn it into true
                {
                    _hasIndexChanged = true;
                }
            }
        }
 private ConverterFromHitToProgramElement(SandoDocument sandoDocument, Lucene.Net.Documents.Document document)
 {
     this.sandoDocument = sandoDocument;
     this.luceneDocument = document;
 }
 private ConverterFromHitToProgramElement(SandoDocument sandoDocument, Lucene.Net.Documents.Document document)
 {
     this.sandoDocument  = sandoDocument;
     this.luceneDocument = document;
 }
 internal static ConverterFromProgramElementToDocument Create(ProgramElement programElement, SandoDocument sandoDocument)
 {
     return(new ConverterFromProgramElementToDocument(programElement, sandoDocument));
 }
 private ConverterFromProgramElementToDocument(ProgramElement programElement, SandoDocument sandoDocument)
 {
     this.programElement = programElement;
     this.sandoDocument  = sandoDocument;
 }
 internal static ConverterFromProgramElementToDocument Create(ProgramElement programElement, SandoDocument sandoDocument)
 {
     return new ConverterFromProgramElementToDocument(programElement,sandoDocument);
 }
 private ConverterFromProgramElementToDocument(ProgramElement programElement, SandoDocument sandoDocument)
 {
     this.programElement = programElement;
     this.sandoDocument = sandoDocument;
 }