Ejemplo n.º 1
0
		public void index_should_return_page()
		{
			// Arrange
			Page page1 = new Page()
			{
				Id = 50,
				Tags = "homepage, tag2",
				Title = "Welcome to the site"
			};
			PageContent page1Content = new PageContent()
			{
				Id = Guid.NewGuid(),
				Page = page1,
				Text = "Hello world"
			};
			_pageRepository.Pages.Add(page1);
			_pageRepository.PageContents.Add(page1Content);

			// Act
			ActionResult result = _wikiController.Index(50, "");

			// Assert
			Assert.That(result, Is.TypeOf<ViewResult>(), "ViewResult");

			PageViewModel model = result.ModelFromActionResult<PageViewModel>();
			Assert.NotNull(model, "Null model");
			Assert.That(model.Title, Is.EqualTo(page1.Title));
			Assert.That(model.Content, Is.EqualTo(page1Content.Text));
		}
Ejemplo n.º 2
0
        public void Internal_Links_Should_Resolve_With_Id()
        {
            // Bug #87

            // Arrange
            Page page = new Page() { Id = 1, Title = "My first page"};

            RepositoryMock repositoryStub = new RepositoryMock();
            repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow);
            repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" };

            ApplicationSettings settings = new ApplicationSettings();
            settings.Installed = true;
            settings.UpgradeRequired = false;

            UrlResolverMock resolver = new UrlResolverMock();
            resolver.InternalUrl = "blah";
            MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory);
            converter.UrlResolver = resolver;

            string markdownText = "[Link](My-first-page)";
            string invalidMarkdownText = "[Link](My first page)";

            // Act
            string expectedHtml = "<p><a href=\"blah\">Link</a></p>\n";
            string expectedInvalidLinkHtml = "<p>[Link](My first page)</p>\n";

            string actualHtml = converter.ToHtml(markdownText);
            string actualHtmlInvalidLink = converter.ToHtml(invalidMarkdownText);

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
            Assert.That(actualHtmlInvalidLink, Is.EqualTo(expectedInvalidLinkHtml));
        }
Ejemplo n.º 3
0
		public void SetUp()
		{
			// Setup the repository
			Repository = GetRepository();
			Clearup();

			// Create 5 Pages with 2 versions of content each
			_createdDate = DateTime.Today.ToUniversalTime().AddDays(-1);
			_editedDate = _createdDate.AddHours(1);

			_page1 = NewPage("admin", "homepage, newpage");
			_pageContent1 = Repository.AddNewPage(_page1, "text", "admin", _createdDate);
			_page1 = _pageContent1.Page;
			_pageContent2 = Repository.AddNewPageContentVersion(_page1, "v2", "admin", _editedDate, 2);
			_page1 = _pageContent2.Page; // update the modified date

			Page page2 = NewPage("editor1");
			PageContent pageContent2 = Repository.AddNewPage(page2, "text", "editor1", _createdDate);
			Repository.AddNewPageContentVersion(pageContent2.Page, "v2", "editor1", _editedDate, 1);

			Page page3 = NewPage("editor2");
			PageContent pageContent3 = Repository.AddNewPage(page3, "text", "editor2", _createdDate);
			Repository.AddNewPageContentVersion(pageContent3.Page, "v2", "editor2", _editedDate, 1);

			Page page4 = NewPage("editor3");
			PageContent pageContent4 = Repository.AddNewPage(page4, "text", "editor3", _createdDate);
			Repository.AddNewPageContentVersion(pageContent4.Page, "v2", "editor3", _editedDate, 1);

			Page page5 = NewPage("editor4");
			PageContent pageContent5 = Repository.AddNewPage(page5, "text", "editor4", _createdDate);
			Repository.AddNewPageContentVersion(pageContent5.Page, "v2", "editor4", _editedDate, 1);
		}
