Ejemplo n.º 1
0
        public void compareversions_has_last_two_versions()
        {
            // Arrange
            DateTime createdDate = DateTime.Today.AddDays(-1);
            Page page = NewPage("admin");
            PageContent v1Content = _pageRepository.AddNewPage(page, "v1 text", "admin", createdDate);
            PageContent v2Content = _pageRepository.AddNewPageContentVersion(page, "v2 text", "admin", createdDate.AddHours(1), 2);
            PageContent v3Content = _pageRepository.AddNewPageContentVersion(page, "v3 text", "admin", createdDate.AddHours(2), 3);
            PageContent v4Content = _pageRepository.AddNewPageContentVersion(page, "v4 text", "admin", createdDate.AddHours(3), 4);

            // Act
            List<PageViewModel> versionList = _historyService.CompareVersions(v4Content.Id).ToList();

            // Assert
            Assert.That(versionList.Count, Is.EqualTo(2));
            Assert.That(versionList[0].Id, Is.EqualTo(v3Content.Page.Id));
            Assert.That(versionList[1].Id, Is.EqualTo(v4Content.Page.Id));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a particular version of a page.
        /// </summary>
        /// <param name="id">The Guid ID for the version.</param>
        /// <returns>A <see cref="PageViewModel"/> as the model, which contains the HTML diff
        /// output inside the <see cref="PageViewModel.Content"/> property.</returns>
        public ActionResult Version(Guid id)
        {
            MarkupConverter       converter    = _pageService.GetMarkupConverter();
            IList <PageViewModel> bothVersions = _historyService.CompareVersions(id).ToList();
            string diffHtml = "";

            if (bothVersions[1] != null)
            {
                string   oldVersion = converter.ToHtml(bothVersions[1].Content).Html;
                string   newVersion = converter.ToHtml(bothVersions[0].Content).Html;
                HtmlDiff diff       = new HtmlDiff(oldVersion, newVersion);
                diffHtml = diff.Build();
            }
            else
            {
                diffHtml = converter.ToHtml(bothVersions[0].Content).Html;
            }

            PageViewModel model = bothVersions[0];

            model.Content = diffHtml;
            return(View(model));
        }