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));
        }
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings = _container.ApplicationSettings;
            _repository          = _container.Repository;
            _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, _repository, _pluginFactory));
            _pageServiceMock.Setup(x => x.GetById(It.IsAny <int>(), false)).Returns <int, bool>((int id, bool loadContent) =>
            {
                Page page = _repository.GetPageById(id);
                return(new PageViewModel(page));
            });
            _pageServiceMock.Setup(x => x.GetById(It.IsAny <int>(), true)).Returns <int, bool>((int id, bool loadContent) =>
            {
                PageContent content = _repository.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();
        }
Example #3
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_repository = _container.Repository;
			_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, _repository, _pluginFactory));
			_pageServiceMock.Setup(x => x.GetById(It.IsAny<int>(), false)).Returns<int, bool>((int id, bool loadContent) =>
				{
					Page page = _repository.GetPageById(id);
					return new PageViewModel(page);
				});
			_pageServiceMock.Setup(x => x.GetById(It.IsAny<int>(), true)).Returns<int,bool>((int id, bool loadContent) =>
			{
				PageContent content = _repository.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();
		}