private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services) { services.AddImageSharpCore( options => { options.Configuration = Configuration.Default; options.MaxBrowserCacheDays = 7; options.MaxCacheDays = 365; options.CachedNameLength = 8; options.OnParseCommands = _ => { }; options.OnBeforeSave = _ => { }; options.OnProcessed = _ => { }; options.OnPrepareResponse = _ => { }; }) .SetRequestParser <QueryCollectionRequestParser>() .SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling()) .SetCache(provider => { var p = new PhysicalFileSystemCache( provider.GetRequiredService <IHostingEnvironment>(), provider.GetRequiredService <MemoryAllocator>(), provider.GetRequiredService <IOptions <ImageSharpMiddlewareOptions> >()); p.Settings[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder; return(p); }) .SetCacheHash <CacheHash>() .SetAsyncKeyLock <AsyncKeyLock>() .AddProvider <PhysicalFileSystemProvider>() .AddProcessor <ResizeWebProcessor>() .AddProcessor <FormatWebProcessor>() .AddProcessor <BackgroundColorWebProcessor>(); }
public void GetCacheRootThrows(string cacheFolder, string cacheRootPath, string webRootPath, string contentRootPath) { var cacheOptions = new PhysicalFileSystemCacheOptions { CacheFolder = cacheFolder, CacheRootPath = cacheRootPath }; Assert.Throws <InvalidOperationException>(() => PhysicalFileSystemCache.GetCacheRoot(cacheOptions, webRootPath, contentRootPath)); }
public void FilePathMatchesReference() { const string Key = "abcdefghijkl"; const int CachedNameLength = 12; string expected = $"{string.Join("/", Key.Substring(0, CachedNameLength).ToCharArray())}/{Key}"; string actual = PhysicalFileSystemCache.ToFilePath(Key, CachedNameLength); Assert.Equal(expected, actual); }
public void GetCacheRoot(string cacheFolder, string cacheRootPath, string webRootPath, string contentRootPath, string expected) { var cacheOptions = new PhysicalFileSystemCacheOptions { CacheFolder = cacheFolder, CacheRootPath = cacheRootPath }; string actual = PhysicalFileSystemCache.GetCacheRoot(cacheOptions, webRootPath, contentRootPath); Assert.Equal(expected, actual); }
public void CacheRootFromOptions(string cacheFolder, string cacheRoot, string webRootPath, string contentRootPath, string expected) { var cacheOptions = new PhysicalFileSystemCacheOptions { CacheFolder = cacheFolder, CacheRoot = cacheRoot }; var cacheRootResult = PhysicalFileSystemCache.GetCacheRoot(cacheOptions, webRootPath, contentRootPath); Assert.Equal(expected, cacheRootResult); }
public void FilePathMatchesReference(string key, int cacheFolderDepth, string expected) { string actual = PhysicalFileSystemCache.ToFilePath(key, cacheFolderDepth); Assert.Equal(expected, actual); }
public string JoinUsingStringCreate() => PhysicalFileSystemCache.ToFilePath(Key, CachedNameLength);
public string JoinUsingStringCreate() => PhysicalFileSystemCache.ToFilePath(Key, this.CacheFolderDepth);