Ejemplo n.º 4
0
        public void Code_Blocks_Should_Allow_Quotes()
        {
            // Issue #82
            // Arrange
            Page page = new Page() { Id = 1, Title = "My first page" };

            RepositoryMock repositoryStub = new RepositoryMock();
            repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow);
            repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" };

            ApplicationSettings settings = new ApplicationSettings();
            settings.Installed = true;
            settings.UpgradeRequired = false;

            MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory);

            string markdownText = "Here is some `// code with a 'quote' in it and another \"quote\"`\n\n" +
                "    var x = \"some tabbed code\";\n\n"; // 2 line breaks followed by 4 spaces (tab stop) at the start indicates a code block

            string expectedHtml = "<p>Here is some <code>// code with a 'quote' in it and another \"quote\"</code></p>\n\n" +
                                "<pre><code>var x = \"some tabbed code\";\n" +
                                "</code></pre>\n";

            // Act
            string actualHtml = converter.ToHtml(markdownText);

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 5
0
        public void Images_Should_Support_Dimensions()
        {
            // Arrange
            Page page = new Page() { Id = 1, Title = "My first page" };

            RepositoryMock repositoryStub = new RepositoryMock();
            repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow);
            repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" };

            ApplicationSettings settings = new ApplicationSettings();
            settings.Installed = true;
            settings.UpgradeRequired = false;

            MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory);

            string markdownText = "Here is an image:![Image](/Image1.png) \n\n" +
                                  "And another with equal dimensions ![Square](/Image1.png =250x) \n\n" +
                                  "And this one is a rectangle ![Rectangle](/Image1.png =250x350)";

            string expectedHtml = "<p>Here is an image:<img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" /> </p>\n\n" +
                                    "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" /> </p>\n\n" +
                                    "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" /></p>\n";

            // Act
            string actualHtml = converter.ToHtml(markdownText);

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 6
0
		public void put_should_update_page()
		{
			// Arrange
			DateTime version1Date = DateTime.Today.AddDays(-1); // stops the getlatestcontent acting up when add+update are the same time

			Page page = new Page();
			page.Title = "Hello world";
			page.Tags = "tag1, tag2";
			page.CreatedOn = version1Date;
			page.ModifiedOn = version1Date;
			PageContent pageContent = _pageRepositoryMock.AddNewPage(page, "Some content1", "editor", version1Date);

			PageViewModel model = new PageViewModel(pageContent.Page);
			model.Title = "New title";
			model.Content = "Some content2";
			model.ModifiedOn = DateTime.UtcNow;

			// Act
			_pagesController.Put(model);

			// Assert
			 Assert.That(_pageService.AllPages().Count(), Is.EqualTo(1));

			PageViewModel actualPage = _pageService.GetById(1, true);
			Assert.That(actualPage.Title, Is.EqualTo("New title"));
			Assert.That(actualPage.Content, Is.EqualTo("Some content2"));
		}
Ejemplo n.º 7
0
		public void frompage_shouldfillcorrectproperties()
		{
			// Arrange
			Page page = new Page();
			page.Id = 123;
			page.CreatedBy = "createdby";
			page.CreatedOn = DateTime.UtcNow;
			page.IsLocked = true;
			page.ModifiedBy = "modifiedby";
			page.ModifiedOn = DateTime.UtcNow;
			page.Tags = "tag1,tag2";
			page.Title = "title";

			PageEntity entity = new PageEntity();

			// Act
			ToEntity.FromPage(page, entity);

			// Assert
			Assert.That(entity.Id, Is.Not.EqualTo(page.Id)); // the id isn't copied from the page
			Assert.That(entity.CreatedBy, Is.EqualTo(page.CreatedBy));
			Assert.That(entity.CreatedOn, Is.EqualTo(page.CreatedOn));
			Assert.That(entity.IsLocked, Is.EqualTo(page.IsLocked));
			Assert.That(entity.ModifiedBy, Is.EqualTo(page.ModifiedBy));
			Assert.That(entity.ModifiedOn, Is.EqualTo(page.ModifiedOn));
			Assert.That(entity.Tags, Is.EqualTo(page.Tags));
			Assert.That(entity.Title, Is.EqualTo(page.Title));
		}
