Exemplo n.º 1
0
        public void findbytag_should_load_from_cache()
        {
            string tag1CacheKey = CacheKeys.PagesByTagKey("tag1");
            string tag2CacheKey = CacheKeys.PagesByTagKey("tag2");

            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();
            CacheMock listCache = new CacheMock();

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

            tag1Model.RawTags = "tag1";
            PageViewModel tag2Model = CreatePageViewModel();

            tag2Model.RawTags = "tag2";

            listCache.Add(tag1CacheKey, new List <PageViewModel>()
            {
                tag1Model
            }, new CacheItemPolicy());
            listCache.Add(tag2CacheKey, new List <PageViewModel>()
            {
                tag2Model
            }, new CacheItemPolicy());

            // Act
            IEnumerable <PageViewModel> actualList = pageService.FindByTag("tag1");

            // Assert
            Assert.That(actualList, Contains.Item(tag1Model));
            Assert.That(actualList, Is.Not.Contains(tag2Model));
        }
Exemplo n.º 2
0
        public void allpagescreatedby_should_load_from_cache()
        {
            string adminCacheKey  = CacheKeys.AllPagesCreatedByKey("admin");
            string editorCacheKey = CacheKeys.AllPagesCreatedByKey("editor");

            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();
            CacheMock listCache = new CacheMock();

            PageService   pageService = CreatePageService(null, listCache, settingsRepository, pageRepository);
            PageViewModel adminModel  = CreatePageViewModel();
            PageViewModel editorModel = CreatePageViewModel("editor");

            listCache.Add(CacheKeys.AllPagesCreatedByKey("admin"), new List <PageViewModel>()
            {
                adminModel
            }, new CacheItemPolicy());
            listCache.Add(CacheKeys.AllPagesCreatedByKey("editor"), new List <PageViewModel>()
            {
                editorModel
            }, new CacheItemPolicy());

            // Act
            IEnumerable <PageViewModel> actualList = pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(actualList, Contains.Item(adminModel));
            Assert.That(actualList, Is.Not.Contains(editorModel));
        }
Exemplo n.º 3
0
        public void RemoveAll_Should_Remove_SiteCache_Keys_Only()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            cache.Add("list.blah", "xyz", new CacheItemPolicy());
            ApplicationSettings settings  = new ApplicationSettings();
            SiteCache           siteCache = new SiteCache(settings, cache);

            siteCache.AddMenu("menu html");
            siteCache.AddLoggedInMenu("logged in menu html");
            siteCache.AddAdminMenu("admin menu html");

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = siteCache;
            plugin.Repository  = new RepositoryMock();
            plugin.Settings.SetValue("foo", "bar");

            // Act
            siteCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Exemplo n.º 4
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.º 5
0
        public void removeall_should_remove_listcache_keys_only()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            cache.Add("site.blah", "xyz", new CacheItemPolicy());

            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        public void GetById_Should_Load_From_Cache_When_PageSummary_Exists_In_Cache()
        {
            // Arrange
            RepositoryMock repository     = new RepositoryMock();
            CacheMock      pageModelCache = new CacheMock();
            PageService    pageService    = CreatePageService(pageModelCache, null, repository);

            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.º 8
0
        public void FindHomePage_Should_Load_From_Cache()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            CacheMock      modelCache = new CacheMock();

            PageService   pageService   = CreatePageService(modelCache, null, repository);
            PageViewModel expectedModel = CreatePageViewModel();

            expectedModel.RawTags = "homepage";
            modelCache.Add(CacheKeys.HomepageKey(), expectedModel, new CacheItemPolicy());

            // Act
            PageViewModel actualModel = pageService.FindHomePage();

            // 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.º 9
0
        public void RemoveAll_Should_Remove_PageViewModelCache_Keys_Only()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            cache.Add("site.blah", "xyz", new CacheItemPolicy());

            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = false
            };
            PageViewModelCache pageCache = new PageViewModelCache(settings, cache);

            pageCache.Add(1, 1, new PageViewModel());

            // Act
            pageCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Exemplo n.º 10
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.º 11
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.º 12
0
 private void AddListCacheItem(CacheMock cache, string key, object value)
 {
     cache.Add(CacheKeys.ListCacheKey(key), value, new CacheItemPolicy());
 }
Exemplo n.º 13
0
 private void AddPageCacheItem(CacheMock cache, string key, object value)
 {
     cache.Add(CacheKeys.PAGEVIEWMODEL_CACHE_PREFIX + key, value, new CacheItemPolicy());
 }