Пример #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));
        }