public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _settingsRepository = _container.SettingsRepository; _userRepository = _container.UserRepository; _pageRepository = _container.PageRepository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _container.ClearCache(); _pageService = _container.PageService; _wikiImporter = new WikiImporterMock(); _pluginFactory = _container.PluginFactory; _searchService = _container.SearchService; // There's no point mocking WikiExporter (and turning it into an interface) as // a lot of usefulness of these tests would be lost when creating fake Streams and zip files. _wikiExporter = new WikiExporter(_applicationSettings, _pageService, _settingsRepository, _pageRepository, _userRepository, _pluginFactory); _wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory; _toolsController = new ToolsController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _context, _listCache, _pageCache, _wikiImporter, _pluginFactory, _wikiExporter); }
public void Setup() { // WikiController setup (use WikiController as it's the one typically used by views) _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _pageRepository = _container.PageRepository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _wikiController = new WikiController(_applicationSettings, _userService, _pageService, _context, _settingsService); _wikiController.SetFakeControllerContext("~/wiki/index/1"); // HtmlHelper setup var viewDataDictionary = new ViewDataDictionary(); _viewContext = new ViewContext(_wikiController.ControllerContext, new Mock<IView>().Object, viewDataDictionary, new TempDataDictionary(), new StringWriter()); var mockViewDataContainer = new Mock<IViewDataContainer>(); mockViewDataContainer.Setup(v => v.ViewData).Returns(viewDataDictionary); _htmlHelper = new HtmlHelper(_viewContext, mockViewDataContainer.Object); }
/// <summary> /// Creates a new instance of MocksAndStubsContainer. /// </summary> /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param> public MocksAndStubsContainer(bool useCacheMock = false) { ApplicationSettings = new ApplicationSettings(); ApplicationSettings.Installed = true; ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments"); // Cache MemoryCache = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache; ListCache = new ListCache(ApplicationSettings, MemoryCache); SiteCache = new SiteCache(ApplicationSettings, MemoryCache); PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache); // Repository Repository = new RepositoryMock(); Repository.SiteSettings = new SiteSettings(); Repository.SiteSettings.MarkupType = "Creole"; PluginFactory = new PluginFactoryMock(); MarkupConverter = new MarkupConverter(ApplicationSettings, Repository, PluginFactory); // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock. SettingsService = new SettingsService(ApplicationSettings, Repository); UserService = new UserServiceMock(ApplicationSettings, Repository); UserContext = new UserContext(UserService); SearchService = new SearchServiceMock(ApplicationSettings, Repository, PluginFactory); SearchService.PageContents = Repository.PageContents; SearchService.Pages = Repository.Pages; HistoryService = new PageHistoryService(ApplicationSettings, Repository, UserContext, PageViewModelCache, PluginFactory); PageService = new PageService(ApplicationSettings, Repository, SearchService, HistoryService, UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory); // EmailTemplates EmailClient = new EmailClientMock(); }
public WikiExporter(ApplicationSettings applicationSettings, PageService pageService, ISettingsRepository settingsRepository, IPageRepository pageRepository, IUserRepository userRepository, IPluginFactory pluginFactory) { if (applicationSettings == null) throw new ArgumentNullException(nameof(applicationSettings)); if (pageService == null) throw new ArgumentNullException(nameof(pageService)); if (settingsRepository == null) throw new ArgumentNullException(nameof(settingsRepository)); if (pageRepository == null) throw new ArgumentNullException(nameof(pageRepository)); if (userRepository == null) throw new ArgumentNullException(nameof(userRepository)); if (pluginFactory == null) throw new ArgumentNullException(nameof(pluginFactory)); _applicationSettings = applicationSettings; _pageService = pageService; _sqlExportBuilder = new SqlExportBuilder(settingsRepository, userRepository, pageRepository, pluginFactory); ExportFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Export"); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.ConnectionString = "connstring"; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _listCache = _container.ListCache; _pageViewModelCache = _container.PageViewModelCache; // User setup _editorUser = new User(); _editorUser.Id = Guid.NewGuid(); _editorUser.Email = EditorEmail; _editorUser.Username = EditorUsername; _editorUser.IsAdmin = false; _editorUser.IsEditor = true; _adminUser = new User(); _adminUser.Id = Guid.NewGuid(); _adminUser.Email = AdminEmail; _adminUser.Username = AdminUsername; _adminUser.IsAdmin = true; _adminUser.IsEditor = true; _userService.Users.Add(_editorUser); _userService.Users.Add(_adminUser); SetUserContext(_adminUser); }
public HomeController(ApplicationSettings settings, UserServiceBase userManager, MarkupConverter markupConverter, PageService pageService, SearchService searchService, IUserContext context, SettingsService settingsService) : base(settings, userManager, context, settingsService) { _markupConverter = markupConverter; _searchService = searchService; PageService = pageService; }
public void Setup() { _container = new MocksAndStubsContainer(); _pageRepositoryMock = _container.PageRepository; _pageService = _container.PageService; _pagesController = new PagesController(_pageService); }
public void Setup() { _container = new MocksAndStubsContainer(); _pageService = _container.PageService; _searchService = _container.SearchService; _searchController = new SearchController(_searchService); }
public InstallController(ApplicationSettings settings, UserServiceBase userService, PageService pageService, SearchService searchService, IRepository respository, SettingsService settingsService, IUserContext context, ConfigReaderWriter configReaderWriter) : base(settings, userService, context, settingsService) { _pageService = pageService; _searchService = searchService; _repository = respository; _settingsService = settingsService; _configReaderWriter = configReaderWriter; }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _repository = _container.Repository; _pageService = _container.PageService; _pluginFactory = _container.PluginFactory; _wikiExporter = new WikiExporter(_applicationSettings, _pageService, _repository, _pluginFactory); _wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory; }
public ToolsController(ApplicationSettings settings, UserServiceBase userManager, SettingsService settingsService, PageService pageService, SearchService searchService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, IWikiImporter wikiImporter, IPluginFactory pluginFactory, WikiExporter wikiExporter) : base(settings, userManager, context, settingsService) { _pageService = pageService; _searchService = searchService; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _wikiImporter = wikiImporter; _wikiExporter = wikiExporter; }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _userContext = _container.UserContext; _userService = _container.UserService; _repositoryMock = _container.Repository; _pageService = _container.PageService; _pagesController = new PagesController(_pageService, _applicationSettings, _userService, _userContext); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageService = _container.PageService; _helpController = new HelpController(_applicationSettings, _userService, _context, _settingsService, _pageService); }
public WikiExporter(ApplicationSettings applicationSettings, PageService pageService, IRepository repository, IPluginFactory pluginFactory) { if (applicationSettings == null) throw new ArgumentNullException("applicationSettings"); if (pageService == null) throw new ArgumentNullException("pageService"); _applicationSettings = applicationSettings; _pageService = pageService; _sqlExportBuilder = new SqlExportBuilder(repository, pluginFactory); ExportFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Export"); }
public UserManagementController(ApplicationSettings settings, UserServiceBase userManager, SettingsService settingsService, PageService pageService, SearchService searchService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache siteCache, IWikiImporter wikiImporter, IRepository repository, IPluginFactory pluginFactory) : base(settings, userManager, context, settingsService) { _settingsService = settingsService; _pageService = pageService; _searchService = searchService; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = siteCache; _wikiImporter = wikiImporter; _repository = repository; _pluginFactory = pluginFactory; }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _pageRepository = _container.PageRepository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _wikiController = new WikiController(_applicationSettings, _userService, _pageService, _context, _settingsService); _wikiController.SetFakeControllerContext(); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.Installed = false; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _searchService = _container.SearchService; _configReaderWriter = new ConfigReaderWriterStub(); _installController = new InstallController(_applicationSettings, _userService, _pageService, _searchService, _repository, _settingsService, _context, _configReaderWriter); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _settingsService = _container.SettingsService; _userService = _container.UserService; _controller = new ControllerBaseStub(_applicationSettings, _userService, _context, _settingsService); MvcMockContainer container = _controller.SetFakeControllerContext("~/"); // Used by InstallController _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _historyService = _container.HistoryService; _pageService = _container.PageService; _searchService = _container.SearchService; _configReaderWriter = new ConfigReaderWriterStub(); }
public void Setup() { _container = new MocksAndStubsContainer(true); _applicationSettings = _container.ApplicationSettings; _applicationSettings.UseObjectCache = true; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _pageViewModelCache = _container.PageViewModelCache; _memoryCache = _container.MemoryCache; _controller = new PluginSettingsController(_applicationSettings, _userService, _context, _settingsService, _pluginFactory, _repository, _siteCache, _pageViewModelCache, _listCache); }
public void Setup() { // WikiController setup (use WikiController as it's the one typically used by views) _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _pageRepository = _container.PageRepository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _siteSettings = _settingsService.GetSiteSettings(); _siteSettings.Theme = "Mediawiki"; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _wikiController = new WikiController(_applicationSettings, _userService, _pageService, _context, _settingsService); _wikiController.SetFakeControllerContext("~/wiki/index/1"); _urlHelper = _wikiController.Url; }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _pageService = _container.PageService; _wikiImporter = new ScrewTurnImporter(_applicationSettings, _repository); _pluginFactory = _container.PluginFactory; _searchService = _container.SearchService; _controller = new UserManagementController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _context, _listCache, _pageCache, _siteCache, _wikiImporter, _repository, _pluginFactory); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _attachmentFileHandler = new AttachmentFileHandler(_applicationSettings,_container.FileService); _fileService = _container.FileService as FileServiceMock; try { // Delete any existing attachments folder DirectoryInfo directoryInfo = new DirectoryInfo(_applicationSettings.AttachmentsFolder); if (directoryInfo.Exists) { directoryInfo.Attributes = FileAttributes.Normal; directoryInfo.Delete(true); } Directory.CreateDirectory(_applicationSettings.AttachmentsFolder); } catch (IOException e) { Assert.Fail("Unable to delete the attachments folder " + _applicationSettings.AttachmentsFolder + ", does it have a lock/explorer window open, or Mercurial open?" + e.ToString()); } catch (ArgumentException e) { Assert.Fail("Unable to delete the attachments folder " + _applicationSettings.AttachmentsFolder + ", is EasyMercurial open?" + e.ToString()); } _filesController = new FileManagerController(_applicationSettings, _userService, _context, _settingsService, _attachmentFileHandler, _fileService); _mvcMockContainer = _filesController.SetFakeControllerContext(); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _pageRepository = _container.PageRepository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _searchService = _container.SearchService; _markupConverter = _container.MarkupConverter; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _pageViewModelCache = _container.PageViewModelCache; _memoryCache = _container.MemoryCache; _homeController = new HomeController(_applicationSettings, _userService, _markupConverter, _pageService, _searchService, _context, _settingsService); _homeController.SetFakeControllerContext(); }
/// <summary> /// Creates a new instance of MocksAndStubsContainer. /// </summary> /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param> public MocksAndStubsContainer(bool useCacheMock = false) { ApplicationSettings = new ApplicationSettings(); ApplicationSettings.Installed = true; ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments"); ConfigReaderWriter = new ConfigReaderWriterStub(); // Cache MemoryCache = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache; ListCache = new ListCache(ApplicationSettings, MemoryCache); SiteCache = new SiteCache(MemoryCache); PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache); // Repositories SettingsRepository = new SettingsRepositoryMock(); SettingsRepository.SiteSettings = new SiteSettings(); SettingsRepository.SiteSettings.MarkupType = "Creole"; UserRepository = new UserRepositoryMock(); PageRepository = new PageRepositoryMock(); InstallerRepository = new InstallerRepositoryMock(); RepositoryFactory = new RepositoryFactoryMock() { SettingsRepository = SettingsRepository, UserRepository = UserRepository, PageRepository = PageRepository, InstallerRepository = InstallerRepository }; DatabaseTester = new DatabaseTesterMock(); // Plugins PluginFactory = new PluginFactoryMock(); MarkupConverter = new MarkupConverter(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory); // Services // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock. SettingsService = new SettingsService(RepositoryFactory, ApplicationSettings); UserService = new UserServiceMock(ApplicationSettings, UserRepository); UserContext = new UserContext(UserService); SearchService = new SearchServiceMock(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory); SearchService.PageContents = PageRepository.PageContents; SearchService.Pages = PageRepository.Pages; HistoryService = new PageHistoryService(ApplicationSettings, SettingsRepository, PageRepository, UserContext, PageViewModelCache, PluginFactory); FileService = new FileServiceMock(); PageService = new PageService(ApplicationSettings, SettingsRepository, PageRepository, SearchService, HistoryService, UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory); StructureMapContainer = new Container(x => { x.AddRegistry(new TestsRegistry(this)); }); Locator = new StructureMapServiceLocator(StructureMapContainer, false); InstallationService = new InstallationService((databaseName, connectionString) => { InstallerRepository.DatabaseName = databaseName; InstallerRepository.ConnectionString = connectionString; return InstallerRepository; }, Locator); // EmailTemplates EmailClient = new EmailClientMock(); }
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; }
public WikiController(ApplicationSettings settings, UserServiceBase userManager, PageService pageService, IUserContext context, SettingsService settingsService) : base(settings, userManager, context, settingsService) { PageService = 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; }
public HelpController(ApplicationSettings settings, UserServiceBase userManager, IUserContext context, SettingsService settingsService, PageService pageService) : base(settings, userManager, context, settingsService) { _customTokenParser = new CustomTokenParser(settings); _pageService = pageService; }
public InstallControllerStub(ApplicationSettings settings, UserServiceBase userService, PageService pageService, SearchService searchService, IRepository respository, SettingsService settingsService, IUserContext context, ConfigReaderWriter configReaderWriter) : base(settings, userService, pageService, searchService, respository, settingsService, context, configReaderWriter) { }
public TagCloud(PageService pageService) { _pageService = pageService; }