Ejemplo n.º 8
0
		private Page AddDummyPage1()
		{
			Page page1 = new Page() { Id = 1, Tags = "tag1,tag2", Title = "Welcome to the site", CreatedBy = "admin" };
			PageContent page1Content = new PageContent() { Id = Guid.NewGuid(), Page = page1, Text = "Hello world 1", VersionNumber = 1 };
			_pageRepository.Pages.Add(page1);
			_pageRepository.PageContents.Add(page1Content);

			return page1;
		}
Ejemplo n.º 9
0
        public void Get_Should_Return_Page_By_Id()
        {
            // Arrange
            Page expectedPage = new Page() { Id = 7, Title = "new page" };
            _repositoryMock.Pages.Add(expectedPage);

            // Act
            PageViewModel actualPage = _pagesController.Get(7);

            // Assert
            Assert.That(actualPage, Is.Not.Null);
            Assert.That(actualPage.Id, Is.EqualTo(expectedPage.Id));
        }
Ejemplo n.º 10
0
		public PageContent AddNewPageContentVersion(Page page, string text, string editedBy, DateTime editedOn, int version)
		{
			PageContent content = new PageContent();
			content.Id = Guid.NewGuid();
			page.ModifiedBy = content.EditedBy = editedBy;
			page.ModifiedOn = content.EditedOn = editedOn;
			content.Page = page;
			content.Text = text;
			content.VersionNumber = FindPageContentsByPageId(page.Id).Max(x => x.VersionNumber) +1;
			PageContents.Add(content);

			return content;
		}
Ejemplo n.º 11
0
		protected Page NewPage(string author, string tags = "tag1,tag2,tag3", string title = "Title")
		{
			Page page = new Page()
			{
				Title = title,
				CreatedOn = _createdDate,
				CreatedBy = author,
				ModifiedBy = author,
				ModifiedOn = _createdDate,
				Tags = tags
			};

			return page;
		}
Ejemplo n.º 12
0
        protected PageContent AddPage(string title, string content)
        {
            using (IRepository repository = GetRepository())
            {
                Page page = new Page();
                page.Title = title;
                page.Tags = "tag1, tag2";
                page.CreatedBy = "admin";
                page.CreatedOn = DateTime.UtcNow;
                page.ModifiedOn = DateTime.UtcNow;
                page.ModifiedBy = "admin";

                return repository.AddNewPage(page, content, "admin", DateTime.UtcNow);
            }
        }
Ejemplo n.º 13
0
		public PageContent AddNewPage(Page page, string text, string editedBy, DateTime editedOn)
		{
			page.Id = Pages.Count + 1;
			Pages.Add(page);

			PageContent content = new PageContent();
			content.Id = Guid.NewGuid();
			content.EditedBy = editedBy;
			content.EditedOn = editedOn;
			content.Page = page;
			content.Text = text;
			content.VersionNumber = 1;
			PageContents.Add(content);

			return content;
		}
