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); }
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()); }
public void CacheIndexController_CacheDisabled() { var controller = new CacheIndexController(_query, new AppSettings { AddMemoryCache = false }); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var actionResult = controller.RemoveCache("/404page") as JsonResult; Assert.AreEqual("cache disabled in config", actionResult.Value); }
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); }