本文整理汇总了C#中Roadkill.Tests.Unit.StubsAndMocks.CacheMock.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CacheMock.Add方法的具体用法?C# CacheMock.Add怎么用?C# CacheMock.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roadkill.Tests.Unit.StubsAndMocks.CacheMock
的用法示例。
在下文中一共展示了CacheMock.Add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: removeall_should_remove_pageviewmodelcache_keys_only
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));
}
示例2: GetById_Should_Load_From_Cache_When_PageSummary_Exists_In_Cache
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));
}
示例3: getbyid_should_load_from_cache_when_pagesummary_exists_in_cache
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));
}
示例4: RemoveAll_Should_Remove_ListCache_Keys_Only
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));
}
示例5: AddListCacheItem
private void AddListCacheItem(CacheMock cache, string key, object value)
{
cache.Add(CacheKeys.ListCacheKey(key), value, new CacheItemPolicy());
}
示例6: AddPageCacheItem
private void AddPageCacheItem(CacheMock cache, string key, object value)
{
cache.Add(CacheKeys.PAGEVIEWMODEL_CACHE_PREFIX + key, value, new CacheItemPolicy());
}
示例7: updatepage_should_remove_homepage_from_cache_when_homepage_is_updated
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));
}
示例8: updatepage_should_clear_list_cache_and_pagesummary_cache
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));
}
示例9: findbytag_should_load_from_cache
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));
}
示例10: findhomepage_should_load_from_cache
public void findhomepage_should_load_from_cache()
{
// Arrange
SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
PageRepositoryMock pageRepository = new PageRepositoryMock();
CacheMock modelCache = new CacheMock();
PageService pageService = CreatePageService(modelCache, null, settingsRepository, pageRepository);
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));
}
示例11: allpagescreatedby_should_load_from_cache
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));
}
示例12: RemoveAll_Should_Remove_SiteCache_Keys_Only
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));
}
示例13: UpdatePage_Should_Remove_Homepage_From_Cache_When_Homepage_Is_Updated
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));
}