Ejemplo n.º 14
0
        /// <summary>
        /// Adds the page to the database.
        /// </summary>
        /// <param name="model">The summary details for the page.</param>
        /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns>
        /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public PageViewModel AddPage(PageViewModel model)
        {
            try
            {
                string currentUser = _context.CurrentUsername;

                Page page = new Page();
                page.Title = model.Title;
                page.Tags = model.CommaDelimitedTags();
                page.CreatedBy = AppendIpForDemoSite(currentUser);
                page.CreatedOn = DateTime.UtcNow;
                page.ModifiedOn = DateTime.UtcNow;
                page.ModifiedBy = AppendIpForDemoSite(currentUser);
                page.ProjectStart = model.ProjectStart;
                page.ProjectEnd = model.ProjectEnd;
                page.ProjectEstimatedTime = model.ProjectEstimatedTime;
                page.ProjectLanguage = model.ProjectLanguage;
                page.ProjectStatus = model.ProjectStatus;
                page.orgID = model.orgID;

                // Double check, incase the HTML form was faked.
                if (_context.IsAdmin)
                    page.IsLocked = model.IsLocked;

                PageContent pageContent = Repository.AddNewPage(page, model.Content, AppendIpForDemoSite(currentUser), DateTime.UtcNow, model.ProjectStart, model.ProjectEnd, model.ProjectEstimatedTime, model.ProjectStatus, model.ProjectLanguage, model.orgID);

                _listCache.RemoveAll();
                _pageViewModelCache.RemoveAll(); // completely clear the cache to update any reciprocal links.

                // Update the lucene index
                PageViewModel savedModel = new PageViewModel(pageContent, _markupConverter);
                try
                {
                    _searchService.Add(savedModel);
                }
                catch (SearchException)
                {
                    // TODO: log
                }

                return savedModel;
            }
            catch (DatabaseException e)
            {
                throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", model.Title);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Extracts and saves all textual content for a page.
        /// </summary>
        /// <param name="pageName"></param>
        /// <param name="page">The page the content belongs to.</param>
        /// <param name="nameTitleMapping">Mapping between name and title</param>
        private void AddContent(string pageName, Page page, Dictionary<string, string> nameTitleMapping)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    connection.Open();
                    command.CommandText = @"SELECT *, (SELECT MAX(Revision) FROM PageContent PC WHERE PC.Page = PageContent.Page) AS MaxRevision
                                            FROM PageContent WHERE [Page]=@Page ORDER BY LastModified";

                    SqlParameter parameter = new SqlParameter();
                    parameter.ParameterName = "@Page";
                    parameter.SqlDbType = System.Data.SqlDbType.VarChar;
                    parameter.Value = pageName;
                    command.Parameters.Add(parameter);

                    List<PageContent> categories = new List<PageContent>();
                    bool hasContent = false;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            PageContent content = new PageContent();
                            string editedBy = reader["User"].ToString();
                            DateTime editedOn = ConvertToUtcDateTime(reader["LastModified"]);
                            string text = reader["Content"].ToString();
                            text = CleanContent(text, nameTitleMapping);
                            int versionNumber = (int.Parse(reader["Revision"].ToString())) + 1;

                            if (versionNumber == 0)
                                versionNumber = (int.Parse(reader["MaxRevision"].ToString())) + 2;

                            Repository.AddNewPageContentVersion(page, text, editedBy, editedOn, versionNumber);
                            hasContent = true;
                        }
                    }

                    // For broken content, make sure the page has something
                    if (!hasContent)
                    {
                        Repository.AddNewPage(page, "", "unknown", DateTime.UtcNow);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public PageViewModel(Page page)
        {
            if (page == null)
                throw new ArgumentNullException("page");

            Id = page.Id;
            Title = page.Title;
            PreviousTitle = page.Title;
            CreatedBy = page.CreatedBy;
            CreatedOn = page.CreatedOn;
            IsLocked = page.IsLocked;
            ModifiedBy = page.ModifiedBy;
            ModifiedOn = page.ModifiedOn;
            RawTags = page.Tags;

            CreatedOn = DateTime.SpecifyKind(CreatedOn, DateTimeKind.Utc);
            ModifiedOn = DateTime.SpecifyKind(ModifiedOn, DateTimeKind.Utc);
            AllTags = new List<TagViewModel>();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Extracts and saves all textual content for a page.
        /// </summary>
        /// <param name="page">The page the content belongs to.</param>
        private void AddContent(string pageName, Page page)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                using (SqlCommand command = connection.CreateCommand())
                {
                    connection.Open();
                    command.CommandText = "SELECT * FROM PageContent WHERE [Page]=@Page";

                    SqlParameter parameter = new SqlParameter();
                    parameter.ParameterName = "@Page";
                    parameter.SqlDbType = System.Data.SqlDbType.VarChar;
                    parameter.Value = pageName;
                    command.Parameters.Add(parameter);

                    List<PageContent> categories = new List<PageContent>();
                    bool hasContent = false;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            PageContent content = new PageContent();
                            string editedBy = reader["User"].ToString();
                            DateTime EditedOn = (DateTime)reader["LastModified"];
                            string text = reader["Content"].ToString();
                            text = CleanContent(text);
                            int versionNumber = (int.Parse(reader["Revision"].ToString())) + 1;

                            Repository.AddNewPageContentVersion(page, text, editedBy, EditedOn, versionNumber);
                            hasContent = true;
                        }
                    }

                    // For broken content, make sure the page has something
                    if (!hasContent)
                    {
                        Repository.AddNewPage(page, "", "unknown", DateTime.UtcNow);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void About_Should_Return_ViewResult_And_Page_With_About_Tag_As_Model()
        {
            // Arrange
            Page aboutPage = new Page()
            {
                Id = 1,
                Title = "about",
                Tags = "about"
            };

            _repository.AddNewPage(aboutPage, "text", "nobody", DateTime.Now);

            // Act
            ViewResult result = _helpController.About() as ViewResult;

            // Assert
            Assert.That(result, Is.Not.Null);

            PageViewModel model = result.ModelFromActionResult<PageViewModel>();
            Assert.NotNull(model, "Null model");
            Assert.That(model.Id, Is.EqualTo(aboutPage.Id));
            Assert.That(model.Title, Is.EqualTo(aboutPage.Title));
        }
Ejemplo n.º 19
0
		public Page SaveOrUpdatePage(Page page)
		{
			Page existingPage = Pages.FirstOrDefault(x => x.Id == page.Id);

			if (existingPage == null)
			{
				page.Id = Pages.Count + 1;
				Pages.Add(page);
				existingPage = page;
			}
			else
			{
				existingPage.CreatedBy = page.CreatedBy;
				existingPage.CreatedOn = page.CreatedOn;
				existingPage.IsLocked = page.IsLocked;
				existingPage.ModifiedBy = page.ModifiedBy;
				existingPage.ModifiedOn = page.ModifiedOn;
				existingPage.Tags = page.Tags;
				existingPage.Title = page.Title;
			}

			return existingPage;
		}
Ejemplo n.º 20
0
        /// <summary>
        /// Adds a page to the mock repository (which is just a list of Page and PageContent objects in memory).
        /// </summary>
        public PageViewModel AddToMockedRepository(int id, string createdBy, string title, string tags, DateTime createdOn, string textContent = "")
        {
            Page page = new Page();
            page.Id = id;
            page.CreatedBy = createdBy;
            page.Title = title;
            page.Tags = tags;
            page.CreatedOn = createdOn;

            if (string.IsNullOrEmpty(textContent))
                textContent = title + "'s text";

            PageContent content = _pageRepository.AddNewPage(page, textContent, createdBy, createdOn);
            PageViewModel model = new PageViewModel()
            {
                Id = id,
                Title = title,
                Content = textContent,
                RawTags = tags,
                CreatedBy = createdBy,
                CreatedOn = createdOn
            };

            return model;
        }
Ejemplo n.º 21
0
		private Page AddDummyPage2()
		{
			Page page2 = new Page() { Id = 50, Tags = "anothertag", Title = "Page 2" };
			PageContent page2Content = new PageContent() { Id = Guid.NewGuid(), Page = page2, Text = "Hello world 2" };
			_pageRepository.Pages.Add(page2);
			_pageRepository.PageContents.Add(page2Content);

			return page2;
		}
Ejemplo n.º 22
0
		private Page NewPage(string author, string tags = "tag1,tag2,tag3", string title = "Title")
		{
			Page page = new Page()
			{
				Title = title,
				CreatedOn = DateTime.Today,
				CreatedBy = author,
				ModifiedBy = author,
				ModifiedOn = DateTime.Today,
				Tags = tags
			};

			return page;
		}
Ejemplo n.º 23
0
		public void page_constructor_should_fill_properties()
		{
			// Arrange
			Page page = new Page();
			page.Id = 3;
			page.Title = "my title";
			page.CreatedBy = "me";
			page.CreatedOn = DateTime.Now;
			page.IsLocked = true;
			page.ModifiedBy = "me2";
			page.ModifiedOn = DateTime.Now.AddDays(1);
			page.Tags = "tag1,tag2,tag3";

			// Act
			PageViewModel model = new PageViewModel(page);

			// Assert
			Assert.That(model.Id, Is.EqualTo(page.Id));
			Assert.That(model.Title, Is.EqualTo(page.Title));
			Assert.That(model.CreatedBy, Is.EqualTo(page.CreatedBy));
			Assert.That(model.ModifiedBy, Is.EqualTo(page.ModifiedBy));
			Assert.That(model.CreatedOn, Is.EqualTo(page.CreatedOn));
			Assert.That(model.CreatedOn.Kind, Is.EqualTo(DateTimeKind.Utc));
			Assert.That(model.ModifiedOn, Is.EqualTo(page.ModifiedOn));
			Assert.That(model.ModifiedOn.Kind, Is.EqualTo(DateTimeKind.Utc));

			Assert.That(model.Tags.Count(), Is.EqualTo(3));
			Assert.That(model.Tags, Contains.Item("tag1"));
			Assert.That(model.Tags, Contains.Item("tag2"));
			Assert.That(model.Tags, Contains.Item("tag3"));
		}
Ejemplo n.º 24
0
		/// <summary>
		/// Adds all pages and their content from screwturn.
		/// </summary>
		private void ImportPages()
		{
			Dictionary<string, string> nameTitleMapping = new Dictionary<string, string>();
			try
			{
				using (SqlConnection connection = new SqlConnection(_connectionString))
				{
					using (SqlCommand command = connection.CreateCommand())
					{
						connection.Open();
						command.CommandText = @"SELECT 
												p.Name,
												pc.Title
											FROM [Page] p
												INNER JOIN [PageContent] pc ON pc.[Page] = p.Name
											WHERE 
												pc.Revision = (SELECT TOP 1 Revision FROM PageContent WHERE [Page]=p.Name ORDER BY LastModified)
											ORDER BY p.CreationDateTime";

						using (SqlDataReader reader = command.ExecuteReader())
						{
							while (reader.Read())
							{
								nameTitleMapping.Add(reader["Name"].ToString(), reader["Title"].ToString());
							}
						}
					}

					using (SqlCommand command = connection.CreateCommand())
					{
						command.CommandText = @"SELECT 
												p.CreationDateTime,
												p.Name,
												pc.[User] as [User],
												pc.Title,
												pc.LastModified 
											FROM [Page] p
												INNER JOIN [PageContent] pc ON pc.[Page] = p.Name
											WHERE 
												pc.Revision = (SELECT TOP 1 Revision FROM PageContent WHERE [Page]=p.Name ORDER BY LastModified)
											ORDER BY p.CreationDateTime";

						using (SqlDataReader reader = command.ExecuteReader())
						{
							while (reader.Read())
							{
								string pageName = reader["Name"].ToString();

								Page page = new Page();
								page.Title = reader["Title"].ToString();
								page.CreatedBy = reader["User"].ToString();
								page.CreatedOn = ConvertToUtcDateTime(reader["CreationDateTime"]);
								page.ModifiedBy = reader["User"].ToString();
								page.ModifiedOn = ConvertToUtcDateTime(reader["LastModified"]);

								string categories = GetCategories(pageName);
								if (!string.IsNullOrWhiteSpace(categories))
									categories += ",";
								page.Tags = categories;

								page = PageRepository.SaveOrUpdatePage(page);
								AddContent(pageName, page, nameTitleMapping);
							}
						}
					}
				}
			}
			catch (SqlException ex)
			{
				throw new DatabaseException(ex, "Unable to import the pages from Screwturn - have you configured it to use the SQL Server pages provider? \n{0}", ex.Message);
			}
		}
Ejemplo n.º 25
0
		public void Should_Export_Pages_With_Content()
		{
			// Arrange
			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings.PluginLastSaveDate = DateTime.Today;

			DateTime page1CreatedOn  = new DateTime(2013, 01, 01, 12, 00, 00);
			DateTime page1ModifiedOn = new DateTime(2013, 01, 01, 13, 00, 00);
			DateTime page2CreatedOn  = new DateTime(2013, 01, 02, 12, 00, 00);
			DateTime page2ModifiedOn = new DateTime(2013, 01, 02, 13, 00, 00);
			DateTime page3CreatedOn  = new DateTime(2013, 01, 03, 12, 00, 00);
			DateTime page3ModifiedOn = new DateTime(2013, 01, 03, 13, 00, 00);

			Guid page1ContentId = new Guid("13a8ad19-b203-46f5-be10-11e0ebf6f812");
			Guid page2ContentId = new Guid("143b0023-329a-49b9-97a4-5094a0e378a2");
			Guid page3ContentId = new Guid("15ee19ef-c093-47de-97d2-83dec406d92d");

			string page1Text = @"the text ;'''


								"" more text """;

			string page2Text = @"the text ;''' #### sdfsdfsdf ####


								"" blah text """;

			string page3Text = @"the text ;''' #### dddd **dddd** ####			
			

								"" pppp text """;

			Page page1 = new Page()
			{
				CreatedBy = "created-by-user1",
				CreatedOn = page1CreatedOn,
				Id = 1,
				IsLocked = true,
				ModifiedBy = "modified-by-user2",
				ModifiedOn = page1ModifiedOn,
				Tags = "tag1,tag2,tag3",
				Title = "Page 1 title"
			};

			Page page2 = new Page()
			{
				CreatedBy = "created-by-user2",
				CreatedOn = page2CreatedOn,
				Id = 2,
				IsLocked = true,
				ModifiedBy = "modified-by-user2",
				ModifiedOn = page2ModifiedOn,
				Tags = "tagA,tagB,tagC",
				Title = "Page 2 title"
			};

			Page page3 = new Page()
			{
				CreatedBy = "created-by-user3",
				CreatedOn = page3CreatedOn,
				Id = 3,
				IsLocked = false,
				ModifiedBy = "modified-by-user3",
				ModifiedOn = page3ModifiedOn,
				Tags = "tagX,tagY,tagZ",
				Title = "Page 3 title"
			};

			PageContent pageContent1 = repository.AddNewPage(page1, page1Text, "modified-by-user1", page1ModifiedOn);
			pageContent1.Id = page1ContentId;

			PageContent pageContent2 = repository.AddNewPage(page2, page2Text, "modified-by-user2", page2ModifiedOn);
			pageContent2.Id = page2ContentId;

			PageContent pageContent3 = repository.AddNewPage(page3, page3Text, "modified-by-user3", page3ModifiedOn);
			pageContent3.Id = page3ContentId;

			SqlExportBuilder builder = new SqlExportBuilder(repository, new PluginFactoryMock());
			builder.IncludeConfiguration = false;
			builder.IncludePages = true;

			string expectedSql = ReadEmbeddedResource("expected-pages-export.sql");

			// Act
			string actualSql = builder.Export();

			// Assert
			Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql);
		}
Ejemplo n.º 26
0
        public void Search_Should_Return_Some_Results_With_Unicode_Content()
        {
            // Arrange
            Page page1 = new Page()
            {
                Id = 1,
                Tags = "homepage, tag2",
                Title = "ОШИБКА: неверная последовательность байт для кодировки"
            };
            PageContent page1Content = new PageContent()
            {
                Id = Guid.NewGuid(),
                Page = page1,
                Text = "БД сервера событий была перенесена из PostgreSQL 8.3 на PostgreSQL 9.1.4. Сервер, развернутый на Windows платформе"
            };
            _repository.Pages.Add(page1);
            _repository.PageContents.Add(page1Content);

            // Act
            ActionResult result = _homeController.Search("ОШИБКА: неверная последовательность байт для кодировки");

            // Assert
            Assert.That(result, Is.TypeOf<ViewResult>(), "ViewResult");

            List<SearchResultViewModel> searchResults = result.ModelFromActionResult<IEnumerable<SearchResultViewModel>>().ToList();
            Assert.NotNull(searchResults, "Null model");
            Assert.That(searchResults.Count(), Is.EqualTo(1));
            Assert.That(searchResults[0].Title, Is.EqualTo(page1.Title));
            Assert.That(searchResults[0].ContentSummary, Contains.Substring(page1Content.Text));
        }
Ejemplo n.º 27
0
		public void DeletePage(Page page)
		{
			Pages.Remove(page);
		}
        private WikiController CreateWikiController(BrowserCacheAttribute attribute)
        {
            // Settings
            ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseBrowserCache = true };
            UserContextStub userContext = new UserContextStub() { IsLoggedIn = false };

            // PageService
            PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, CacheMock.RoadkillCache);
            ListCache listCache = new ListCache(appSettings, CacheMock.RoadkillCache);
            SiteCache siteCache = new SiteCache(appSettings, CacheMock.RoadkillCache);
            SearchServiceMock searchService = new SearchServiceMock(appSettings, _repositoryMock, _pluginFactory);
            PageHistoryService historyService = new PageHistoryService(appSettings, _repositoryMock, userContext, pageViewModelCache, _pluginFactory);
            PageService pageService = new PageService(appSettings, _repositoryMock, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory);

            // WikiController
            SettingsService settingsService = new SettingsService(appSettings, _repositoryMock);
            UserServiceStub userManager = new UserServiceStub();
            WikiController wikiController = new WikiController(appSettings, userManager, pageService, userContext, settingsService);

            // Create a page that the request is for
            Page page = new Page() { Title = "title", ModifiedOn = _pageModifiedDate };
            _repositoryMock.AddNewPage(page, "text", "user", _pageCreatedDate);

            // Update the BrowserCacheAttribute
            attribute.ApplicationSettings = appSettings;
            attribute.Context = userContext;
            attribute.PageService = pageService;

            return wikiController;
        }
Ejemplo n.º 29
0
        public PageViewModel(Page page)
        {
            if (page == null)
                throw new ArgumentNullException("page");

            Id = page.Id;
            Title = page.Title;
            PreviousTitle = page.Title;
            CreatedBy = page.CreatedBy;
            CreatedOn = page.CreatedOn;
            IsLocked = page.IsLocked;
            ModifiedBy = page.ModifiedBy;
            ModifiedOn = page.ModifiedOn;
            RawTags = page.Tags;
            ProjectStart = page.ProjectStart;
            ProjectEnd = page.ProjectEnd;
            ProjectEstimatedTime = page.ProjectEstimatedTime;
            ProjectStatus = page.ProjectStatus;
            ProjectLanguage = page.ProjectLanguage;
            orgID = page.orgID;
            Rel = RelToUserToPage(Id);

            Relationships = GetRelationships();

            CreatedOn = DateTime.SpecifyKind(CreatedOn, DateTimeKind.Utc);
            ModifiedOn = DateTime.SpecifyKind(ModifiedOn, DateTimeKind.Utc);
            AllTags = new List<TagViewModel>();

        }