本文整理汇总了C#中Roadkill.Tests.Unit.StubsAndMocks.CacheMock类的典型用法代码示例。如果您正苦于以下问题:C# CacheMock类的具体用法?C# CacheMock怎么用?C# CacheMock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheMock类属于Roadkill.Tests.Unit.StubsAndMocks命名空间,在下文中一共展示了CacheMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_Replace_Known_Tokens_When_Logged_In_As_Editor
public void Should_Replace_Known_Tokens_When_Logged_In_As_Editor()
{
// Arrange
string menuMarkup = "* %categories%\r\n\r\n%allpages%\r\n%mainpage%\r\n%newpage%\r\n%managefiles%\r\n%sitesettings%\r\n";
string expectedHtml = "<ul><li><a href=\"/pages/alltags\">Categories</a></li></ul>" +
"<a href=\"/pages/allpages\">All pages</a>" +
"<a href=\"/\">Main Page</a>" +
"<a href=\"/pages/new\">New page</a><a href=\"/filemanager\">Manage files</a>";
RepositoryMock repository = new RepositoryMock();
repository.SiteSettings = new SiteSettings();
repository.SiteSettings.MarkupType = "Markdown";
repository.SiteSettings.MenuMarkup = menuMarkup;
UserContextStub userContext = new UserContextStub();
userContext.IsAdmin = false;
userContext.IsLoggedIn = true;
ApplicationSettings applicationSettings = new ApplicationSettings();
applicationSettings.Installed = true;
CacheMock cache = new CacheMock();
SiteCache siteCache = new SiteCache(applicationSettings, cache);
MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
MenuParser parser = new MenuParser(converter, repository, siteCache, userContext);
// Act
string actualHtml = parser.GetMenu();
// Assert
Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml);
}
示例2: addloggedinmenu_should_cache_html
public void addloggedinmenu_should_cache_html()
{
// Arrange
CacheMock cache = new CacheMock();
SiteCache siteCache = new SiteCache(cache);
// Act
siteCache.AddLoggedInMenu("some html");
// Assert
Assert.That(cache.Count(), Is.EqualTo(1));
IEnumerable<string> keys = cache.Select(x => x.Key);
Assert.That(keys, Contains.Item(CacheKeys.LoggedInMenuKey()));
}
示例3: Should_Add_Item
public void Should_Add_Item()
{
// Arrange
CacheMock cache = new CacheMock();
ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true };
List<string> tagCacheItems = new List<string>() { "1", "2" };
ListCache listCache = new ListCache(settings, cache);
// Act
listCache.Add("all.tags", tagCacheItems);
// Assert
Assert.That(cache.CacheItems.Count, Is.EqualTo(1));
}
示例4: AddMenu_Should_Cache_Html
public void AddMenu_Should_Cache_Html()
{
// Arrange
CacheMock cache = new CacheMock();
ApplicationSettings settings = new ApplicationSettings();
SiteCache siteCache = new SiteCache(settings, cache);
// Act
siteCache.AddMenu("some html");
// Assert
Assert.That(cache.Count(), Is.EqualTo(1));
IEnumerable<string> keys = cache.Select(x => x.Key);
Assert.That(keys, Contains.Item(CacheKeys.MenuKey()));
}
示例5: getmenu_should_return_correct_html
public void getmenu_should_return_correct_html()
{
// Arrange
string expectedHtml = "some html";
CacheMock cache = new CacheMock();
SiteCache siteCache = new SiteCache(cache);
siteCache.AddMenu(expectedHtml);
// Act
string actualHtml = siteCache.GetMenu();
// Assert
Assert.That(actualHtml, Is.EqualTo(expectedHtml));
}
示例6: GetAdminMenu_Should_Return_Correct_Html
public void GetAdminMenu_Should_Return_Correct_Html()
{
// Arrange
string expectedHtml = "some html";
CacheMock cache = new CacheMock();
ApplicationSettings settings = new ApplicationSettings();
SiteCache siteCache = new SiteCache(settings, cache);
siteCache.AddAdminMenu(expectedHtml);
// Act
string actualHtml = siteCache.GetAdminMenu();
// Assert
Assert.That(actualHtml, Is.EqualTo(expectedHtml));
}
示例7: 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));
}
示例8: Should_Get_Item
public void Should_Get_Item()
{
// Arrange
CacheMock cache = new CacheMock();
ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true };
List<string> tagCacheItems = new List<string>() { "1", "2" };
AddToCache(cache, "all.tags", tagCacheItems);
ListCache listCache = new ListCache(settings, cache);
// Act
var tags = listCache.Get<string>("all.tags");
// Assert
Assert.That(tags, Is.EqualTo(tagCacheItems));
}
示例9: Should_Remove_Item
public void Should_Remove_Item()
{
// Arrange
CacheMock cache = new CacheMock();
ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true };
List<string> tagCacheItems = new List<string>() { "1", "2" };
AddToCache(cache, "all.tags", tagCacheItems);
ListCache listCache = new ListCache(settings, cache);
// Act
listCache.Remove("all.tags");
// Assert
var tags = cache.CacheItems.FirstOrDefault();
Assert.That(tags, Is.Null);
}
示例10: 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));
}
示例11: Should_GetAllKeys
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")));
}
示例12: AddPage_Should_Clear_List_And_PageSummary_Caches
public void AddPage_Should_Clear_List_And_PageSummary_Caches()
{
// Arrange
RepositoryMock repository = new RepositoryMock();
CacheMock pageModelCache = new CacheMock();
CacheMock listCache = new CacheMock();
PageService pageService = CreatePageService(pageModelCache, listCache, repository);
PageViewModel expectedModel = CreatePageViewModel();
AddPageCacheItem(pageModelCache, "key", expectedModel);
AddListCacheItem(listCache, "key", new List<string>() { "tag1", "tag2" });
// Act
pageService.AddPage(new PageViewModel() { Title = "totoro" });
// Assert
Assert.That(pageModelCache.CacheItems.Count, Is.EqualTo(0));
Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
}
示例13: AllPagesCreatedBy_Should_Add_To_Cache_When_Cache_Is_Empty
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));
}
示例14: 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));
}
示例15: Setup
public void Setup()
{
_pluginFactory = new PluginFactoryMock();
_pageRepository = new PageRepositoryMock();
_settingsRepository = new SettingsRepositoryMock();
_settingsRepository.SiteSettings = new SiteSettings();
_settingsRepository.SiteSettings.MarkupType = "Markdown";
_userContext = new UserContextStub();
_applicationSettings = new ApplicationSettings();
_applicationSettings.Installed = true;
_cache = new CacheMock();
_siteCache = new SiteCache(_cache);
_converter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
_menuParser = new MenuParser(_converter, _settingsRepository, _siteCache, _userContext);
}