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); }
/// <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 void Setup() { // WikiController setup (use WikiController as it's the one typically used by views) _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; _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); }
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 void Should_Remove_Empty_UL_Tags_For_Logged_In_Tokens_When_Not_Logged_In(string markupType, string expectedHtml) { // Arrange - \r\n is important so the markdown is valid string menuMarkup = "%mainpage%\r\n\r\n* %newpage%\r\n* %managefiles%\r\n* %sitesettings%\r\n"; RepositoryMock repository = new RepositoryMock(); repository.SiteSettings = new SiteSettings(); repository.SiteSettings.MarkupType = markupType; repository.SiteSettings.MenuMarkup = menuMarkup; UserContextStub userContext = new UserContextStub(); userContext.IsLoggedIn = false; 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)); }
public void Internal_Links_Should_Resolve_With_Id() { // Bug #87 // Arrange Page page = new Page() { Id = 1, Title = "My first page"}; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; UrlResolverMock resolver = new UrlResolverMock(); resolver.InternalUrl = "blah"; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); converter.UrlResolver = resolver; string markdownText = "[Link](My-first-page)"; string invalidMarkdownText = "[Link](My first page)"; // Act string expectedHtml = "<p><a href=\"blah\">Link</a></p>\n"; string expectedInvalidLinkHtml = "<p>[Link](My first page)</p>\n"; string actualHtml = converter.ToHtml(markdownText); string actualHtmlInvalidLink = converter.ToHtml(invalidMarkdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); Assert.That(actualHtmlInvalidLink, Is.EqualTo(expectedInvalidLinkHtml)); }
public void Code_Blocks_Should_Allow_Quotes() { // Issue #82 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is some `// code with a 'quote' in it and another \"quote\"`\n\n" + " var x = \"some tabbed code\";\n\n"; // 2 line breaks followed by 4 spaces (tab stop) at the start indicates a code block string expectedHtml = "<p>Here is some <code>// code with a 'quote' in it and another \"quote\"</code></p>\n\n" + "<pre><code>var x = \"some tabbed code\";\n" + "</code></pre>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Images_Should_Support_Dimensions() { // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is an image:![Image](/Image1.png) \n\n" + "And another with equal dimensions ![Square](/Image1.png =250x) \n\n" + "And this one is a rectangle ![Rectangle](/Image1.png =250x350)"; string expectedHtml = "<p>Here is an image:<img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" /> </p>\n\n" + "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" /> </p>\n\n" + "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" /></p>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
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; _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 it // a lot of usefulness of these tests would be lost when creating fake Streams and zip files. _wikiExporter = new WikiExporter(_applicationSettings, _pageService, _repository, _pluginFactory); _wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory; _toolsController = new ToolsController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _context, _listCache, _pageCache, _wikiImporter, _repository, _pluginFactory, _wikiExporter); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _repository = _container.Repository; _settingsService = _container.SettingsService; }
public void Setup() { _container = new MocksAndStubsContainer(); _pluginFactory = _container.PluginFactory; _appSettings = _container.ApplicationSettings; _appSettings.Installed = true; _repository = _container.Repository; _markupConverter = _container.MarkupConverter; _markupConverter.UrlResolver = new UrlResolverMock(); }
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 void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _userService = _container.UserService; _userService.Users.Add(new User() { Email = "*****@*****.**" }); _userViewModel = new UserViewModel(_applicationSettings, _userService); }
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 void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.UseHtmlWhiteList = true; _applicationSettings.CustomTokensPath = Path.Combine(Settings.WEB_PATH, "App_Data", "customvariables.xml"); _pluginFactory = _container.PluginFactory; _repository = _container.Repository; _markupConverter = _container.MarkupConverter; _markupConverter.UrlResolver = new UrlResolverMock(); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _specialPagesController = new SpecialPagesController(_applicationSettings, _userService, _context, _settingsService, _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; _wikiController = new WikiController(_applicationSettings, _userService, _pageService, _context, _settingsService); _wikiController.SetFakeControllerContext(); }
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); }
public void Setup() { _container = new MocksAndStubsContainer(); _container.ClearCache(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.AttachmentsFolder = AppDomain.CurrentDomain.BaseDirectory; _context = _container.UserContext; _repository = _container.Repository; _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(); _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; _repository = _container.Repository; _userService = _container.UserService; _historyService = _container.HistoryService; _testUser = new User(); _testUser.IsActivated = true; _testUser.Id = Guid.NewGuid(); _testUser.Email = AdminEmail; _testUser.Username = AdminUsername; _userService.Users.Add(_testUser); _context.CurrentUser = _testUser.Id.ToString(); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments"); _repository = _container.Repository; _settingsService = _container.SettingsService; _userService = _container.UserService; _userContext = _container.UserContext; _emailClientMock = _container.EmailClient; _userService.AddUser(AdminEmail, AdminUsername, AdminPassword, true, true); _userService.Users[0].IsActivated = true; _userService.Users[0].Firstname = "Firstname"; _userService.Users[0].Lastname = "LastnameNotSurname"; _userController = new UserController(_applicationSettings, _userService, _userContext, _settingsService, null, null); _mvcMockContainer = _userController.SetFakeControllerContext(); }
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() { // WikiController setup (use WikiController as it's the one typically used by views) _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _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(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 Should_Return_Different_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; string guestHtml = parser.GetMenu(); userContext.IsLoggedIn = true; userContext.IsAdmin = false; string editorHtml = parser.GetMenu(); userContext.IsLoggedIn = true; userContext.IsAdmin = true; string adminHtml = parser.GetMenu(); // Assert Assert.That(guestHtml, Is.EqualTo("My menu")); Assert.That(editorHtml, Is.EqualTo("My menu <a href=\"/pages/new\">New page</a>")); Assert.That(adminHtml, Is.EqualTo("My menu <a href=\"/pages/new\">New page</a> <a href=\"/settings\">Site settings</a>")); }
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; _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; _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 Images_Should_Support_Dimensions_And_Titles() { // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is an image with a title:![Image](/Image1.png \"Image\") \n\n" + "And another with equal dimensions ![Square](/Image1.png \"Square\" =250x) \n\n" + "And this one is a rectangle ![Rectangle](/Image1.png \"Rectangle\" =250x350)"; string expectedHtml = "<p>Here is an image with a title:<img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" title=\"Image\" /> </p>\n\n" + "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" title=\"Square\" /> </p>\n\n" + "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" title=\"Rectangle\" /></p>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
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)); }
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; _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"); // 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(); // Other services FileService = new FileServiceMock(); }
public void Should_Replace_Known_Tokens_When_Logged_In_As_Admin() { // 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>" + "<a href=\"/settings\">Site settings</a>"; RepositoryMock repository = new RepositoryMock(); repository.SiteSettings = new SiteSettings(); repository.SiteSettings.MarkupType = "Markdown"; repository.SiteSettings.MenuMarkup = menuMarkup; UserContextStub userContext = new UserContextStub(); userContext.IsAdmin = true; 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); }
public void Edit_GET_Should_Load_Settings_From_Repository() { // Arrange TextPluginStub plugin = new TextPluginStub(); plugin.Repository = _repository; plugin.PluginCache = _siteCache; plugin.Settings.SetValue("name1", "default-value1"); plugin.Settings.SetValue("name2", "default-value2"); RepositoryMock repositoryMock = new RepositoryMock(); repositoryMock.SaveTextPluginSettings(plugin); repositoryMock.TextPlugins[0].Settings.SetValue("name1", "value1"); repositoryMock.TextPlugins[0].Settings.SetValue("name2", "value2"); _pluginFactory.RegisterTextPlugin(plugin); // Act ViewResult result = _controller.Edit(plugin.Id) as ViewResult; // Assert PluginViewModel model = result.ModelFromActionResult<PluginViewModel>(); Assert.That(model.SettingValues[0].Value, Is.EqualTo("value1")); Assert.That(model.SettingValues[1].Value, Is.EqualTo("value2")); }
public void Should_Export_Users_With_All_FieldValues() { // Arrange RepositoryMock repository = new RepositoryMock(); repository.SiteSettings.PluginLastSaveDate = DateTime.Today; Guid user1Id = new Guid("29a8ad19-b203-46f5-be10-11e0ebf6f812"); Guid user2Id = new Guid("e63b0023-329a-49b9-97a4-5094a0e378a2"); Guid user3Id = new Guid("a6ee19ef-c093-47de-97d2-83dec406d92d"); Guid user1Activationkey = new Guid("0953cf95-f357-4e5b-ae2b-7541844d3b6b"); Guid user2Activationkey = new Guid("aa87fe31-9781-4c93-b7e3-9092ed095810"); Guid user3Activationkey = new Guid("b8ef994d-87f5-4543-85de-66b41244a20a"); User user1 = new User() { Id = user1Id, ActivationKey = user1Activationkey.ToString(), Firstname = "firstname1", Lastname = "lastname1", Email = "user1@localhost", Password = "******", Salt = "salt1", IsActivated = true, IsAdmin = true, Username = "******" }; User user2 = new User() { Id = user2Id, ActivationKey = user2Activationkey.ToString(), Firstname = "firstname2", Lastname = "lastname2", Email = "user2@localhost", Password = "******", Salt = "salt2", IsActivated = true, IsEditor = true, Username = "******" }; User user3 = new User() { Id = user3Id, ActivationKey = user3Activationkey.ToString(), Firstname = "firstname3", Lastname = "lastname3", Email = "user3@localhost", Password = "******", Salt = "salt3", IsActivated = false, IsEditor = true, Username = "******" }; repository.Users.Add(user1); repository.Users.Add(user2); repository.Users.Add(user3); SqlExportBuilder builder = new SqlExportBuilder(repository, new PluginFactoryMock()); builder.IncludeConfiguration = false; builder.IncludePages = false; string expectedSql = ReadEmbeddedResource("expected-users-export.sql"); // Act string actualSql = builder.Export(); // Assert Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql); }
public void Should_Export_Pages_With_Content() { // Arrange RepositoryMock repository = new RepositoryMock(); repository.SiteSettings.PluginLastSaveDate = DateTime.Today; DateTime page1CreatedOn = new DateTime(2013, 01, 01, 12, 00, 00); DateTime page1ModifiedOn = new DateTime(2013, 01, 01, 13, 00, 00); DateTime page2CreatedOn = new DateTime(2013, 01, 02, 12, 00, 00); DateTime page2ModifiedOn = new DateTime(2013, 01, 02, 13, 00, 00); DateTime page3CreatedOn = new DateTime(2013, 01, 03, 12, 00, 00); DateTime page3ModifiedOn = new DateTime(2013, 01, 03, 13, 00, 00); Guid page1ContentId = new Guid("13a8ad19-b203-46f5-be10-11e0ebf6f812"); Guid page2ContentId = new Guid("143b0023-329a-49b9-97a4-5094a0e378a2"); Guid page3ContentId = new Guid("15ee19ef-c093-47de-97d2-83dec406d92d"); string page1Text = @"the text ;''' "" more text """ ; string page2Text = @"the text ;''' #### sdfsdfsdf #### "" blah text """ ; string page3Text = @"the text ;''' #### dddd **dddd** #### "" pppp text """ ; Page page1 = new Page() { CreatedBy = "created-by-user1", CreatedOn = page1CreatedOn, Id = 1, IsLocked = true, ModifiedBy = "modified-by-user2", ModifiedOn = page1ModifiedOn, Tags = "tag1,tag2,tag3", Title = "Page 1 title" }; Page page2 = new Page() { CreatedBy = "created-by-user2", CreatedOn = page2CreatedOn, Id = 2, IsLocked = true, ModifiedBy = "modified-by-user2", ModifiedOn = page2ModifiedOn, Tags = "tagA,tagB,tagC", Title = "Page 2 title" }; Page page3 = new Page() { CreatedBy = "created-by-user3", CreatedOn = page3CreatedOn, Id = 3, IsLocked = false, ModifiedBy = "modified-by-user3", ModifiedOn = page3ModifiedOn, Tags = "tagX,tagY,tagZ", Title = "Page 3 title" }; PageContent pageContent1 = repository.AddNewPage(page1, page1Text, "modified-by-user1", page1ModifiedOn); pageContent1.Id = page1ContentId; PageContent pageContent2 = repository.AddNewPage(page2, page2Text, "modified-by-user2", page2ModifiedOn); pageContent2.Id = page2ContentId; PageContent pageContent3 = repository.AddNewPage(page3, page3Text, "modified-by-user3", page3ModifiedOn); pageContent3.Id = page3ContentId; SqlExportBuilder builder = new SqlExportBuilder(repository, new PluginFactoryMock()); builder.IncludeConfiguration = false; builder.IncludePages = true; string expectedSql = ReadEmbeddedResource("expected-pages-export.sql"); // Act string actualSql = builder.Export(); // Assert Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql); }