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);
		}
Beispiel #2
0
		public void Should_Replace_Known_Tokens_When_Logged_In_As_Editor()
		{
			// Arrange
			string menuMarkup = "* %categories%\r\n\r\n%allpages%\r\n%mainpage%\r\n%newpage%\r\n%managefiles%\r\n%sitesettings%\r\n";
			string expectedHtml = "<ul><li><a href=\"/pages/alltags\">Categories</a></li></ul>" +
								  "<a href=\"/pages/allpages\">All pages</a>" +
								  "<a href=\"/\">Main Page</a>" +
								  "<a href=\"/pages/new\">New page</a><a href=\"/filemanager\">Manage files</a>";

			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = "Markdown";
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			userContext.IsAdmin = false;
			userContext.IsLoggedIn = true;

			ApplicationSettings applicationSettings = new ApplicationSettings();
			applicationSettings.Installed = true;
			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(applicationSettings, cache);

			MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
			MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

			// Act
			string actualHtml = parser.GetMenu();

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml);
		}
Beispiel #3
0
 public MenuParser(MarkupConverter markupConverter, IRepository repository, SiteCache siteCache, IUserContext userContext)
 {
     _markupConverter = markupConverter;
     _repository = repository;
     _siteCache = siteCache;
     _userContext = userContext;
 }
Beispiel #4
0
		public MenuParser(MarkupConverter markupConverter, ISettingsRepository settingsRepository, SiteCache siteCache, IUserContext userContext)
		{
			_markupConverter = markupConverter;
			_settingsRepository = settingsRepository;
			_siteCache = siteCache;
			_userContext = userContext;
		}
        /// <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();
        }
Beispiel #6
0
 internal TextPluginStub(IRepository repository, SiteCache siteCache)
     : base(repository, siteCache)
 {
     _id = "Amazing plugin";
     _name = "An amazing plugin";
     _description = "Amazing stubbed plugin";
 }
		public void Setup()
		{
			// Setup the repository
			Repository = GetRepository();
			Clearup();

			_siteCache = new SiteCache(CacheMock.RoadkillCache);
		}
		public SettingsController(ApplicationSettings settings, UserServiceBase userManager, SettingsService settingsService, 
			IUserContext context, SiteCache siteCache, ConfigReaderWriter configReaderWriter)
			: base(settings, userManager, context, settingsService) 
		{
			_settingsService = settingsService;
			_siteCache = siteCache;
			_configReaderWriter = configReaderWriter;
		}
Beispiel #9
0
		public CacheController(ApplicationSettings settings, UserServiceBase userService,
			SettingsService settingsService, IUserContext context,
			ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache siteCache)
			: base(settings, userService, context, settingsService) 
		{
			_listCache = listCache;
			_pageViewModelCache = pageViewModelCache;
			_siteCache = siteCache;
		}
		public PluginSettingsController(ApplicationSettings settings, UserServiceBase userService, IUserContext context, 
			SettingsService settingsService, IPluginFactory pluginFactory, IRepository repository, SiteCache siteCache, 
			PageViewModelCache viewModelCache, ListCache listCache)
			: base (settings, userService, context, settingsService)
		{
			_pluginFactory = pluginFactory;
			_repository = repository;
			_siteCache = siteCache;
			_viewModelCache = viewModelCache;
			_listCache = listCache;
		}
Beispiel #11
0
 public RelService(ApplicationSettings settings, IRepository repository, SearchService searchService,
     PageHistoryService historyService, IUserContext context,
     ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory)
     : base(settings, repository)
 {
     _searchService = searchService;
     _markupConverter = new MarkupConverter(settings, repository, pluginFactory);
     _historyService = historyService;
     _context = context;
     _listCache = listCache;
     _pageViewModelCache = pageViewModelCache;
     _siteCache = sitecache;
     _pluginFactory = pluginFactory;
 }
Beispiel #12
0
		public void addloggedinmenu_should_cache_html()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(cache);

			// Act
			siteCache.AddLoggedInMenu("some html");

			// Assert
			Assert.That(cache.Count(), Is.EqualTo(1));
			IEnumerable<string> keys = cache.Select(x => x.Key);
			Assert.That(keys, Contains.Item(CacheKeys.LoggedInMenuKey()));
		}
Beispiel #13
0
		public void getmenu_should_return_correct_html()
		{
			// Arrange
			string expectedHtml = "some html";

			CacheMock cache = new CacheMock();
			SiteCache siteCache = new SiteCache(cache);
			siteCache.AddMenu(expectedHtml);

			// Act
			string actualHtml = siteCache.GetMenu();

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml));
		}
Beispiel #14
0
        public void AddMenu_Should_Cache_Html()
        {
            // Arrange
            CacheMock cache = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings();
            SiteCache siteCache = new SiteCache(settings, cache);

            // Act
            siteCache.AddMenu("some html");

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
            IEnumerable<string> keys = cache.Select(x => x.Key);
            Assert.That(keys, Contains.Item(CacheKeys.MenuKey()));
        }
Beispiel #15
0
        public void GetAdminMenu_Should_Return_Correct_Html()
        {
            // Arrange
            string expectedHtml = "some html";

            CacheMock cache = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings();
            SiteCache siteCache = new SiteCache(settings, cache);
            siteCache.AddAdminMenu(expectedHtml);

            // Act
            string actualHtml = siteCache.GetAdminMenu();

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
		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;
		}
Beispiel #17
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();
			_container.ClearCache();

			_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;

			_cacheController = new CacheController(_applicationSettings, _userService, _settingsService, _context, _listCache, _pageCache, _siteCache);
		}
