public void RenameTag_Should_Redirect_And_Set_TempData_Message_And_Rename_Tag() { // Arrange _repository.AddNewPage(new Page() { Id = 1, Tags = "old" }, "text", "admin", DateTime.UtcNow); _repository.AddNewPage(new Page() { Id = 2, Tags = "old" }, "text", "admin", DateTime.UtcNow); // Act RedirectToRouteResult result = _toolsController.RenameTag("old", "new") as RedirectToRouteResult; // Assert Assert.That(result, Is.Not.Null, "RedirectToRouteResult"); Assert.That(result.RouteValues["action"], Is.EqualTo("Index")); Assert.That(_toolsController.TempData["SuccessMessage"], Is.EqualTo(SiteStrings.SiteSettings_Tools_RenameTag_Message)); Assert.That(_repository.GetPageById(1).Tags, Is.StringContaining("new")); Assert.That(_repository.GetPageById(2).Tags, Is.StringContaining("new")); }
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(); }
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(); }