Пример #1
0
        public void revertto_with_pageid_should_add_new_version()
        {
            // Arrange
            DateTime createdDate = DateTime.Today.AddDays(-1);
            Page page = NewPage("admin");
            PageContent v1Content = _pageRepository.AddNewPage(page, "v1 text", "admin", createdDate);
            page = v1Content.Page;
            PageContent v2Content = _pageRepository.AddNewPageContentVersion(page, "v2 text", "admin", createdDate.AddHours(1), 2);

            // Act
            _historyService.RevertTo(page.Id, 1);
            PageContent actualContent = _pageRepository.GetLatestPageContent(page.Id);

            // Assert
            Assert.That(actualContent.VersionNumber, Is.EqualTo(3));
            Assert.That(actualContent.Text, Is.EqualTo(v1Content.Text));
            Assert.That(actualContent.EditedBy, Is.EqualTo("admin"));
        }
        public void RevertTo_With_VersionId_Should_Add_New_Version()
        {
            // Arrange
            DateTime createdDate = DateTime.Today.AddDays(-1);

            _context.CurrentUser = "******";
            Page        page      = NewPage("admin");
            PageContent v1Content = _repository.AddNewPage(page, "v1 text", "admin", createdDate);

            page = v1Content.Page;
            PageContent v2Content = _repository.AddNewPageContentVersion(page, "v2 text", "admin", createdDate.AddHours(1), 2);

            // Act
            _historyService.RevertTo(v1Content.Id, _context);
            PageContent actualContent = _repository.GetLatestPageContent(page.Id);

            // Assert
            Assert.That(actualContent.VersionNumber, Is.EqualTo(3));
            Assert.That(actualContent.Text, Is.EqualTo(v1Content.Text));
            Assert.That(actualContent.EditedBy, Is.EqualTo(_context.CurrentUsername));
        }
Пример #3
0
        public ActionResult Revert(Guid versionId, int pageId)
        {
            // Check if the page is locked to admin edits only before reverting.
            PageViewModel page = _pageService.GetById(pageId);

            if (page == null || (page.IsLocked && !Context.IsAdmin))
            {
                return(RedirectToAction("Index", "Home"));
            }

            _historyService.RevertTo(versionId, Context);

            return(RedirectToAction("History", new { id = pageId }));
        }