コード例 #1
0
        static MediaTokenServiceBenchmark()
        {
            IMemoryCache memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
            IMemoryCache nullCache   = new NullCache();

            using var rng = RandomNumberGenerator.Create();
            var hashKey = new byte[64];

            rng.GetBytes(hashKey);

            // mimic default configuration
            var options = Options.Create(new MediaTokenOptions {
                HashKey = hashKey
            });
            var processors = new IImageWebProcessor[]
            {
                new ResizeWebProcessor(),
                new FormatWebProcessor(Options.Create(new ImageSharpMiddlewareOptions())),
                new BackgroundColorWebProcessor(),
                new JpegQualityWebProcessor(),
                new ImageVersionProcessor(),
                new TokenCommandProcessor()
            };

            _mediaTokenService             = new MediaTokenService(memoryCache, options, processors);
            _mediaTokenServiceWithoutCache = new MediaTokenService(nullCache, options, processors);
        }
コード例 #2
0
        public void WebProcessingExtensions_GetBySupportedCommands_Empty()
        {
            var processors = new IImageWebProcessor[]
            {
                new MockWebProcessor()
            };

            CommandCollection commands = new();

            IReadOnlyList <(int Index, IImageWebProcessor Processor)> supportedProcessors = processors.OrderBySupportedCommands(commands);

            Assert.Empty(supportedProcessors);
        }
コード例 #3
0
        public void WebProcessingExtensions_GetBySupportedCommands()
        {
            var processors = new IImageWebProcessor[]
            {
                new QualityWebProcessor(),
                new ResizeWebProcessor(),
                new BackgroundColorWebProcessor(),
                new MockWebProcessor()
            };

            CommandCollection commands = new()
            {
                new(ResizeWebProcessor.Width, null),
                new(QualityWebProcessor.Quality, null),
                new(ResizeWebProcessor.Height, null)
            };

            IReadOnlyList <(int Index, IImageWebProcessor Processor)> supportedProcessors = processors.OrderBySupportedCommands(commands);

            Assert.Equal(2, supportedProcessors.Count);
            Assert.IsType <ResizeWebProcessor>(supportedProcessors[0].Processor);
            Assert.IsType <QualityWebProcessor>(supportedProcessors[1].Processor);
        }