Exemple #1
0
        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));
        }
        public void Index_POST_Should_Clear_Site_Cache()
        {
            // Arrange
            _siteCache.AddMenu("some menu");
            _siteCache.AddAdminMenu("admin menu");
            _siteCache.AddLoggedInMenu("logged in menu");

            SettingsViewModel model = new SettingsViewModel();

            // Act
            ViewResult result = _settingsController.Index(model) as ViewResult;

            // Assert
            Assert.That(_cache.Count(), Is.EqualTo(0));
        }
Exemple #3
0
        public void addadminmenu_should_cache_html()
        {
            // Arrange
            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(cache);

            // Act
            siteCache.AddAdminMenu("some html");

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
            IEnumerable <string> keys = cache.Select(x => x.Key);

            Assert.That(keys, Contains.Item(CacheKeys.AdminMenuKey()));
        }
Exemple #4
0
		public string GetMenu()
		{
			string html = "";

			if (_userContext.IsLoggedIn)
			{
				if (_userContext.IsAdmin)
				{
					html = _siteCache.GetAdminMenu();
				}
				else
				{
					html = _siteCache.GetLoggedInMenu();
				}
			}
			else
			{
				html = _siteCache.GetMenu();
			}

			// If the cache is empty, populate the right menu option
			if (string.IsNullOrEmpty(html))
			{
				SiteSettings siteSettings = _settingsRepository.GetSiteSettings();
				html = siteSettings.MenuMarkup;

				html = _markupConverter.ParseMenuMarkup(html);
				html = ReplaceKnownTokens(html);

				if (_userContext.IsLoggedIn)
				{
					if (_userContext.IsAdmin)
					{
						_siteCache.AddAdminMenu(html);
					}
					else
					{
						_siteCache.AddLoggedInMenu(html);
					}
				}
				else
				{
					_siteCache.AddMenu(html);
				}
			}

			return html;
		}
Exemple #5
0
        public void AddAdminMenu_Should_Cache_Html()
        {
            // Arrange
            CacheMock           cache     = new CacheMock();
            ApplicationSettings settings  = new ApplicationSettings();
            SiteCache           siteCache = new SiteCache(settings, cache);

            // Act
            siteCache.AddAdminMenu("some html");

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
            IEnumerable <string> keys = cache.Select(x => x.Key);

            Assert.That(keys, Contains.Item(CacheKeys.AdminMenuKey()));
        }
Exemple #6
0
        public void getadminmenu_should_return_correct_html()
        {
            // Arrange
            string expectedHtml = "some html";

            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(cache);

            siteCache.AddAdminMenu(expectedHtml);

            // Act
            string actualHtml = siteCache.GetAdminMenu();

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        public void removemenucacheitems_should_clear_cache_items()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            SiteCache siteCache = new SiteCache(cache);

            siteCache.AddMenu("menu html");
            siteCache.AddLoggedInMenu("logged in menu html");
            siteCache.AddAdminMenu("admin menu html");

            // Act
            siteCache.RemoveMenuCacheItems();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(0));
        }
Exemple #9
0
        public void RemoveMenuCacheItems_Should_Clear_Cache_Items()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            SiteCache siteCache = new SiteCache(settings, cache);

            siteCache.AddMenu("menu html");
            siteCache.AddLoggedInMenu("logged in menu html");
            siteCache.AddAdminMenu("admin menu html");

            // Act
            siteCache.RemoveMenuCacheItems();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(0));
        }