public void should_getallkeys() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true }; List <string> tagCacheItems1 = new List <string>() { "1", "2" }; List <string> tagCacheItems2 = new List <string>() { "a", "b" }; ListCache listCache = new ListCache(settings, cache); // Act listCache.Add("all.tags1", tagCacheItems1); listCache.Add("all.tags2", tagCacheItems2); // Assert List <string> keys = listCache.GetAllKeys().ToList(); Assert.That(keys, Contains.Item(CacheKeys.ListCacheKey("all.tags1"))); Assert.That(keys, Contains.Item(CacheKeys.ListCacheKey("all.tags2"))); }
public void should_not_add_if_cache_disabled() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = false }; List <string> tagCacheItems = new List <string>() { "1", "2" }; ListCache listCache = new ListCache(settings, cache); // Act listCache.Add("all.tags", tagCacheItems); // Assert var tags = listCache.Get <string>("all.tags"); Assert.That(tags, Is.Null); IEnumerable <string> keys = listCache.GetAllKeys(); Assert.That(keys.Count(), Is.EqualTo(0)); }
public ActionResult Index() { CacheViewModel viewModel = new CacheViewModel() { IsCacheEnabled = ApplicationSettings.UseObjectCache, PageKeys = _pageViewModelCache.GetAllKeys(), ListKeys = _listCache.GetAllKeys(), SiteKeys = _siteCache.GetAllKeys() }; return(View(viewModel)); }
public void Should_GetAllKeys() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true }; List<string> tagCacheItems1 = new List<string>() { "1", "2" }; List<string> tagCacheItems2 = new List<string>() { "a", "b" }; ListCache listCache = new ListCache(settings, cache); // Act listCache.Add("all.tags1", tagCacheItems1); listCache.Add("all.tags2", tagCacheItems2); // Assert List<string> keys = listCache.GetAllKeys().ToList(); Assert.That(keys, Contains.Item(CacheKeys.ListCacheKey("all.tags1"))); Assert.That(keys, Contains.Item(CacheKeys.ListCacheKey("all.tags2"))); }
public void UpdateLinksToPage_Should_Clear_Cache() { // Arrange _container.ClearCache(); _repository.AddNewPage(new Page() { Id = 1, Title = "Homepage" }, "This is a link to [[About page title|About]]", "editor", DateTime.UtcNow); _repository.AddNewPage(new Page() { Id = 2, Title = "About page title" }, "This is a link to [[Homepage|Back home]]", "editor", DateTime.UtcNow); _pageViewModelCache.Add(1, new PageViewModel()); _pageViewModelCache.Add(2, new PageViewModel()); _listCache.Add("somekey", new List <string>()); // Act _pageService.UpdateLinksToPage("About page title", "New title"); // Assert Assert.That(_pageViewModelCache.GetAllKeys().Count(), Is.EqualTo(0)); Assert.That(_listCache.GetAllKeys().Count(), Is.EqualTo(0)); }
public void Should_Not_Add_If_Cache_Disabled() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = false }; List<string> tagCacheItems = new List<string>() { "1", "2" }; ListCache listCache = new ListCache(settings, cache); // Act listCache.Add("all.tags", tagCacheItems); // Assert var tags = listCache.Get<string>("all.tags"); Assert.That(tags, Is.Null); IEnumerable<string> keys = listCache.GetAllKeys(); Assert.That(keys.Count(), Is.EqualTo(0)); }