public void AddFileTest()
        {
            Collectors.InitCollectors();
            Collectors.AddProvider(typeof(AzureIndexDirectoryProvider), System.Reflection.Assembly.GetAssembly(typeof(AzureIndexDirectoryProvider)), ConfigurationManager.AppSettings["AzureConnString"], typeof(IIndexDirectoryProviderV40));
            Host.Instance = new Host();
            Host.Instance.OverridePublicDirectory(testDir);

            ProviderLoader.SetUp <IIndexDirectoryProviderV40>(typeof(AzureIndexDirectoryProvider), ConfigurationManager.AppSettings["AzureConnString"]);

            string fileName = "file_name_1";

            string filePath = Path.Combine(testDir, "test.txt");

            using (StreamWriter writer = File.CreateText(filePath)) {
                writer.Write("This is the content of a file");
            }

            Assert.IsTrue(SearchClass.IndexFile(fileName, filePath, "wiki1"));

            List <SearchResult> results = SearchClass.Search("wiki1", new SearchField[] { SearchField.FileName, SearchField.FileContent }, "file", SearchOptions.AtLeastOneWord);

            Assert.AreEqual(1, results.Count, "Wrong result length");

            Assert.AreEqual(DocumentType.File, results[0].DocumentType, "Wrong document type");

            FileDocument fileDocument = results[0].Document as FileDocument;

            Assert.AreEqual(fileName, fileDocument.FileName, "Wrong file name");
            Assert.AreEqual("This is the content of a <b class=\"searchkeyword\">file</b>", fileDocument.HighlightedFileContent, "Wrong file content");
        }
Ejemplo n.º 2
0
        public void RenameFileTest()
        {
            Host.Instance = new Host();

            Collectors.IndexDirectoryProvider = new DummyIndexDirectoryProvider();
            ProviderLoader.SetUp <IIndexDirectoryProviderV30>(typeof(DummyIndexDirectoryProvider), "");

            string fileName = "file name_1";

            string filePath = Path.Combine(testDir, "test.txt");

            using (StreamWriter writer = File.CreateText(filePath))
            {
                writer.Write("This is the content of a file");
            }

            Assert.IsTrue(SearchClass.IndexFile(fileName, filePath));

            List <SearchResult> results = SearchClass.Search(new SearchField[] { SearchField.FileName, SearchField.FileContent }, "file", SearchOptions.AtLeastOneWord);

            Assert.AreEqual(1, results.Count, "Wrong result length");

            Assert.AreEqual(DocumentType.File, results[0].DocumentType, "Wrong document type");

            FileDocument fileDocument = results[0].Document as FileDocument;

            Assert.AreEqual(fileName, fileDocument.FileName, "Wrong file name");
            Assert.AreEqual("This is the content of a <b class=\"searchkeyword\">file</b>", fileDocument.HighlightedFileContent, "Wrong file content");

            Assert.IsTrue(SearchClass.RenameFile(fileName, "file name_2"));

            results = SearchClass.Search(new SearchField[] { SearchField.FileName, SearchField.FileContent }, "file", SearchOptions.AtLeastOneWord);

            Assert.AreEqual(1, results.Count, "Wrong result length");

            Assert.AreEqual(DocumentType.File, results[0].DocumentType, "Wrong document type");

            fileDocument = results[0].Document as FileDocument;

            Assert.AreEqual("file name_2", fileDocument.FileName, "Wrong file name");
            Assert.AreEqual("This is the content of a <b class=\"searchkeyword\">file</b>", fileDocument.HighlightedFileContent, "Wrong file content");
        }