Exemplo n.º 1
1
		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);
		}
Exemplo n.º 2
0
		public void internal_links_should_resolve_with_id()
		{
			// Bug #87

			// Arrange
			Page page = new Page() { Id = 1, Title = "My first page" };

			var settingsRepository = new SettingsRepositoryMock();
			settingsRepository.SiteSettings = new SiteSettings() { MarkupType = "Markdown" };

			PageRepositoryMock pageRepositoryStub = new PageRepositoryMock();
			pageRepositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow);

			ApplicationSettings settings = new ApplicationSettings();
			settings.Installed = true;

			UrlResolverMock resolver = new UrlResolverMock();
			resolver.InternalUrl = "blah";
			MarkupConverter converter = new MarkupConverter(settings, settingsRepository, pageRepositoryStub, _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));
		}
Exemplo n.º 3
0
		public void code_blocks_should_allow_quotes()
		{
			// Issue #82
			// Arrange
			Page page = new Page() { Id = 1, Title = "My first page" };

			PageRepositoryMock pageRepositoryStub = new PageRepositoryMock();
			pageRepositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow);

			var settingsRepository = new SettingsRepositoryMock();
			settingsRepository.SiteSettings = new SiteSettings() { MarkupType = "Markdown" };

			ApplicationSettings settings = new ApplicationSettings();
			settings.Installed = true;

			MarkupConverter converter = new MarkupConverter(settings, settingsRepository, pageRepositoryStub, _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 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);
		}
Exemplo n.º 5
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_pageRepositoryMock = _container.PageRepository;
			_pageService = _container.PageService;

			_pagesController = new PagesController(_pageService);
		}
Exemplo n.º 6
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_siteSettings = _container.SettingsService.GetSiteSettings();

			_pluginFactory = _container.PluginFactory;
			_pageRepository = _container.PageRepository;
		}
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;
			_pageRepository = _container.PageRepository;
			_userService = _container.UserService;

			_userService.Users.Add(new User() { Email = "*****@*****.**" });
			_userViewModel = new UserViewModel(_applicationSettings, _userService);
		}
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_container.SettingsRepository.SiteSettings.PluginLastSaveDate = _pluginLastSavedDate;

			_pluginFactory = _container.PluginFactory;
			_settingsRepository = _container.SettingsRepository;
			_pageRepository = _container.PageRepository;

			_settingsService = _container.SettingsService;
		}
Exemplo n.º 9
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_pluginFactory = _container.PluginFactory;
			_appSettings = _container.ApplicationSettings;
			_appSettings.Installed = true;
			_pageRepository = _container.PageRepository;
			_settingsRepository = _container.SettingsRepository;
			_markupConverter = _container.MarkupConverter;
			_markupConverter.UrlResolver = new UrlResolverMock();
		}
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;
			_pageRepository = _container.PageRepository;
			_pluginFactory = _container.PluginFactory;
			_settingsService = _container.SettingsService;
			_userService = _container.UserService;

			_specialPagesController = new SpecialPagesController(_applicationSettings, _userService, _context, _settingsService, _pluginFactory);
		}
Exemplo n.º 11
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_applicationSettings.UseHtmlWhiteList = true;
			_applicationSettings.CustomTokensPath = Path.Combine(TestConstants.WEB_PATH, "App_Data", "customvariables.xml");

			_settingsRepository = _container.SettingsRepository;
			_pageRepository = _container.PageRepository;

			_pluginFactory = _container.PluginFactory;
			_markupConverter = _container.MarkupConverter;
			_markupConverter.UrlResolver = new UrlResolverMock();
		}
