Ejemplo n.º 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);
        }
Ejemplo n.º 2
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();
            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);
            Thread.Sleep(2000);
        }
Ejemplo n.º 3
0
        public void Update(string filePath, XElement xElement)
        {
            var fileInfo = new FileInfo(filePath);

            try
            {
                var parsed = ExtensionPointsRepository.Instance.GetParserImplementation(fileInfo.Extension).Parse(filePath, xElement);

                var unresolvedElements = parsed.FindAll(pe => pe is CppUnresolvedMethodElement);
                if (unresolvedElements.Count > 0)
                {
                    //first generate program elements for all the included headers
                    var headerElements = CppHeaderElementResolver.GenerateCppHeaderElements(filePath, unresolvedElements);

                    //then try to resolve
                    foreach (CppUnresolvedMethodElement unresolvedElement in unresolvedElements)
                    {
                        var document = CppHeaderElementResolver.GetDocumentForUnresolvedCppMethod(unresolvedElement, headerElements);
                        if (document != null)
                        {
                            //writeLog( "- DI.AddDocument()");
                            _currentIndexer.AddDocument(document);
                        }
                    }
                }

                foreach (var programElement in parsed)
                {
                    if (!(programElement is CppUnresolvedMethodElement))
                    {
                        var document = DocumentFactory.Create(programElement);
                        if (document != null)
                        {
                            //writeLog( "- DI.AddDocument()");
                            _currentIndexer.AddDocument(document);
                        }
                    }
                }
                if (indexUpdated != null)
                {
                    indexUpdated(parsed.AsReadOnly());
                }
            }
            catch (Exception e)
            {
                LogEvents.UIIndexUpdateError(this, e);
            }
        }
Ejemplo n.º 4
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();
            ServiceLocator.RegisterInstance(_indexer);
            ServiceLocator.RegisterInstance<ISandoOptionsProvider>(new FakeOptionsProvider(String.Empty, 20, false, new List<string>()));

            // xige
            var dictionary = new DictionaryBasedSplitter();
            dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
            ServiceLocator.RegisterInstance(dictionary);

            var reformer = new QueryReformerManager(dictionary);
            reformer.Initialize(null);
            ServiceLocator.RegisterInstance(reformer);

            var history = new SearchHistory();
            history.Initialize(PathManager.Instance.GetIndexPath
                (ServiceLocator.Resolve<SolutionKey>()));
            ServiceLocator.RegisterInstance(history);

            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);
            Thread.Sleep(2000);
        }
Ejemplo n.º 5
0
 public void DocumentIndexer_AddDocumentThrowsWhenProgramElementIsNull()
 {
     _documentIndexer = new DocumentIndexer();
     try
     {
         _documentIndexer.AddDocument(null);
     }
     catch
     {
         //contract exception catched here
     }
     Assert.True(_contractFailed, "Contract should fail!");
 }
Ejemplo n.º 6
0
        private void IndexFilesInDirectory(string solutionPath)
        {
            var files = Directory.GetFiles(solutionPath);

            foreach (var file in files)
            {
                string fullPath = Path.GetFullPath(file);
                var    srcMl    = _parser.Parse(fullPath);
                foreach (var programElement in srcMl)
                {
                    _indexer.AddDocument(DocumentFactory.Create(programElement));
                }
            }
        }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
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);
     }
 }
Ejemplo n.º 9
0
 public void DocumentIndexer_DeleteDocuments()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));
         _documentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
         MethodElement sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         int numDocs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(numDocs == 1);
         _documentIndexer.DeleteDocuments(sampleMethodElement.FullFilePath);
         int docs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(docs == 0);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Ejemplo n.º 10
0
 public void GIVEN_DocumentIndexer_WHEN_IndexSearcherIsClosed_AND_SearchFailed_THEN_IndexSearcherIsRecreated_AND_SearchReturnsResults()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));
         _documentIndexer = new DocumentIndexer(TimeSpan.FromMilliseconds(500));
         var sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         const string searchQueryString = "body: sth";
         var          query             = _documentIndexer.QueryParser.Parse(searchQueryString);
         int          hitsPerPage       = SearchCriteria.DefaultNumberOfSearchResultsReturned;
         var          collector         = TopScoreDocCollector.create(hitsPerPage, true);
         _documentIndexer.NUnit_CloseIndexSearcher();
         _documentIndexer.Search(query, collector);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Ejemplo n.º 11
0
 public void DocumentIndexer_DeleteDocuments()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
         _documentIndexer = new DocumentIndexer();
         MethodElement sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         Thread.Sleep(2000);
         int numDocs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(numDocs == 1);
         _documentIndexer.DeleteDocuments(sampleMethodElement.FullFilePath);
         Thread.Sleep(2000);
         int docs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(docs == 0);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Ejemplo n.º 12
0
 public void GIVEN_DocumentIndexer_WHEN_IndexSearcherIsClosed_THEN_IndexSearcherIsRecreatedInBackgroundThread_AND_SearchReturnsResults()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
         _documentIndexer = new DocumentIndexer();
         var sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         const string searchQueryString = "body: sth";
         var query = _documentIndexer.QueryParser.Parse(searchQueryString);
         int hitsPerPage = SearchCriteria.DefaultNumberOfSearchResultsReturned;
         var collector = TopScoreDocCollector.create(hitsPerPage, true);
         _documentIndexer.NUnit_CloseIndexSearcher();
         Thread.Sleep(600);
         _documentIndexer.Search(query, collector);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }