Пример #1
0
        public void AddPageAttachmentTest()
        {
            IPagesStorageProviderV30 pagesStorageProvider = mocks.DynamicMock <IPagesStorageProviderV30>();

            mocks.ReplayAll();

            Host.Instance = new Host();

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

            DateTime    dt       = DateTime.Now;
            PageContent page     = new PageContent(new PageInfo("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(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");
        }
        public void RenamePageAttachmentTest()
        {
            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");

            Assert.IsTrue(SearchClass.RenamePageAttachment(page, 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.Attachment, results[0].DocumentType, "Wrong document type");

            pageAttachmentDocument = results[0].Document as PageAttachmentDocument;

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