Esempio n. 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));
        }
Esempio n. 3
0
        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()));
        }
Esempio n. 4
0
        public void getloggedinmenu_should_return_correct_html()
        {
            // Arrange
            string    expectedHtml = "some html";
            CacheMock cache        = new CacheMock();
            SiteCache siteCache    = new SiteCache(cache);

            siteCache.AddLoggedInMenu(expectedHtml);

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

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Esempio n. 5
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;
		}
Esempio n. 6
0
        public void AddLoggedInMenu_Should_Cache_Html()
        {
            // Arrange
            CacheMock           cache     = new CacheMock();
            ApplicationSettings settings  = new ApplicationSettings();
            SiteCache           siteCache = new SiteCache(settings, 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()));
        }
Esempio n. 7
0
        public void GetLoggedInMenu_Should_Return_Correct_Html()
        {
            // Arrange
            string              expectedHtml = "some html";
            CacheMock           cache        = new CacheMock();
            ApplicationSettings settings     = new ApplicationSettings();
            SiteCache           siteCache    = new SiteCache(settings, cache);

            siteCache.AddLoggedInMenu(expectedHtml);

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

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }