예제 #1
0
        public void AllPagesCreatedBy_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            string adminCacheKey = CacheKeys.AllPagesCreatedByKey("admin");

            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Title = "1"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Title = "2"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Title = "3"
            }, "text", "editor", DateTime.UtcNow);

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

            // Act
            pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(adminCacheKey));
        }
예제 #2
0
        public void FindByTag_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            string cacheKey = CacheKeys.PagesByTagKey("tag1");

            RepositoryMock repository = new RepositoryMock();

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

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

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

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(cacheKey));
        }
예제 #3
0
        public void AllPages_Should_Add_To_Cache_When_Cache_Is_Empty(bool loadPageContent)
        {
            // Arrange
            string cacheKey = (loadPageContent) ? (CacheKeys.AllPagesWithContent()) : (CacheKeys.AllPages());

            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Title = "1"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Title = "2"
            }, "text", "admin", DateTime.UtcNow);

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

            // Act
            pageService.AllPages(loadPageContent);

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(cacheKey));
        }
예제 #4
0
        public void DeletePage_Should_Clear_List_And_PageSummary_Caches()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page(), "text", "admin", DateTime.UtcNow);
            CacheMock pageCache = new CacheMock();
            CacheMock listCache = new CacheMock();

            PageService   pageService   = CreatePageService(pageCache, listCache, repository);
            PageViewModel expectedModel = CreatePageViewModel();

            AddPageCacheItem(pageCache, "key", expectedModel);
            AddListCacheItem(listCache, "key", new List <string>()
            {
                "tag1", "tag2"
            });

            // Act
            pageService.DeletePage(1);

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(0));
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
예제 #5
0
        public void UpdatePage_Should_Remove_Homepage_From_Cache_When_Homepage_Is_Updated()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Tags = "homepage"
            }, "text", "admin", DateTime.UtcNow);

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

            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));
        }
예제 #6
0
        public void RenameTag_Should_Clear_ListCache()
        {
            // Arrange
            string         tag1CacheKey = CacheKeys.PagesByTagKey("tag1");
            RepositoryMock repository   = new RepositoryMock();

            repository.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, repository);

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

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
예제 #7
0
        public void Put_Should_Update_Page()
        {
            // Arrange
            DateTime version1Date = DateTime.Today.AddDays(-1);             // stops the getlatestcontent acting up when add+update are the same time

            Page page = new Page();

            page.Title      = "Hello world";
            page.Tags       = "tag1, tag2";
            page.CreatedOn  = version1Date;
            page.ModifiedOn = version1Date;
            PageContent pageContent = _repositoryMock.AddNewPage(page, "Some content1", "editor", version1Date);

            PageViewModel model = new PageViewModel(pageContent.Page);

            model.Title      = "New title";
            model.Content    = "Some content2";
            model.ModifiedOn = DateTime.UtcNow;

            // Act
            _pagesController.Put(model);

            // Assert
            Assert.That(_pageService.AllPages().Count(), Is.EqualTo(1));

            PageViewModel actualPage = _pageService.GetById(1, true);

            Assert.That(actualPage.Title, Is.EqualTo("New title"));
            Assert.That(actualPage.Content, Is.EqualTo("Some content2"));
        }
예제 #8
0
        public void AllPagesCreatedBy_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            string adminCacheKey = CacheKeys.AllPagesCreatedByKey("admin");

            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Title = "1" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "2" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "3" }, "text", "editor", DateTime.UtcNow);

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

            // Act
            pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(adminCacheKey));
        }
예제 #9
0
        public void UpdatePage_Should_Clear_List_Cache_And_PageSummary_Cache()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Tags = "homepage"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Tags = "tag2"
            }, "text", "admin", DateTime.UtcNow);

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

            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));
        }
예제 #10
0
        public void AllTags_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Tags = "tag1;tag2"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Tags = "tag3;tag4"
            }, "text", "admin", DateTime.UtcNow);

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

            // Act
            pageService.AllTags();

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(CacheKeys.AllTags()));
        }
예제 #11
0
        public void FindHomePage_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Title = "1", Tags = "homepage"
            }, "text", "admin", DateTime.UtcNow);

            CacheMock   pageCache   = new CacheMock();
            PageService pageService = CreatePageService(pageCache, null, repository);

            // Act
            pageService.FindHomePage();

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(pageCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(CacheKeys.HomepageKey()));
        }
예제 #12
0
        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);
        }
예제 #13
0
        public void ExportAsXml_Should_Return_Non_Empty_Stream()
        {
            // Arrange
            _repository.AddNewPage(new Page()
            {
                Id = 1
            }, "text", "admin", DateTime.UtcNow);
            _repository.AddNewPage(new Page()
            {
                Id = 2
            }, "text", "admin", DateTime.UtcNow);

            // Act
            Stream stream = _wikiExporter.ExportAsXml();

            // Assert
            Assert.That(stream.Length, Is.GreaterThan(1));
        }
예제 #14
0
        public void AllTags_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Tags = "tag1;tag2" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Tags = "tag3;tag4" }, "text", "admin", DateTime.UtcNow);

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

            // Act
            pageService.AllTags();

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(CacheKeys.AllTags()));
        }
예제 #15
0
        public void FindByTag_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            string cacheKey = CacheKeys.PagesByTagKey("tag1");

            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Title = "1", Tags = "tag1" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "2", Tags = "tag2" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "2", Tags = "tag3" }, "text", "admin", DateTime.UtcNow);

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

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

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(cacheKey));
        }
예제 #16
0
        public void DeletePage_Should_Clear_List_And_PageSummary_Caches()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page(), "text", "admin", DateTime.UtcNow);
            CacheMock pageCache = new CacheMock();
            CacheMock listCache = new CacheMock();

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

            // Act
            pageService.DeletePage(1);

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(0));
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
예제 #17
0
        public void FindHomePage_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Title = "1", Tags= "homepage" }, "text", "admin", DateTime.UtcNow);

            CacheMock pageCache = new CacheMock();
            PageService pageService = CreatePageService(pageCache, null, repository);

            // Act
            pageService.FindHomePage();

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(pageCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(CacheKeys.HomepageKey()));
        }
예제 #18
0
        public void RenameTag_Should_Clear_ListCache()
        {
            // Arrange
            string tag1CacheKey = CacheKeys.PagesByTagKey("tag1");
            RepositoryMock repository = new RepositoryMock();
            repository.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, repository);

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

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
예제 #19
0
        public void UpdatePage_Should_Clear_List_Cache_And_PageSummary_Cache()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Tags = "homepage" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Tags = "tag2" }, "text", "admin", DateTime.UtcNow);

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

            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));
        }
예제 #20
0
        public void UpdatePage_Should_Remove_Homepage_From_Cache_When_Homepage_Is_Updated()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Tags = "homepage" }, "text", "admin", DateTime.UtcNow);

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

            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));
        }
예제 #21
0
        public void AllPages_Should_Add_To_Cache_When_Cache_Is_Empty(bool loadPageContent)
        {
            // Arrange
            string cacheKey = (loadPageContent) ? (CacheKeys.AllPagesWithContent()) : (CacheKeys.AllPages());

            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Title = "1" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "2" }, "text", "admin", DateTime.UtcNow);

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

            // Act
            pageService.AllPages(loadPageContent);

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