Beispiel #18
0
		public PageService(ApplicationSettings settings, ISettingsRepository settingsRepository, IPageRepository pageRepository, SearchService searchService, 
			PageHistoryService historyService, IUserContext context, 
			ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory)
		{
			_searchService = searchService;
			_markupConverter = new MarkupConverter(settings, settingsRepository, pageRepository, pluginFactory);
			_historyService = historyService;
			_context = context;
			_listCache = listCache;
			_pageViewModelCache = pageViewModelCache;
			_siteCache = sitecache;
			_pluginFactory = pluginFactory;
			_markupLinkUpdater = new MarkupLinkUpdater(_markupConverter.Parser);

			ApplicationSettings = settings;
			SettingsRepository = settingsRepository;
			PageRepository = pageRepository;
		}
		public void Setup()
		{
			_container = new MocksAndStubsContainer();
			_container.ClearCache();

			_applicationSettings = _container.ApplicationSettings;
			_applicationSettings.AttachmentsFolder = AppDomain.CurrentDomain.BaseDirectory;
			_context = _container.UserContext;
			_settingsRepository = _container.SettingsRepository;
			_settingsService = _container.SettingsService;
			_userService = _container.UserService;
			_pageCache = _container.PageViewModelCache;
			_listCache = _container.ListCache;
			_siteCache = _container.SiteCache;
			_cache = _container.MemoryCache;
			_configReaderWriter = new ConfigReaderWriterStub();

			_settingsController = new SettingsController(_applicationSettings, _userService, _settingsService, _context, _siteCache, _configReaderWriter);
		}
		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);
		}
Beispiel #21
0
		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);
		}
		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;
			_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();
		}
Beispiel #24
0
        public void Should_Cache_Menu_Html_For_Admin_And_Editor_And_Guest_User()
        {
            // Arrange
            string menuMarkup = "My menu %newpage% %sitesettings%";

            RepositoryMock repository = new RepositoryMock();
            repository.SiteSettings = new SiteSettings();
            repository.SiteSettings.MarkupType = "Markdown";
            repository.SiteSettings.MenuMarkup = menuMarkup;

            UserContextStub userContext = new UserContextStub();
            ApplicationSettings applicationSettings = new ApplicationSettings();
            applicationSettings.Installed = true;

            CacheMock cache = new CacheMock();
            SiteCache siteCache = new SiteCache(applicationSettings, cache);

            MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
            MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);

            // Act
            userContext.IsLoggedIn = false;
            userContext.IsAdmin = false;
            parser.GetMenu();

            userContext.IsLoggedIn = true;
            userContext.IsAdmin = false;
            parser.GetMenu();

            userContext.IsLoggedIn = true;
            userContext.IsAdmin = true;
            parser.GetMenu();

            // Assert
            Assert.That(cache.CacheItems.Count, Is.EqualTo(3));
        }
		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;
        }
Beispiel #27
0
        public void UpdatePluginSettings_Should_Add_Plugin_Settings_ToCache()
        {
            // Arrange
            CacheMock cache = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings();
            SiteCache siteCache = new SiteCache(settings, cache);

            TextPluginStub plugin = new TextPluginStub();
            plugin.PluginCache = siteCache;
            plugin.Repository = new RepositoryMock();
            plugin.Settings.SetValue("foo", "bar");

            // Act
            siteCache.UpdatePluginSettings(plugin);

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Beispiel #28
0
		internal TextPlugin(ISettingsRepository repository, SiteCache siteCache) : this()
		{
			Repository = repository;
			PluginCache = siteCache;
		}
Beispiel #29
0
		public void Should_Export_SiteConfiguration_And_Plugin_Settings()
		{
			// Arrange
			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings.PluginLastSaveDate = new DateTime(2013, 11, 09, 0, 0, 0);
			repository.SiteSettings.AllowedFileTypes = ".exe,.vbscript";
			repository.SiteSettings.MenuMarkup = "markup ```''' \r\n";
			
			// Plugins setup
			SiteCache siteCache = new SiteCache(new ApplicationSettings(), new CacheMock());

			TextPluginStub plugin1 = new TextPluginStub("fake-plugin1", "fake plugin1", "description 1", "1.1");
			plugin1.PluginCache = siteCache;
			plugin1.Repository = repository;
			plugin1.Settings.IsEnabled = true;
			plugin1.Settings.SetValue("key1", "value1");
			plugin1.Settings.SetValue("key2", "value2");

			TextPluginStub plugin2 = new TextPluginStub("fake-plugin2", "fake plugin2", "description 2", "2.1");
			plugin2.PluginCache = siteCache;
			plugin2.Repository = repository;

			PluginFactoryMock pluginFactory = new PluginFactoryMock();
			pluginFactory.TextPlugins.Add(plugin1);
			pluginFactory.TextPlugins.Add(plugin2);

			// SqlExportBuilder
			SqlExportBuilder builder = new SqlExportBuilder(repository, pluginFactory);
			builder.IncludeConfiguration = true;
			builder.IncludePages = false;

			string expectedSql = ReadEmbeddedResource("expected-siteconfiguration-export.sql");
			expectedSql = expectedSql.Replace("{AppVersion}", ApplicationSettings.ProductVersion);

			// Act
			string actualSql = builder.Export();

			// Assert
			Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql);
		}
 public void Setup()
 {
     _siteCache = new SiteCache(ApplicationSettings, CacheMock.RoadkillCache);
 }