示例#1
0
        public void CacheIndexController_NonExistingCacheRemove()
        {
            // Act
            var controller = new CacheIndexController(_query, _appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult = controller.RemoveCache("/404page") as BadRequestObjectResult;

            Assert.AreEqual(400, actionResult.StatusCode);
        }
示例#2
0
        public void CacheIndexController_CheckIfCacheIsRemoved_CleanCache()
        {
            // Act
            var controller = new CacheIndexController(_query, _appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            _query.AddItem(new FileIndexItem
            {
                FileName        = "cacheDeleteTest",
                ParentDirectory = "/",
                IsDirectory     = true
            });

            _query.AddItem(new FileIndexItem
            {
                FileName        = "file.jpg",
                ParentDirectory = "/cacheDeleteTest",
                IsDirectory     = false
            });

            Assert.AreEqual(true, _query.DisplayFileFolders("/cacheDeleteTest").Any());

            // Ask the cache
            _query.DisplayFileFolders("/cacheDeleteTest");

            // Don't notify the cache that there is an update
            var newItem = new FileIndexItem
            {
                FileName        = "file2.jpg",
                ParentDirectory = "/cacheDeleteTest",
                IsDirectory     = false
            };

            _context.FileIndex.Add(newItem);
            _context.SaveChanges();
            // Write changes to database

            // Check if there is one item in the cache
            var beforeQuery = _query.DisplayFileFolders("/cacheDeleteTest");

            Assert.AreEqual(1, beforeQuery.Count());

            // Act, remove content from cache
            var actionResult = controller.RemoveCache("/cacheDeleteTest") as JsonResult;

            Assert.AreEqual("cache successful cleared", actionResult.Value);

            // Check if there are now two items in the cache
            var newQuery = _query.DisplayFileFolders("/cacheDeleteTest");

            Assert.AreEqual(2, newQuery.Count());
        }
示例#3
0
        public void ListCache_CacheDisabled()
        {
            var controller = new CacheIndexController(_query, new AppSettings {
                AddMemoryCache = false
            });

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult = controller.ListCache("/404page") as JsonResult;

            Assert.AreEqual("cache disabled in config", actionResult.Value);
        }
示例#4
0
        public void ListCache_CacheDidNotExist()
        {
            // Act
            var controller = new CacheIndexController(_query, _appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            // Act, remove content from cache
            var actionResult = controller.ListCache("/cacheDeleteTest2") as BadRequestObjectResult;

            Assert.AreEqual("ignored, please check if the 'f' path " +
                            "exist or use a folder string to get the cache", actionResult.Value);
        }
示例#5
0
        public void RemoveCache_CacheDidNotExist()
        {
            // Act
            var controller = new CacheIndexController(_query, _appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            _query.AddItem(new FileIndexItem
            {
                FileName        = "cacheDeleteTest2",
                ParentDirectory = "/",
                IsDirectory     = true
            });

            // Act, remove content from cache
            var actionResult = controller.RemoveCache("/cacheDeleteTest2") as JsonResult;

            Assert.AreEqual("cache did not exist", actionResult.Value);
        }
示例#6
0
        public void ListCache_GetCache()
        {
            // Act
            var controller = new CacheIndexController(_query, _appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            _query.AddCacheParentItem("/list-cache", new List <FileIndexItem> {
                new FileIndexItem
                {
                    FileName        = "cacheDeleteTest2",
                    ParentDirectory = "/list-cache",
                    IsDirectory     = true
                }
            });

            // Act, remove content from cache
            var actionResult = controller.ListCache("/list-cache") as JsonResult;

            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(actionResult.Value);
        }