Exemplo n.º 12
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();
			_applicationSettings = _container.ApplicationSettings;

			_settingsRepository = _container.SettingsRepository;
			_pageRepository = _container.PageRepository;
			_userRepository = _container.UserRepository;

			_pageService = _container.PageService;
			_pluginFactory = _container.PluginFactory;

			_wikiExporter = new WikiExporter(_applicationSettings, _pageService, _settingsRepository, _pageRepository, _userRepository, _pluginFactory);
			_wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory;
		}
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;

			_pageRepository = _container.PageRepository;
			_userRepository = _container.UserRepository;

			_settingsService = _container.SettingsService;
			_userService = _container.UserService;

			_controller = new UserManagementController(_applicationSettings, _userService, _settingsService, _context);
		}
Exemplo n.º 14
0
		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();
		}
Exemplo n.º 15
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();
			_container.ClearCache();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;
			_pageRepository = _container.PageRepository;
			_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);
		}
Exemplo n.º 16
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;	
			_pageRepository = _container.PageRepository;
			_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();
		}
Exemplo n.º 17
0
		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();
		}
Exemplo n.º 18
0
		public void getbyid_should_load_from_cache_when_pagesummary_exists_in_cache()
		{
			// Arrange
			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			CacheMock pageModelCache = new CacheMock();
			PageService pageService = CreatePageService(pageModelCache, null, settingsRepository, pageRepository);

			PageViewModel expectedModel = CreatePageViewModel();
			string cacheKey = CacheKeys.PageViewModelKey(1, PageViewModelCache.LATEST_VERSION_NUMBER);
			pageModelCache.Add(cacheKey, expectedModel, new CacheItemPolicy());

			// Act
			PageViewModel actualModel = pageService.GetById(1);

			// Assert
			Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
			Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
			Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
		}
Exemplo n.º 19
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);
		}
Exemplo n.º 20
0
		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;
			_pageRepository = _container.PageRepository;
			_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();
		}
Exemplo n.º 22
0
		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();
		}
Exemplo n.º 23
0
		public void getbyid_should_add_to_cache_when_pagesummary_does_not_exist_in_cache()
		{
			// Arrange
			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			CacheMock pageModelCache = new CacheMock();
			PageService pageService = CreatePageService(pageModelCache, null, settingsRepository, pageRepository);

			PageViewModel expectedModel = CreatePageViewModel();
			expectedModel = pageService.AddPage(expectedModel); // get it back to update the version no.

			// Act
			pageService.GetById(1);

			// Assert
			CacheItem cacheItem = pageModelCache.CacheItems.First();
			string cacheKey = CacheKeys.PageViewModelKey(1, PageViewModelCache.LATEST_VERSION_NUMBER);
			Assert.That(cacheItem.Key, Is.EqualTo(cacheKey));

			PageViewModel actualModel = (PageViewModel)cacheItem.Value;
			Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
			Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
			Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
		}
		public void Setup()
		{
			_container = new MocksAndStubsContainer(true);

			_applicationSettings = _container.ApplicationSettings;
			_applicationSettings.UseObjectCache = true;
			_context = _container.UserContext;

			_settingsRepository = _container.SettingsRepository;
			_pageRepository = _container.PageRepository;

			_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, _settingsRepository, _siteCache, _pageViewModelCache, _listCache);
		}
Exemplo n.º 25
0
 public RepositoryFactoryMock()
 {
     PageRepository      = new PageRepositoryMock();
     InstallerRepository = new InstallerRepositoryMock();
 }
Exemplo n.º 26
0
		public void addpage_should_clear_list_and_pagesummary_caches()
		{
			// Arrange
			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			CacheMock pageModelCache = new CacheMock();
			CacheMock listCache = new CacheMock();

			PageService pageService = CreatePageService(pageModelCache, listCache, settingsRepository, pageRepository);
			PageViewModel expectedModel = CreatePageViewModel();
			AddPageCacheItem(pageModelCache, "key", expectedModel);
			AddListCacheItem(listCache, "key", new List<string>() { "tag1", "tag2" });

			// Act
			pageService.AddPage(new PageViewModel() { Title = "totoro" });

			// Assert
			Assert.That(pageModelCache.CacheItems.Count, Is.EqualTo(0));
			Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
		}
