Esempio n. 1
0
        public void SearchIntoMultipleFieldsTest()
        {
            IPagesStorageProviderV40 pagesStorageProvider = mocks.DynamicMock <IPagesStorageProviderV40>();

            Expect.Call(pagesStorageProvider.CurrentWiki).Return("wiki1").Repeat.Any();

            mocks.ReplayAll();

            Collectors.InitCollectors();
            Collectors.AddProvider(typeof(DummyIndexDirectoryProvider), System.Reflection.Assembly.GetAssembly(typeof(DummyIndexDirectoryProvider)), "", typeof(IIndexDirectoryProviderV40));
            Host.Instance = new Host();

            ProviderLoader.SetUp <IIndexDirectoryProviderV40>(typeof(DummyIndexDirectoryProvider), "");

            string      pageTitle1   = "This is the title";
            string      pageContent1 = "This is the content of the page";
            PageContent page1        = new PageContent("pagefullname1", pagesStorageProvider, DateTime.Now, pageTitle1,
                                                       "user-test", DateTime.Now, "comment to last editing", pageContent1, null, "Description of the page");
            string      pageTitle2   = "This is the title of the second page";
            string      pageContent2 = "This is the content of the second page";
            PageContent page2        = new PageContent("pagefullname2", pagesStorageProvider, DateTime.Now, pageTitle2,
                                                       "user-test", DateTime.Now, "comment to last editing", pageContent2, null, "Description of the page");

            Lucene.Net.Store.Directory directory = new RAMDirectory();
            Assert.IsTrue(SearchClass.IndexPage(page1));
            Assert.IsTrue(SearchClass.IndexPage(page2));

            List <SearchResult> results = SearchClass.Search("wiki1", new SearchField[] { SearchField.Title, SearchField.Content }, "page", SearchOptions.AtLeastOneWord);

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

            Assert.AreEqual(DocumentType.Page, results[1].DocumentType, "Wrong document type");
            PageDocument doc1 = results[1].Document as PageDocument;

            Assert.AreEqual(string.Empty, doc1.HighlightedTitle, "Wrong title");
            Assert.AreEqual("This is the content of the <b class=\"searchkeyword\">page</b>", doc1.HighlightedContent, "Wrong content");

            Assert.AreEqual(DocumentType.Page, results[0].DocumentType, "Wrong document type");
            PageDocument doc2 = results[0].Document as PageDocument;

            Assert.AreEqual("This is the title of the second <b class=\"searchkeyword\">page</b>", doc2.HighlightedTitle, "Wrong title");
            Assert.AreEqual("This is the content of the second <b class=\"searchkeyword\">page</b>", doc2.HighlightedContent, "Wrong content");
        }
Esempio n. 2
0
        public void RenameFileTest()
        {
            Collectors.InitCollectors();
            Collectors.AddProvider(typeof(FSIndexDirectoryProvider), System.Reflection.Assembly.GetAssembly(typeof(FSIndexDirectoryProvider)), "", typeof(IIndexDirectoryProviderV40));
            Host.Instance = new Host();
            Host.Instance.OverridePublicDirectory(testDir);

            ProviderLoader.SetUp <IIndexDirectoryProviderV40>(typeof(FSIndexDirectoryProvider), "");

            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");

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

            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 = 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");
        }
        public void UnindexMessageTest()
        {
            IPagesStorageProviderV60 pagesStorageProvider = mocks.DynamicMock <IPagesStorageProviderV60>();

            Expect.Call(pagesStorageProvider.CurrentWiki).Return("wiki1").Repeat.Any();

            mocks.ReplayAll();

            Collectors.InitCollectors();
            Collectors.AddProvider(typeof(FSIndexDirectoryProvider), System.Reflection.Assembly.GetAssembly(typeof(FSIndexDirectoryProvider)), "", typeof(IIndexDirectoryProviderV60));
            Host.Instance = new Host();
            Host.Instance.OverridePublicDirectory(testDir);

            ProviderLoader.SetUp <IIndexDirectoryProviderV60>(typeof(FSIndexDirectoryProvider), "");

            string messageSubject = "This is the subject of the message";
            string messageBody    = "This is the body of the message";

            DateTime    dt      = DateTime.Now;
            PageContent page    = new PageContent("pagefullname", pagesStorageProvider, dt, "title", "user-test", dt, "", "content", new string[0], "");
            Message     message = new Message(1, "user-test", messageSubject, dt, messageBody);

            Assert.IsTrue(SearchClass.IndexMessage(message, page));

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

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

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

            MessageDocument documentMessage = results[0].Document as MessageDocument;

            Assert.AreEqual("This is the subject of the message", documentMessage.Subject, "Wrong title");
            Assert.AreEqual("This is the body of the <b class=\"searchkeyword\">message</b>", documentMessage.HighlightedBody, "Wrong content");

            Assert.IsTrue(SearchClass.UnindexMessage(1, page));

            results = SearchClass.Search("wiki1", new SearchField[] { SearchField.Content }, "message", SearchOptions.AtLeastOneWord);

            Assert.AreEqual(0, results.Count, "Wrong result length");
        }
        public void AddPageAttachmentTest()
        {
            IPagesStorageProviderV60 pagesStorageProvider = mocks.DynamicMock <IPagesStorageProviderV60>();

            Expect.Call(pagesStorageProvider.CurrentWiki).Return("wiki1").Repeat.Any();

            mocks.ReplayAll();

            Collectors.InitCollectors();
            Collectors.AddProvider(typeof(FSIndexDirectoryProvider), System.Reflection.Assembly.GetAssembly(typeof(FSIndexDirectoryProvider)), "", typeof(IIndexDirectoryProviderV60));
            Host.Instance = new Host();
            Host.Instance.OverridePublicDirectory(testDir);

            ProviderLoader.SetUp <IIndexDirectoryProviderV60>(typeof(FSIndexDirectoryProvider), "");

            DateTime    dt       = DateTime.Now;
            PageContent page     = new PageContent("pagefullname", pagesStorageProvider, dt, "title", "user-test", dt, "", "content", new string[0], "");
            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.IndexPageAttachment(fileName, filePath, page));

            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.Attachment, results[0].DocumentType, "Wrong document type");

            PageAttachmentDocument pageAttachmentDocument = results[0].Document as PageAttachmentDocument;

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