Example #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 static Document GetLuceneDocument()
        {
            ClassElement element  = SampleProgramElementFactory.GetSampleClassElement();
            Document     document = DocumentFactory.Create(element).GetDocument();

            document.Add(new Field("Bam", "Zaow", Field.Store.YES, Field.Index.ANALYZED));
            document.RemoveField(ProgramElement.CustomTypeTag);
            document.Add(new Field(ProgramElement.CustomTypeTag, typeof(MyCustomClassForTesting).AssemblyQualifiedName, Field.Store.YES, Field.Index.NO));
            return(document);
        }
 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);
     }
 }
        public void ProgramElementReader_ReadProgramElementFromDocumentReturnValidCommentElementForValidDocument()
        {
            CommentElement element  = SampleProgramElementFactory.GetSampleCommentElement();
            Document       document = DocumentFactory.Create(element).GetDocument();

            CommentElement returnedElement = ConverterFromHitToProgramElement.Create(document).Convert() as CommentElement;

            Assert.IsNotNull(returnedElement, "returned class element is null!");
            Assert.True("not stored in index" == returnedElement.Body, "AccessLevel is different!");
            Assert.True(element.DefinitionLineNumber == returnedElement.DefinitionLineNumber, "DefinitionLineNumber is different!");
            Assert.True(StandardizeFilePath(element.FullFilePath) == returnedElement.FullFilePath, "FullFilePath is different!");
            Assert.True(element.Name == returnedElement.Name, "Name is different!");
            Assert.True(element.ProgramElementType == returnedElement.ProgramElementType, "ProgramElementType is different!");
            Assert.True(element.RawSource == returnedElement.RawSource, "Snippet is different!");
        }
Example #5
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);
     }
 }
        public void ProgramElementReader_ReadProgramElementFromDocumentReturnValidClassElementForValidDocument()
        {
            ClassElement element  = SampleProgramElementFactory.GetSampleClassElement();
            Document     document = DocumentFactory.Create(element).GetDocument();

            ClassElement returnedElement = ConverterFromHitToProgramElement.Create(document).Convert() as ClassElement;

            Assert.IsNotNull(returnedElement, "returned class element is null!");
            Assert.True(element.AccessLevel == returnedElement.AccessLevel, "AccessLevel is different!");
            Assert.True(element.DefinitionLineNumber == returnedElement.DefinitionLineNumber, "DefinitionLineNumber is different!");
            Assert.True(element.ExtendedClasses == returnedElement.ExtendedClasses, "ExtendedClasses is different!");
            Assert.True(StandardizeFilePath(element.FullFilePath) == returnedElement.FullFilePath, "FullFilePath is different!");
            Assert.True(element.ImplementedInterfaces == returnedElement.ImplementedInterfaces, "ImplementedInterfaces is different!");
            Assert.True(element.Name == returnedElement.Name, "Name is different!");
            Assert.True(element.Namespace == returnedElement.Namespace, "Namespace is different!");
            Assert.True(element.ProgramElementType == returnedElement.ProgramElementType, "ProgramElementType is different!");
            Assert.True(element.RawSource == returnedElement.RawSource, "Snippet is different!");
        }
Example #7
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);
     }
 }
        public void ProgramElementReader_ReadProgramElementFromDocumentReturnValidMethodElementForValidDocument()
        {
            MethodElement element  = SampleProgramElementFactory.GetSampleMethodElement();
            Document      document = DocumentFactory.Create(element).GetDocument();

            MethodElement returnedElement = ConverterFromHitToProgramElement.Create(document).Convert() as MethodElement;

            Assert.IsNotNull(returnedElement, "returned class element is null!");
            Assert.True(element.AccessLevel == returnedElement.AccessLevel, "AccessLevel is different!");
            Assert.True(element.Arguments == returnedElement.Arguments, "Arguments is different!");
            Assert.True("not stored in index" == returnedElement.Body, "Body is different!");
            Assert.True(element.ClassId == returnedElement.ClassId, "ClassId is different!");
            Assert.True(element.ClassName == returnedElement.ClassName.ToSandoDisplayable(), "ClassName is different!");
            Assert.True(element.DefinitionLineNumber == returnedElement.DefinitionLineNumber, "DefinitionLineNumber is different!");
            Assert.True(StandardizeFilePath(element.FullFilePath) == returnedElement.FullFilePath, "FullFilePath is different!");
            Assert.True(element.Name == returnedElement.Name, "Name is different!");
            Assert.True(element.ProgramElementType == returnedElement.ProgramElementType, "ProgramElementType is different!");
            Assert.True(element.ReturnType == returnedElement.ReturnType, "ReturnType is different!");
            Assert.True(element.RawSource == returnedElement.RawSource, "Snippet is different!");
        }
Example #9
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);
     }
 }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomResultsReorderer()
        {
            CreateExtensionPointsConfiguration(addValidResultsReordererConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IResultsReorderer resultsReorderer = ExtensionPointsRepository.Instance.GetResultsReordererImplementation();

            Assert.IsNotNull(resultsReorderer, "Results reorderer should be registered!");
            Assert.AreEqual(resultsReorderer.GetType().FullName, "Sando.TestExtensionPoints.TestResultsReorderer", "Invalid results reorderer returned!");

            List <CodeSearchResult> results = new List <CodeSearchResult>()
            {
                new CodeSearchResult(SampleProgramElementFactory.GetSampleClassElement(), 1),
                new CodeSearchResult(SampleProgramElementFactory.GetSampleMethodElement(), 3),
            };

            Assert.DoesNotThrow(() => results = resultsReorderer.ReorderSearchResults(results.AsQueryable()).ToList());
            Assert.IsTrue(results != null && results.Count() == 2, "Invalid results from ReorderSearchResults method!");
            Assert.IsTrue(results.ElementAt(0).Score == 3 && results.ElementAt(0).ProgramElement.ProgramElementType == ProgramElementType.Method, "First result is invalid!");
            Assert.IsTrue(results.ElementAt(1).Score == 1 && results.ElementAt(1).ProgramElement.ProgramElementType == ProgramElementType.Class, "Second result is invalid!");
        }