当前位置: 首页>>代码示例>>C#>>正文


C# CacheMock.Add方法代码示例

本文整理汇总了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));
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:16,代码来源:PageViewModelCacheTests.cs

示例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));
		}
开发者ID:35e8,项目名称:roadkill,代码行数:19,代码来源:PageServiceCacheTests.cs

示例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));
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:20,代码来源:PageServiceCacheTests.cs

示例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));
        }
开发者ID:NaseUkolyCZ,项目名称:roadkill,代码行数:21,代码来源:ListCacheTests.cs

示例5: AddListCacheItem

		private void AddListCacheItem(CacheMock cache, string key, object value)
		{
			cache.Add(CacheKeys.ListCacheKey(key), value, new CacheItemPolicy());
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:4,代码来源:PageServiceCacheTests.cs

示例6: AddPageCacheItem

		private void AddPageCacheItem(CacheMock cache, string key, object value)
		{
			cache.Add(CacheKeys.PAGEVIEWMODEL_CACHE_PREFIX + key, value, new CacheItemPolicy());
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:4,代码来源:PageServiceCacheTests.cs

示例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));
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:21,代码来源:PageServiceCacheTests.cs

示例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));
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:28,代码来源:PageServiceCacheTests.cs

示例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));

		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:27,代码来源:PageServiceCacheTests.cs

示例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));
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:20,代码来源:PageServiceCacheTests.cs

示例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));

		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:24,代码来源:PageServiceCacheTests.cs

示例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));
        }
开发者ID:NaseUkolyCZ,项目名称:roadkill,代码行数:23,代码来源:SiteCacheTests.cs

示例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));
        }
开发者ID:NaseUkolyCZ,项目名称:roadkill,代码行数:20,代码来源:PageServiceCacheTests.cs


注:本文中的Roadkill.Tests.Unit.StubsAndMocks.CacheMock.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。