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_CreateReturnsClassDocumentForValidClassElement() { try { ProgramElement programElement = SampleProgramElementFactory.GetSampleClassElement(); SandoDocument sandoDocument = DocumentFactory.Create(programElement); Assert.True(sandoDocument != null, "Null returned from DocumentFactory!"); Assert.True(sandoDocument is ClassDocument, "ClassDocument must be returned for ClassElement object!"); } catch (Exception ex) { Assert.Fail(ex.Message + ". " + ex.StackTrace); } }
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!"); }
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!"); }