Beispiel #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 ClearPages_Should_Set_TempData_Message_And_Clear_Cache_And_Clear_All_Pages()
        {
            // Arrange
            _repository.AddNewPage(new Page()
            {
                Id = 1
            }, "text", "admin", DateTime.UtcNow);
            _repository.AddNewPage(new Page()
            {
                Id = 2
            }, "text", "admin", DateTime.UtcNow);

            _pageCache.Add(1, new PageViewModel());
            _listCache.Add("list.somekey", new List <string>());
            _siteCache.AddMenu("should not be cleared");

            // Act
            RedirectToRouteResult result = _toolsController.ClearPages() as RedirectToRouteResult;

            // Assert
            Assert.That(result, Is.Not.Null, "RedirectToRouteResult");
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));

            Assert.That(_toolsController.TempData["SuccessMessage"], Is.EqualTo(SiteStrings.SiteSettings_Tools_ClearDatabase_Message));
            Assert.That(_cache.Count(), Is.EqualTo(1));
            Assert.That(_repository.AllPages().Count(), Is.EqualTo(0));
        }
        public void index_should_return_viewmodel_with_filled_properties()
        {
            // Arrange
            _applicationSettings.UseObjectCache = true;
            _pageCache.Add(1, new PageViewModel());
            _listCache.Add <string>("test", new List <string>());
            _siteCache.AddMenu("menu");

            // Act
            ViewResult result = _cacheController.Index() as ViewResult;

            // Assert
            Assert.That(result, Is.Not.Null, "ViewResult");

            CacheViewModel model = result.ModelFromActionResult <CacheViewModel>();

            Assert.NotNull(model, "Null model");
            Assert.That(model.IsCacheEnabled, Is.True);
            Assert.That(model.PageKeys.Count(), Is.EqualTo(1));
            Assert.That(model.ListKeys.Count(), Is.EqualTo(1));
            Assert.That(model.SiteKeys.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));
        }
Beispiel #5
0
        public void addmenu_should_cache_html()
        {
            // Arrange
            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(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()));
        }
Beispiel #6
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;
		}
Beispiel #7
0
        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()));
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        public void GetMenu_Should_Return_Correct_Html()
        {
            // Arrange
            string expectedHtml = "some html";

            CacheMock           cache     = new CacheMock();
            ApplicationSettings settings  = new ApplicationSettings();
            SiteCache           siteCache = new SiteCache(settings, cache);

            siteCache.AddMenu(expectedHtml);

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

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Beispiel #10
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));
        }
Beispiel #11
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));
        }