Exemplo n.º 27
0
		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;
		}
Exemplo n.º 28
0
		public void renametag_should_clear_listcache()
		{
			// Arrange
			string tag1CacheKey = CacheKeys.PagesByTagKey("tag1");
			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			pageRepository.AddNewPage(new Page() { Tags = "homepage, tag1" }, "text1", "admin", DateTime.UtcNow);

			CacheMock listCache = new CacheMock();
			PageViewModel homepageModel = CreatePageViewModel();
			PageViewModel page1Model = CreatePageViewModel();
			AddListCacheItem(listCache, tag1CacheKey, new List<PageViewModel>() { homepageModel, page1Model });

			PageService pageService = CreatePageService(null, listCache, settingsRepository, pageRepository);

			// Act
			pageService.RenameTag("tag1", "some.other.tag"); // calls UpdatePage, which clears the cache

			// Assert
			Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
		}
Exemplo n.º 29
0
		public void updatepage_should_remove_homepage_from_cache_when_homepage_is_updated()
		{
			// Arrange
			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			pageRepository.AddNewPage(new Page() { Tags = "homepage" }, "text", "admin", DateTime.UtcNow);

			CacheMock pageCache = new CacheMock();
			CacheMock listCache = new CacheMock();
			PageService pageService = CreatePageService(pageCache, listCache, settingsRepository, pageRepository);

			PageViewModel homepageModel = CreatePageViewModel();
			homepageModel.RawTags = "homepage";
			pageCache.Add(CacheKeys.HomepageKey(), homepageModel, new CacheItemPolicy());

			// Act
			pageService.UpdatePage(homepageModel);

			// Assert
			Assert.That(pageCache.CacheItems.Count, Is.EqualTo(0));
		}
Exemplo n.º 30
0
		public void updatepage_should_clear_list_cache_and_pagesummary_cache()
		{
			// Arrange
			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			pageRepository.AddNewPage(new Page() { Tags = "homepage" }, "text", "admin", DateTime.UtcNow);
			pageRepository.AddNewPage(new Page() { Tags = "tag2" }, "text", "admin", DateTime.UtcNow);

			CacheMock pageCache = new CacheMock();
			CacheMock listCache = new CacheMock();
			PageService pageService = CreatePageService(pageCache, listCache, settingsRepository, pageRepository);

			PageViewModel homepageModel = CreatePageViewModel();
			homepageModel.Id = 1;
			PageViewModel page2Model = CreatePageViewModel();
			page2Model.Id = 2;

			AddPageCacheItem(pageCache, CacheKeys.HomepageKey(), homepageModel);
			pageCache.Add(CacheKeys.PageViewModelKey(2, 0), page2Model, new CacheItemPolicy());
			AddListCacheItem(listCache, CacheKeys.AllTags(), new List<string>() { "tag1", "tag2" });

			// Act
			pageService.UpdatePage(page2Model);

			// Assert
			Assert.That(pageCache.CacheItems.Count, Is.EqualTo(1));
			Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
		}
Exemplo n.º 31
0
		public void findbytag_should_add_to_cache_when_cache_is_empty()
		{
			// Arrange
			string cacheKey = CacheKeys.PagesByTagKey("tag1");

			SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
			PageRepositoryMock pageRepository = new PageRepositoryMock();
			pageRepository.AddNewPage(new Page() { Title = "1", Tags = "tag1" }, "text", "admin", DateTime.UtcNow);
			pageRepository.AddNewPage(new Page() { Title = "2", Tags = "tag2" }, "text", "admin", DateTime.UtcNow);
			pageRepository.AddNewPage(new Page() { Title = "2", Tags = "tag3" }, "text", "admin", DateTime.UtcNow);

			CacheMock listCache = new CacheMock();
			PageService pageService = CreatePageService(null, listCache, settingsRepository, pageRepository);

			// Act
			pageService.FindByTag("tag1");

			// Assert
			Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
			Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(cacheKey));
		}