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(); }
public void Setup() { _pluginFactory = new PluginFactoryMock(); _pageRepository = new PageRepositoryMock(); _settingsRepository = new SettingsRepositoryMock(); _settingsRepository.SiteSettings = new SiteSettings(); _settingsRepository.SiteSettings.MarkupType = "Markdown"; _userContext = new UserContextStub(); _applicationSettings = new ApplicationSettings(); _applicationSettings.Installed = true; _cache = new CacheMock(); _siteCache = new SiteCache(_cache); _converter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); _menuParser = new MenuParser(_converter, _settingsRepository, _siteCache, _userContext); }
private PageService CreatePageService(ObjectCache pageObjectCache, ObjectCache listObjectCache, SettingsRepositoryMock settingsRepository, PageRepositoryMock pageRepository) { // Stick to memorycache when each one isn't used if (pageObjectCache == null) pageObjectCache = CacheMock.RoadkillCache; if (listObjectCache == null) listObjectCache = CacheMock.RoadkillCache; // Settings ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseObjectCache = true }; UserContextStub userContext = new UserContextStub() { IsLoggedIn = false }; // PageService PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, pageObjectCache); ListCache listCache = new ListCache(appSettings, listObjectCache); SiteCache siteCache = new SiteCache(CacheMock.RoadkillCache); SearchServiceMock searchService = new SearchServiceMock(appSettings, settingsRepository, pageRepository, _pluginFactory); PageHistoryService historyService = new PageHistoryService(appSettings, settingsRepository, pageRepository, userContext, pageViewModelCache, _pluginFactory); PageService pageService = new PageService(appSettings, settingsRepository, pageRepository, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory); return pageService; }
private WikiController CreateWikiController(BrowserCacheAttribute attribute) { // Settings ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseBrowserCache = true }; UserContextStub userContext = new UserContextStub() { IsLoggedIn = false }; // PageService PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, CacheMock.RoadkillCache); ListCache listCache = new ListCache(appSettings, CacheMock.RoadkillCache); SiteCache siteCache = new SiteCache(appSettings, CacheMock.RoadkillCache); SearchServiceMock searchService = new SearchServiceMock(appSettings, _repositoryMock, _pluginFactory); PageHistoryService historyService = new PageHistoryService(appSettings, _repositoryMock, userContext, pageViewModelCache, _pluginFactory); PageService pageService = new PageService(appSettings, _repositoryMock, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory); // WikiController SettingsService settingsService = new SettingsService(appSettings, _repositoryMock); UserServiceStub userManager = new UserServiceStub(); WikiController wikiController = new WikiController(appSettings, userManager, pageService, userContext, settingsService); // Create a page that the request is for Page page = new Page() { Title = "title", ModifiedOn = _pageModifiedDate }; _repositoryMock.AddNewPage(page, "text", "user", _pageCreatedDate); // Update the BrowserCacheAttribute attribute.ApplicationSettings = appSettings; attribute.Context = userContext; attribute.PageService = pageService; return wikiController; }