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 Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _settingsRepository = _container.SettingsRepository; _pageRepository = _container.PageRepository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _markupConverter = _container.MarkupConverter; _searchService = _container.SearchService; // Use a stub instead of the MocksAndStubsContainer's default _contextStub = new UserContextStub(); // Customise the page service so we can verify what was called _pageServiceMock = new Mock<IPageService>(); _pageServiceMock.Setup(x => x.GetMarkupConverter()).Returns(new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory)); _pageServiceMock.Setup(x => x.GetById(It.IsAny<int>(), false)).Returns<int, bool>((int id, bool loadContent) => { Page page = _pageRepository.GetPageById(id); return new PageViewModel(page); }); _pageServiceMock.Setup(x => x.GetById(It.IsAny<int>(), true)).Returns<int,bool>((int id, bool loadContent) => { PageContent content = _pageRepository.GetLatestPageContent(id); if (content != null) return new PageViewModel(content, _markupConverter); else return null; }); _pageServiceMock.Setup(x => x.FindByTag(It.IsAny<string>())); _pageService = _pageServiceMock.Object; _pagesController = new PagesController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _historyService, _contextStub); _mocksContainer = _pagesController.SetFakeControllerContext(); }