public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _settingsRepository = _container.SettingsRepository; _userRepository = _container.UserRepository; _pageRepository = _container.PageRepository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _container.ClearCache(); _pageService = _container.PageService; _wikiImporter = new WikiImporterMock(); _pluginFactory = _container.PluginFactory; _searchService = _container.SearchService; // There's no point mocking WikiExporter (and turning it into an interface) as // a lot of usefulness of these tests would be lost when creating fake Streams and zip files. _wikiExporter = new WikiExporter(_applicationSettings, _pageService, _settingsRepository, _pageRepository, _userRepository, _pluginFactory); _wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory; _toolsController = new ToolsController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _context, _listCache, _pageCache, _wikiImporter, _pluginFactory, _wikiExporter); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.ConnectionString = "connstring"; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _listCache = _container.ListCache; _pageViewModelCache = _container.PageViewModelCache; // User setup _editorUser = new User(); _editorUser.Id = Guid.NewGuid(); _editorUser.Email = EditorEmail; _editorUser.Username = EditorUsername; _editorUser.IsAdmin = false; _editorUser.IsEditor = true; _adminUser = new User(); _adminUser.Id = Guid.NewGuid(); _adminUser.Email = AdminEmail; _adminUser.Username = AdminUsername; _adminUser.IsAdmin = true; _adminUser.IsEditor = true; _userService.Users.Add(_editorUser); _userService.Users.Add(_adminUser); SetUserContext(_adminUser); }
/// <summary> /// Creates a new instance of MocksAndStubsContainer. /// </summary> /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param> public MocksAndStubsContainer(bool useCacheMock = false) { ApplicationSettings = new ApplicationSettings(); ApplicationSettings.Installed = true; ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments"); // Cache MemoryCache = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache; ListCache = new ListCache(ApplicationSettings, MemoryCache); SiteCache = new SiteCache(ApplicationSettings, MemoryCache); PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache); // Repository Repository = new RepositoryMock(); Repository.SiteSettings = new SiteSettings(); Repository.SiteSettings.MarkupType = "Creole"; PluginFactory = new PluginFactoryMock(); MarkupConverter = new MarkupConverter(ApplicationSettings, Repository, PluginFactory); // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock. SettingsService = new SettingsService(ApplicationSettings, Repository); UserService = new UserServiceMock(ApplicationSettings, Repository); UserContext = new UserContext(UserService); SearchService = new SearchServiceMock(ApplicationSettings, Repository, PluginFactory); SearchService.PageContents = Repository.PageContents; SearchService.Pages = Repository.Pages; HistoryService = new PageHistoryService(ApplicationSettings, Repository, UserContext, PageViewModelCache, PluginFactory); PageService = new PageService(ApplicationSettings, Repository, SearchService, HistoryService, UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory); // EmailTemplates EmailClient = new EmailClientMock(); }
private PageService CreatePageService(ObjectCache pageObjectCache, ObjectCache listObjectCache, SettingsRepositoryMock settingsRepository, PageRepositoryMock pageRepository) { // Stick to memorycache when each one isn't used if (pageObjectCache == null) { pageObjectCache = CacheMock.RoadkillCache; } if (listObjectCache == null) { listObjectCache = CacheMock.RoadkillCache; } // Settings ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseObjectCache = true }; UserContextStub userContext = new UserContextStub() { IsLoggedIn = false }; // PageService PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, pageObjectCache); ListCache listCache = new ListCache(appSettings, listObjectCache); SiteCache siteCache = new SiteCache(CacheMock.RoadkillCache); SearchServiceMock searchService = new SearchServiceMock(appSettings, settingsRepository, pageRepository, _pluginFactory); PageHistoryService historyService = new PageHistoryService(appSettings, settingsRepository, pageRepository, userContext, pageViewModelCache, _pluginFactory); PageService pageService = new PageService(appSettings, settingsRepository, pageRepository, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory); return(pageService); }
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 void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _container.ClearCache(); _pageService = _container.PageService; _wikiImporter = new WikiImporterMock(); _pluginFactory = _container.PluginFactory; _searchService = _container.SearchService; // There's no point mocking WikiExporter (and turning it into an interface) as // a lot of usefulness of these tests would be lost when creating fake Streams and zip files. _wikiExporter = new WikiExporter(_applicationSettings, _pageService, _repository, _pluginFactory); _wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory; _toolsController = new ToolsController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _context, _listCache, _pageCache, _wikiImporter, _repository, _pluginFactory, _wikiExporter); }
public async Task <ServicesResponse <List <string> > > Get() { if (cache == null || (DateTime.Now - cache.Created).TotalSeconds > 60) { var allPatrons = new List <string>(); var nextLink = "api/campaigns/1400397/pledges?include=patron.null&page%5Bcount%5D=9999"; do { var stringData = await Patreon.SendStringRequest(nextLink); var document = JsonConvert.DeserializeObject <DocumentRoot <Pledge[]> >(stringData, new JsonApiSerializerSettings()); allPatrons.AddRange(document.Data.Where(a => a.declined_since == null).Select(a => a.patron.full_name)); if (document.Links.ContainsKey("next")) { nextLink = document.Links["next"].Href; } else { break; } }while (!string.IsNullOrEmpty(nextLink)); cache = new ListCache(allPatrons.OrderBy(a => a).ToList()); } return(new ServicesResponse <List <string> >(cache.Names)); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); await _onCreateLock.WaitAsync(); SetContentView(Resource.Layout.activityMain); _preferences = new PreferenceWrapper(this); _authCache = new ListCache <WearAuthenticator>(AuthenticatorCacheName, this); _categoryCache = new ListCache <WearCategory>(CategoryCacheName, this); _customIconCache = new CustomIconCache(this); await _authCache.Init(); await _categoryCache.Init(); _authSource = new AuthenticatorSource(_authCache); var defaultCategory = _preferences.DefaultCategory; if (defaultCategory != null) { _authSource.SetCategory(defaultCategory); } RunOnUiThread(InitViews); _onCreateLock.Release(); }
private void UpdateBattles(int deltaTime) { using (var rmvs = ListCache <string> .Get()) { foreach (var kv in battles) { try { var battle = kv.Value; battle.Update(deltaTime); if (battle.Destroyable) { rmvs.Add(kv.Key); } } catch (Exception ex) { Logger.Exception(ex); } } for (var i = rmvs.Count - 1; i >= 0; i--) { DeleteBattle(rmvs[i]); } } }
public void should_not_removeall_if_cache_disabled() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = false }; 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 var tags1 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags1")); var tags2 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags2")); Assert.That(tags1, Is.Not.Null); Assert.That(tags2, Is.Not.Null); }
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_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); }
public static List <int> GetContentIdList(SiteInfo siteInfo, ChannelInfo channelInfo, int?onlyAdminId, int offset, int limit) { var list = ListCache.GetContentIdList(channelInfo.Id, onlyAdminId); if (list.Count >= offset + limit) { return(list.Skip(offset).Take(limit).ToList()); } var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); if (list.Count == offset) { var dict = ContentCache.GetContentDict(channelInfo.Id); var pageContentInfoList = DataProvider.ContentDao.GetContentInfoList(tableName, DataProvider.ContentDao.GetCacheWhereString(siteInfo, channelInfo, onlyAdminId), DataProvider.ContentDao.GetOrderString(channelInfo, string.Empty), offset, limit); foreach (var contentInfo in pageContentInfoList) { dict[contentInfo.Id] = contentInfo; } var pageContentIdList = pageContentInfoList.Select(x => x.Id).ToList(); list.AddRange(pageContentIdList); return(pageContentIdList); } return(DataProvider.ContentDao.GetCacheContentIdList(tableName, DataProvider.ContentDao.GetCacheWhereString(siteInfo, channelInfo, onlyAdminId), DataProvider.ContentDao.GetOrderString(channelInfo, string.Empty), offset, limit)); }
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)); }
public void should_removeall_items() { // 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>() { "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.CacheItems.Count, Is.EqualTo(0)); }
public static void UpdateCache(SiteInfo siteInfo, ChannelInfo channelInfo, ContentInfo contentInfoToUpdate) { var dict = ContentCache.GetContentDict(channelInfo.Id); var contentInfo = GetContentInfo(siteInfo, channelInfo, contentInfoToUpdate.Id); if (contentInfo != null) { if (ListCache.IsChanged(channelInfo, contentInfo, contentInfoToUpdate)) { ListCache.Remove(channelInfo.Id); } if (CountCache.IsChanged(contentInfo, contentInfoToUpdate)) { var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); CountCache.Remove(tableName, contentInfo); CountCache.Add(tableName, contentInfoToUpdate); } } dict[contentInfoToUpdate.Id] = contentInfoToUpdate; StlContentCache.ClearCache(); }
public static List <ReplaceItem> GetReplaceItems( Match match, ReplaceOptions replaceOptions, CancellationToken cancellationToken = default) { List <Match> matches = GetMatches(match); int offset = 0; List <ReplaceItem> replaceItems = ListCache <ReplaceItem> .GetInstance(); if (replaceItems.Capacity < matches.Count) { replaceItems.Capacity = matches.Count; } foreach (Match match2 in matches) { string value = replaceOptions.Replace(match2); replaceItems.Add(new ReplaceItem(match2, value, match2.Index + offset)); offset += value.Length - match2.Length; cancellationToken.ThrowIfCancellationRequested(); } ListCache <Match> .Free(matches); return(replaceItems);
public static void RemoveCache(string tableName, int channelId) { ListCache.Remove(channelId); ContentCache.Remove(channelId); CountCache.Clear(tableName); StlContentCache.ClearCache(); }
public static void UpdateCache(SiteInfo siteInfo, ChannelInfo channelInfo, IContentInfo contentInfoToUpdate) { var dict = ContentCache.GetContentDict(channelInfo.Id); var contentInfo = GetContentInfo(siteInfo, channelInfo, contentInfoToUpdate.Id); if (contentInfo != null) { var isClearCache = contentInfo.IsTop != contentInfoToUpdate.IsTop; if (!isClearCache) { var orderAttributeName = ETaxisTypeUtils.GetContentOrderAttributeName( ETaxisTypeUtils.GetEnumType(channelInfo.Additional.DefaultTaxisType)); if (contentInfo.Get(orderAttributeName) != contentInfoToUpdate.Get(orderAttributeName)) { isClearCache = true; } } if (isClearCache) { ListCache.Remove(channelInfo.Id); } } dict[contentInfoToUpdate.Id] = (ContentInfo)contentInfoToUpdate; StlContentCache.ClearCache(); }
public static List <int> GetContentIdList(SiteInfo siteInfo, ChannelInfo channelInfo, int offset, int limit) { var list = ListCache.GetContentIdList(channelInfo.Id); if (list.Count >= offset + limit) { return(list.Skip(offset).Take(limit).ToList()); } if (list.Count == offset) { var dict = ContentCache.GetContentDict(channelInfo.Id); var pageContentInfoList = DataProvider.ContentDao.GetCacheContentInfoList(siteInfo, channelInfo, offset, limit); foreach (var contentInfo in pageContentInfoList) { dict[contentInfo.Id] = contentInfo; } var pageContentIdList = pageContentInfoList.Select(x => x.Id).ToList(); list.AddRange(pageContentIdList); return(pageContentIdList); } return(DataProvider.ContentDao.GetCacheContentIdList(siteInfo, channelInfo, offset, limit)); }
public static void StringListCreation(string[] xs) { var expected = xs.ToList(); var cache = new ListCache(1); var actual = (FuncList <string>)cache.RetrieveOrCacheCreate(typeof(string), xs.Cast <object>()); Assert.Equal(expected, actual); }
public void Dispose() { if (OnDispose != null) { OnDispose(this); } ListCache.PushList <Component>(m_Components); }
public static void IntListListCreation(List <int>[] xs) { var expected = xs.ToList(); var cache = new ListCache(1); var actual = (FuncList <List <int> >)cache.RetrieveOrCacheCreate(typeof(List <int>), xs.Cast <object>()); Assert.Equal(expected, actual); }
public void OnUpdate(Sql cond) { ListCache.Remove(CombineCacheKey(cond)); if (!cond.Disposed) { cond.Dispose(); } }
public CacheController(ApplicationSettings settings, UserServiceBase userService, SettingsService settingsService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache siteCache) : base(settings, userService, context, settingsService) { _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = siteCache; }
void ClearUIElementsGroup() { for (int i = 0; i < uiElementsGroup.Count; i++) { uiElementsGroup[i].Clear(); ListCache.Push(uiElementsGroup[i]); } uiElementsGroup.Clear(); }
protected AbstractBlittableJsonDocumentBuilder() { if (GlobalCache.TryPull(out _cacheItem) == false) { _cacheItem = new GlobalPoolItem(); } _propertiesCache = _cacheItem.PropertyCache; _positionsCache = _cacheItem.PositionsCache; _tokensCache = _cacheItem.TokensCache; }
public static void RemoveCacheBySiteId(string tableName, int siteId) { foreach (var channelId in ChannelManager.GetChannelIdList(siteId)) { ListCache.Remove(channelId); ContentCache.Remove(channelId); } CountCache.Clear(tableName); StlContentCache.ClearCache(); }
public static List <(int ChannelId, int ContentId)> GetChannelContentIdList(SiteInfo siteInfo, ChannelInfo channelInfo, int adminId, bool isAllContents, int offset, int limit) { var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var channelContentIdList = new List <(int ChannelId, int ContentId)>(); foreach (var contentId in ListCache.GetContentIdList(channelInfo.Id, adminId)) { channelContentIdList.Add((channelInfo.Id, contentId)); } if (isAllContents) { var channelIdList = ChannelManager.GetChannelIdList(channelInfo, EScopeType.Descendant); foreach (var contentChannelId in channelIdList) { var contentChannelInfo = ChannelManager.GetChannelInfo(siteInfo.Id, contentChannelId); var channelTableName = ChannelManager.GetTableName(siteInfo, contentChannelInfo); if (!StringUtils.EqualsIgnoreCase(tableName, channelTableName)) { continue; } foreach (var contentId in ListCache.GetContentIdList(contentChannelId, adminId)) { channelContentIdList.Add((contentChannelId, contentId)); } } } if (channelContentIdList.Count >= offset + limit) { return(channelContentIdList.Skip(offset).Take(limit).ToList()); } if (channelContentIdList.Count == offset) { var dict = ContentCache.GetContentDict(channelInfo.Id); var pageContentInfoList = DataProvider.ContentDao.GetContentInfoList(tableName, DataProvider.ContentDao.GetCacheWhereString(siteInfo, channelInfo, adminId, isAllContents), DataProvider.ContentDao.GetOrderString(channelInfo, string.Empty, isAllContents), offset, limit); foreach (var contentInfo in pageContentInfoList) { ListCache.Set(contentInfo); dict[contentInfo.Id] = contentInfo; } var pageContentIdList = pageContentInfoList.Select(x => (x.ChannelId, x.Id)).ToList(); channelContentIdList.AddRange(pageContentIdList); return(pageContentIdList); } return(DataProvider.ContentDao.GetCacheChannelContentIdList(tableName, DataProvider.ContentDao.GetCacheWhereString(siteInfo, channelInfo, adminId, isAllContents), DataProvider.ContentDao.GetOrderString(channelInfo, string.Empty, isAllContents), offset, limit)); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.activityMain); try { await WearableClass.GetMessageClient(this).AddListenerAsync(this); await FindServerNode(); } catch (ApiException) { } _loadingLayout = FindViewById <RelativeLayout>(Resource.Id.layoutLoading); _emptyLayout = FindViewById <RelativeLayout>(Resource.Id.layoutEmpty); _offlineLayout = FindViewById <LinearLayout>(Resource.Id.layoutOffline); _authList = FindViewById <WearableRecyclerView>(Resource.Id.list); _authList.EdgeItemsCenteringEnabled = true; _authList.HasFixedSize = true; _authList.SetItemViewCacheSize(12); _authList.SetItemAnimator(null); var layoutCallback = new ScrollingListLayoutCallback(Resources.Configuration.IsScreenRound); _authList.SetLayoutManager(new WearableLinearLayoutManager(this, layoutCallback)); _authCache = new ListCache <WearAuthenticator>("authenticators", this); _categoryCache = new ListCache <WearCategory>("categories", this); _customIconCache = new CustomIconCache(this); await _authCache.Init(); _authSource = new AuthenticatorSource(_authCache); _authListAdapter = new AuthenticatorListAdapter(_authSource, _customIconCache); _authListAdapter.ItemClick += OnItemClick; _authListAdapter.HasStableIds = true; _authList.SetAdapter(_authListAdapter); if (_authCache.GetItems().Count > 0 || _serverNode == null) { UpdateViewState(); } await _categoryCache.Init(); var categoriesDrawer = FindViewById <WearableNavigationDrawerView>(Resource.Id.drawerCategories); _categoryListAdapter = new CategoryListAdapter(this, _categoryCache); categoriesDrawer.SetAdapter(_categoryListAdapter); categoriesDrawer.ItemSelected += OnCategorySelected; await Refresh(); }
public PluginSettingsController(ApplicationSettings settings, UserServiceBase userService, IUserContext context, SettingsService settingsService, IPluginFactory pluginFactory, IRepository repository, SiteCache siteCache, PageViewModelCache viewModelCache, ListCache listCache) : base (settings, userService, context, settingsService) { _pluginFactory = pluginFactory; _repository = repository; _siteCache = siteCache; _viewModelCache = viewModelCache; _listCache = listCache; }
public PluginSettingsController(ApplicationSettings settings, UserServiceBase userService, IUserContext context, SettingsService settingsService, IPluginFactory pluginFactory, ISettingsRepository settingsRepository, SiteCache siteCache, PageViewModelCache viewModelCache, ListCache listCache) : base(settings, userService, context, settingsService) { _pluginFactory = pluginFactory; _settingsRepository = settingsRepository; _siteCache = siteCache; _viewModelCache = viewModelCache; _listCache = listCache; }
public ToolsController(ApplicationSettings settings, UserServiceBase userManager, SettingsService settingsService, PageService pageService, SearchService searchService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, IWikiImporter wikiImporter, IPluginFactory pluginFactory, WikiExporter wikiExporter) : base(settings, userManager, context, settingsService) { _pageService = pageService; _searchService = searchService; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _wikiImporter = wikiImporter; _wikiExporter = wikiExporter; }
public RelService(ApplicationSettings settings, IRepository repository, SearchService searchService, PageHistoryService historyService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory) : base(settings, repository) { _searchService = searchService; _markupConverter = new MarkupConverter(settings, repository, pluginFactory); _historyService = historyService; _context = context; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = sitecache; _pluginFactory = pluginFactory; }
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)); }
public UserManagementController(ApplicationSettings settings, UserServiceBase userManager, SettingsService settingsService, PageService pageService, SearchService searchService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache siteCache, IWikiImporter wikiImporter, IRepository repository, IPluginFactory pluginFactory) : base(settings, userManager, context, settingsService) { _settingsService = settingsService; _pageService = pageService; _searchService = searchService; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = siteCache; _wikiImporter = wikiImporter; _repository = repository; _pluginFactory = pluginFactory; }
public void Setup() { _container = new MocksAndStubsContainer(); _container.ClearCache(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _cacheController = new CacheController(_applicationSettings, _userService, _settingsService, _context, _listCache, _pageCache, _siteCache); }
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)); }
public PageService(ApplicationSettings settings, ISettingsRepository settingsRepository, IPageRepository pageRepository, SearchService searchService, PageHistoryService historyService, IUserContext context, ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory) { _searchService = searchService; _markupConverter = new MarkupConverter(settings, settingsRepository, pageRepository, pluginFactory); _historyService = historyService; _context = context; _listCache = listCache; _pageViewModelCache = pageViewModelCache; _siteCache = sitecache; _pluginFactory = pluginFactory; _markupLinkUpdater = new MarkupLinkUpdater(_markupConverter.Parser); ApplicationSettings = settings; SettingsRepository = settingsRepository; PageRepository = pageRepository; }
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); }
public void Setup() { _container = new MocksAndStubsContainer(); _container.ClearCache(); _applicationSettings = _container.ApplicationSettings; _applicationSettings.AttachmentsFolder = AppDomain.CurrentDomain.BaseDirectory; _context = _container.UserContext; _settingsRepository = _container.SettingsRepository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _configReaderWriter = new ConfigReaderWriterStub(); _settingsController = new SettingsController(_applicationSettings, _userService, _settingsService, _context, _siteCache, _configReaderWriter); }
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 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)); }
public void Setup() { _container = new MocksAndStubsContainer(true); _applicationSettings = _container.ApplicationSettings; _applicationSettings.UseObjectCache = true; _context = _container.UserContext; _repository = _container.Repository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _pageViewModelCache = _container.PageViewModelCache; _memoryCache = _container.MemoryCache; _controller = new PluginSettingsController(_applicationSettings, _userService, _context, _settingsService, _pluginFactory, _repository, _siteCache, _pageViewModelCache, _listCache); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _repository = _container.Repository; _settingsService = _container.SettingsService; _userService = _container.UserService; _pageCache = _container.PageViewModelCache; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _cache = _container.MemoryCache; _pageService = _container.PageService; _wikiImporter = new ScrewTurnImporter(_applicationSettings, _repository); _pluginFactory = _container.PluginFactory; _searchService = _container.SearchService; _controller = new UserManagementController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _context, _listCache, _pageCache, _siteCache, _wikiImporter, _repository, _pluginFactory); }
public void Setup() { _container = new MocksAndStubsContainer(); _applicationSettings = _container.ApplicationSettings; _context = _container.UserContext; _pageRepository = _container.PageRepository; _pluginFactory = _container.PluginFactory; _settingsService = _container.SettingsService; _userService = _container.UserService; _historyService = _container.HistoryService; _pageService = _container.PageService; _searchService = _container.SearchService; _markupConverter = _container.MarkupConverter; _listCache = _container.ListCache; _siteCache = _container.SiteCache; _pageViewModelCache = _container.PageViewModelCache; _memoryCache = _container.MemoryCache; _homeController = new HomeController(_applicationSettings, _userService, _markupConverter, _pageService, _searchService, _context, _settingsService); _homeController.SetFakeControllerContext(); }
private WikiController CreateWikiController(BrowserCacheAttribute attribute) { // Settings ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseBrowserCache = true }; UserContextStub userContext = new UserContextStub() { IsLoggedIn = false }; // PageService PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, CacheMock.RoadkillCache); ListCache listCache = new ListCache(appSettings, CacheMock.RoadkillCache); SiteCache siteCache = new SiteCache(appSettings, CacheMock.RoadkillCache); SearchServiceMock searchService = new SearchServiceMock(appSettings, _repositoryMock, _pluginFactory); PageHistoryService historyService = new PageHistoryService(appSettings, _repositoryMock, userContext, pageViewModelCache, _pluginFactory); PageService pageService = new PageService(appSettings, _repositoryMock, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory); // WikiController SettingsService settingsService = new SettingsService(appSettings, _repositoryMock); UserServiceStub userManager = new UserServiceStub(); WikiController wikiController = new WikiController(appSettings, userManager, pageService, userContext, settingsService); // Create a page that the request is for Page page = new Page() { Title = "title", ModifiedOn = _pageModifiedDate }; _repositoryMock.AddNewPage(page, "text", "user", _pageCreatedDate); // Update the BrowserCacheAttribute attribute.ApplicationSettings = appSettings; attribute.Context = userContext; attribute.PageService = pageService; return wikiController; }
/// <summary> /// Creates a new instance of MocksAndStubsContainer. /// </summary> /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param> public MocksAndStubsContainer(bool useCacheMock = false) { ApplicationSettings = new ApplicationSettings(); ApplicationSettings.Installed = true; ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments"); ConfigReaderWriter = new ConfigReaderWriterStub(); // Cache MemoryCache = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache; ListCache = new ListCache(ApplicationSettings, MemoryCache); SiteCache = new SiteCache(MemoryCache); PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache); // Repositories SettingsRepository = new SettingsRepositoryMock(); SettingsRepository.SiteSettings = new SiteSettings(); SettingsRepository.SiteSettings.MarkupType = "Creole"; UserRepository = new UserRepositoryMock(); PageRepository = new PageRepositoryMock(); InstallerRepository = new InstallerRepositoryMock(); RepositoryFactory = new RepositoryFactoryMock() { SettingsRepository = SettingsRepository, UserRepository = UserRepository, PageRepository = PageRepository, InstallerRepository = InstallerRepository }; DatabaseTester = new DatabaseTesterMock(); // Plugins PluginFactory = new PluginFactoryMock(); MarkupConverter = new MarkupConverter(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory); // Services // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock. SettingsService = new SettingsService(RepositoryFactory, ApplicationSettings); UserService = new UserServiceMock(ApplicationSettings, UserRepository); UserContext = new UserContext(UserService); SearchService = new SearchServiceMock(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory); SearchService.PageContents = PageRepository.PageContents; SearchService.Pages = PageRepository.Pages; HistoryService = new PageHistoryService(ApplicationSettings, SettingsRepository, PageRepository, UserContext, PageViewModelCache, PluginFactory); FileService = new FileServiceMock(); PageService = new PageService(ApplicationSettings, SettingsRepository, PageRepository, SearchService, HistoryService, UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory); StructureMapContainer = new Container(x => { x.AddRegistry(new TestsRegistry(this)); }); Locator = new StructureMapServiceLocator(StructureMapContainer, false); InstallationService = new InstallationService((databaseName, connectionString) => { InstallerRepository.DatabaseName = databaseName; InstallerRepository.ConnectionString = connectionString; return InstallerRepository; }, Locator); // EmailTemplates EmailClient = new EmailClientMock(); }
private PageService CreatePageService(ObjectCache pageObjectCache, ObjectCache listObjectCache, SettingsRepositoryMock settingsRepository, PageRepositoryMock pageRepository) { // Stick to memorycache when each one isn't used if (pageObjectCache == null) pageObjectCache = CacheMock.RoadkillCache; if (listObjectCache == null) listObjectCache = CacheMock.RoadkillCache; // Settings ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseObjectCache = true }; UserContextStub userContext = new UserContextStub() { IsLoggedIn = false }; // PageService PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, pageObjectCache); ListCache listCache = new ListCache(appSettings, listObjectCache); SiteCache siteCache = new SiteCache(CacheMock.RoadkillCache); SearchServiceMock searchService = new SearchServiceMock(appSettings, settingsRepository, pageRepository, _pluginFactory); PageHistoryService historyService = new PageHistoryService(appSettings, settingsRepository, pageRepository, userContext, pageViewModelCache, _pluginFactory); PageService pageService = new PageService(appSettings, settingsRepository, pageRepository, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory); return pageService; }
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 void Should_Not_RemoveAll_If_Cache_Disabled() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = false }; 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 var tags1 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags1")); var tags2 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags2")); Assert.That(tags1, Is.Not.Null); Assert.That(tags2, Is.Not.Null); }
public void Should_RemoveAll_Items() { // 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>() { "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.CacheItems.Count, Is.EqualTo(0)); }