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 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)); }
public void AddPage_Should_Clear_List_And_PageSummary_Caches() { // Arrange RepositoryMock repository = new RepositoryMock(); CacheMock pageModelCache = new CacheMock(); CacheMock listCache = new CacheMock(); PageService pageService = CreatePageService(pageModelCache, listCache, repository); 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)); }
public void GetById_Should_Add_To_Cache_When_PageSummary_Does_Not_Exist_In_Cache() { // Arrange RepositoryMock repository = new RepositoryMock(); CacheMock pageModelCache = new CacheMock(); PageService pageService = CreatePageService(pageModelCache, null, repository); 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 get_should_return_all_pages() { // Arrange _pageService.AddPage(new PageViewModel() { Id = 1, Title = "new page" }); _pageService.AddPage(new PageViewModel() { Id = 2, Title = "new page", IsLocked = true }); // Act IEnumerable <PageViewModel> pages = _pagesController.Get(); // Assert Assert.That(pages.Count(), Is.EqualTo(2)); }
public ActionResult Create([Bind(Include = "Id,Title,Author,Content,AdditionalContent,CommentsEnabled")] PageViewModels pageViewModels) { if (!ModelState.IsValid) { return(View(pageViewModels)); } _pS.AddPage(pageViewModels); return(RedirectToAction("Index")); }
public void get_should_search_return_correct_results_using_search_service() { // Arrange _pageService.AddPage(new PageViewModel() { Id = 1, Title = "title 1", Content = "page 1" }); _pageService.AddPage(new PageViewModel() { Id = 2, Title = "title 2", Content = "page 2" }); _pageService.AddPage(new PageViewModel() { Id = 3, Title = "new page 3", Content = "page 3" }); // Act IEnumerable <SearchResultViewModel> searchResults = _searchController.Get("title"); // Assert Assert.That(searchResults.Count(), Is.EqualTo(2)); }
public void AddPage_Should_Save_To_Repository_And_Set_Locked_If_User_Is_Admin() { // Arrange PageViewModel model = new PageViewModel() { Id = 1, Title = "Homepage", Content = "**Homepage**", RawTags = "1;2;3;", CreatedBy = AdminUsername, CreatedOn = DateTime.UtcNow, IsLocked = true }; // Act PageViewModel actualModel = _pageService.AddPage(model); // Assert Assert.That(actualModel, Is.Not.Null); Assert.That(actualModel.Content, Is.EqualTo(model.Content)); Assert.That(actualModel.IsLocked, Is.True); Assert.That(_repository.Pages.Count, Is.EqualTo(1)); Assert.That(_repository.PageContents.Count, Is.EqualTo(1)); }
public void pagelink_should_render_html_link_with_page_title_and_html_attributes() { // Arrange _pageService.AddPage(new PageViewModel() { Id = 7, Title = "Crispy Pancake Recipe" }); string expectedHtml = "@<a data-merry=\"xmas\" href=\"/wiki/1/crispy%20pancake%20recipe\">captains log</a>~"; // the url will always be /wiki/1 because of the mock url setup // Act string actualHtml = _htmlHelper.PageLink("captains log", "Crispy Pancake Recipe", new { data_merry = "xmas" }, "@", "~", _pageService).ToString(); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void PageLink_Should_Render_Html_Link_With_Page_Title_And_Html_Attributes() { // Arrange _pageService.AddPage(new PageViewModel() { Id = 7, Title = "Crispy Pancake Recipe" }); ObjectFactory.Configure(x => x.For <IPageService>().Use(_pageService)); // the extension uses bastard injection string expectedHtml = "@<a data-merry=\"xmas\" href=\"/wiki/1/crispy%20pancake%20recipe\">captains log</a>~"; // the url will always be /wiki/1 because of the mock url setup // Act string actualHtml = _htmlHelper.PageLink("captains log", "Crispy Pancake Recipe", new { data_merry = "xmas" }, "@", "~").ToString(); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void renderpagebytag_should_return_rendered_html_locked_page_when_multiple_pages_exist_for_tag() { // Arrange _pageService.AddPage(new PageViewModel() { Title = "Page1", RawTags = "software,tag2,tag3", IsLocked = true, Content = "page 1 content" }); _pageService.AddPage(new PageViewModel() { Title = "Page2", RawTags = "software,page2", Content = "page 2 content" }); // Act MvcHtmlString htmlString = _htmlHelper.RenderPageByTag("software"); // Assert Assert.That(htmlString.ToHtmlString(), Is.EqualTo("<p>page 1 content\n</p>")); }