public void AddPageTest()
        {
            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 pageTitle   = "This is the title of the page";
            string pageContent = "This is the content of the page";

            PageContent page = new PageContent("pagefullname", pagesStorageProvider, DateTime.Now, pageTitle,
                                               "user-test", DateTime.Now, "comment to last editing", pageContent, null, "Description of the page");


            Assert.IsTrue(SearchClass.IndexPage(page));

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

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

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

            PageDocument documentPage = results[0].Document as PageDocument;

            Assert.AreEqual("This is the title of the <b class=\"searchkeyword\">page</b>", documentPage.HighlightedTitle, "Wrong title");
            Assert.AreEqual("This is the content of the <b class=\"searchkeyword\">page</b>", documentPage.HighlightedContent, "Wrong content");
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new Snippet.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="name">The name of the Snippet.</param>
        /// <param name="content">The content of the Snippet.</param>
        /// <param name="provider">The Provider to use to store the Snippet (<c>null</c> for the default provider).</param>
        /// <returns>True if the Snippets has been addedd successfully.</returns>
        public static bool AddSnippet(string wiki, string name, string content, IPagesStorageProviderV60 provider)
        {
            if (Find(wiki, name) != null)
            {
                return(false);
            }

            if (provider == null)
            {
                provider = Collectors.CollectorsBox.PagesProviderCollector.GetProvider(GlobalSettings.DefaultPagesProvider, wiki);
            }

            Snippet newSnippet = provider.AddSnippet(name, content);

            if (newSnippet != null)
            {
                Log.LogEntry("Snippet " + name + " created", EntryType.General, Log.SystemUsername, wiki);
            }
            else
            {
                Log.LogEntry("Creation failed for Snippet " + name, EntryType.Error, Log.SystemUsername, wiki);
            }

            return(newSnippet != null);
        }
        public void AddMessageTest()
        {
            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");
        }
        public void UnindexPageTest()
        {
            IPagesStorageProviderV60 pagesStorageProvider = mocks.DynamicMock <IPagesStorageProviderV60>();

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

            mocks.ReplayAll();

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

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

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

            Assert.IsTrue(SearchClass.UnindexPage(page1));

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

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

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

            Assert.AreEqual("This is the title of the second <b class=\"searchkeyword\">page</b>", doc3.HighlightedTitle, "Wrong title");
            Assert.AreEqual("This is the content of the second <b class=\"searchkeyword\">page</b>", doc3.HighlightedContent, "Wrong content");
        }
        public void Init()
        {
            IPagesStorageProviderV60 prov = GetProvider();

            prov.Init(MockHost(), connString, null);

            Assert.IsNotNull(prov.Information, "Information should not be null");

            prov.Dispose();
        }
        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");
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PageContent"/> class.
 /// </summary>
 /// <param name="pageFullName">The PageInfo object.</param>
 /// <param name="provider">The Pages Storage Provider that manages this Page.</param>
 /// <param name="creationDateTime">The Page creation Date/Time.</param>
 /// <param name="title">The Title.</param>
 /// <param name="user">The User that last modified the Page.</param>
 /// <param name="lastModified">The last modification Date and Time.</param>
 /// <param name="comment">The Comment of the editor, about this revision.</param>
 /// <param name="content">The <b>unparsed</b> Content.</param>
 /// <param name="keywords">The keywords, usually used for SEO, or <c>null</c>.</param>
 /// <param name="description">The description, usually used for SEO, or <c>null</c>.</param>
 public PageContent(string pageFullName, IPagesStorageProviderV60 provider, DateTime creationDateTime, string title, string user, DateTime lastModified, string comment, string content,
                    string[] keywords, string description)
 {
     this.nspace           = NameTools.GetNamespace(pageFullName);
     this.name             = NameTools.GetLocalName(pageFullName);
     this.provider         = provider;
     this.creationDateTime = creationDateTime;
     this.title            = title;
     this.user             = user;
     this.lastModified     = lastModified;
     this.content          = content;
     this.comment          = comment;
     this.keywords         = keywords != null ? keywords : new string[0];
     this.description      = description;
 }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:NamespaceInfo" /> class.
 /// </summary>
 /// <param name="name">The namespace name.</param>
 /// <param name="provider">The provider.</param>
 /// <param name="defaultPageFullName">The full name of the default page, or <c>null</c>.</param>
 public NamespaceInfo(string name, IPagesStorageProviderV60 provider, string defaultPageFullName)
 {
     this.name                = name;
     this.provider            = provider;
     this.defaultPageFullName = defaultPageFullName;
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:CategoryInfo" /> class.
 /// </summary>
 /// <param name="fullName">The Full Name of the Category.</param>
 /// <param name="provider">The Storage that manages the category.</param>
 public CategoryInfo(string fullName, IPagesStorageProviderV60 provider)
 {
     NameTools.ExpandFullName(fullName, out nspace, out name);
     this.provider = provider;
 }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <b>Snippet</b> class.
 /// </summary>
 /// <param name="name">The Name of the Snippet.</param>
 /// <param name="content">The Content of the Snippet.</param>
 /// <param name="provider">The Provider of the Snippet.</param>
 public Snippet(string name, string content, IPagesStorageProviderV60 provider)
 {
     this.name     = name;
     this.content  = content;
     this.provider = provider;
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <b>NavigationPath</b> class.
 /// </summary>
 /// <param name="fullName">The Full Name of the Navigation Path.</param>
 /// <param name="provider">The Provider</param>
 public NavigationPath(string fullName, IPagesStorageProviderV60 provider)
 {
     NameTools.ExpandFullName(fullName, out nspace, out name);
     this.provider = provider;
     pages         = new string[0];
 }
Beispiel #12
0
        /// <summary>
        /// Adds a new Navigation Path.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="nspace">The target namespace (<c>null</c> for the root).</param>
        /// <param name="name">The Name.</param>
        /// <param name="pages">The full name of the pages.</param>
        /// <param name="provider">The Provider to use for the new Navigation Path, or <c>null</c> for the default provider.</param>
        /// <returns>True if the Path is added successfully.</returns>
        public static bool AddNavigationPath(string wiki, NamespaceInfo nspace, string name, List <string> pages, IPagesStorageProviderV60 provider)
        {
            string namespaceName = nspace != null ? nspace.Name : null;
            string fullName      = NameTools.GetFullName(namespaceName, name);

            if (Exists(wiki, fullName))
            {
                return(false);
            }

            if (provider == null)
            {
                provider = Collectors.CollectorsBox.PagesProviderCollector.GetProvider(GlobalSettings.DefaultPagesProvider, wiki);
            }

            NavigationPath newPath = provider.AddNavigationPath(namespaceName, name, pages.ToArray());

            if (newPath != null)
            {
                Log.LogEntry("Navigation Path " + fullName + " added", EntryType.General, Log.SystemUsername, wiki);
            }
            else
            {
                Log.LogEntry("Creation failed for Navigation Path " + fullName, EntryType.Error, Log.SystemUsername, wiki);
            }
            return(newPath != null);
        }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ContentTemplate" /> class.
 /// </summary>
 /// <param name="name">The name of the template.</param>
 /// <param name="content">The content of the template.</param>
 /// <param name="provider">The provider handling the template.</param>
 public ContentTemplate(string name, string content, IPagesStorageProviderV60 provider)
 {
     this.name     = name;
     this.content  = content;
     this.provider = provider;
 }
        public void Init()
        {
            IPagesStorageProviderV60 prov = GetProvider();

            Assert.IsNotNull(prov.Information, "Information should not be null");
        }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EmptyPageContent"/> class.
 /// </summary>
 /// <param name="pageFullName">The page the content refers to.</param>
 /// <param name="provider">The Pages Storage Provider that manages this Page.</param>
 /// <param name="creationDateTime">The Page creation Date/Time.</param>
 public EmptyPageContent(string pageFullName, IPagesStorageProviderV60 provider, DateTime creationDateTime)
     : base(pageFullName, provider, creationDateTime, "", "", DateTime.MinValue, "", "", null, "")
 {
 }
Beispiel #16
0
 /// <summary>
 /// Gets an empty instance of <see cref="T:PageContent" />.
 /// </summary>
 /// <param name="pageFullName">The page full name.</param>
 /// <param name="provider">The Pages Storage Provider that manages this Page.</param>
 /// <param name="creationDateTime">The Page creation Date/Time.</param>
 /// <returns>The instance.</returns>
 public static PageContent GetEmpty(string pageFullName, IPagesStorageProviderV60 provider, DateTime creationDateTime)
 {
     return(new EmptyPageContent(pageFullName, provider, creationDateTime));
 }