diff --git a/.editorconfig b/.editorconfig index 2e3045fb..f579ff5d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -104,8 +104,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:war dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion # Expression-level preferences -dotnet_style_object_initializer = true:warning -dotnet_style_collection_initializer = true:warning +dotnet_style_object_initializer = true:error +dotnet_style_collection_initializer = true:error dotnet_style_explicit_tuple_names = true:warning dotnet_style_prefer_inferred_tuple_names = true:warning dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning @@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning # https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules [*.{cs,csx,cake}] # 'var' preferences -csharp_style_var_for_built_in_types = false:warning -csharp_style_var_when_type_is_apparent = false:warning -csharp_style_var_elsewhere = false:warning +csharp_style_var_for_built_in_types = false:error +csharp_style_var_when_type_is_apparent = false:error +csharp_style_var_elsewhere = false:error # Expression-bodied members csharp_style_expression_bodied_methods = true:warning csharp_style_expression_bodied_constructors = true:warning @@ -160,7 +160,10 @@ csharp_style_pattern_local_over_anonymous_function = true:warning csharp_style_deconstructed_variable_declaration = true:warning csharp_style_prefer_index_operator = true:warning csharp_style_prefer_range_operator = true:warning -csharp_style_implicit_object_creation_when_type_is_apparent = true:warning +csharp_style_implicit_object_creation_when_type_is_apparent = true:error +# ReSharper inspection severities +resharper_arrange_object_creation_when_type_evident_highlighting = error +resharper_arrange_object_creation_when_type_not_evident_highlighting = error # "Null" checking preferences csharp_style_throw_expression = true:warning csharp_style_conditional_delegate_call = true:warning @@ -172,6 +175,11 @@ dotnet_diagnostic.IDE0063.severity = suggestion csharp_using_directive_placement = outside_namespace:warning # Modifier preferences csharp_prefer_static_local_function = true:warning +# Primary constructor preferences +csharp_style_prefer_primary_constructors = false:none +# Collection preferences +dotnet_style_prefer_collection_expression = true:error +resharper_use_collection_expression_highlighting =true:error ########################################## # Unnecessary Code Rules diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cc88f801..68fef91f 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -16,30 +16,37 @@ jobs: matrix: options: - os: ubuntu-latest - framework: net7.0 + framework: net9.0 + sdk: 9.0.x sdk-preview: true runtime: -x64 codecov: false - os: macos-latest - framework: net7.0 + framework: net9.0 + sdk: 9.0.x sdk-preview: true runtime: -x64 codecov: false - os: windows-latest - framework: net7.0 + framework: net9.0 + sdk: 9.0.x sdk-preview: true runtime: -x64 codecov: true + - os: ubuntu-latest - framework: net6.0 + framework: net8.0 + sdk: 8.0.x runtime: -x64 codecov: false - os: macos-latest - framework: net6.0 + framework: net8.0 + sdk: 8.0.x runtime: -x64 codecov: false - os: windows-latest - framework: net6.0 + framework: net8.0 + sdk: 8.0.x runtime: -x64 codecov: false @@ -112,11 +119,18 @@ jobs: s3rver -d . & - name: DotNet Setup + if: ${{ matrix.options.sdk-preview != true }} + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 8.0.x + + - name: DotNet Setup Preview + if: ${{ matrix.options.sdk-preview == true }} uses: actions/setup-dotnet@v4 with: dotnet-version: | - 7.0.x - 6.0.x + 9.0.x - name: DotNet Build if: ${{ matrix.options.sdk-preview != true }} diff --git a/samples/ImageSharp.Web.Sample/ImageSharp.Web.Sample.csproj b/samples/ImageSharp.Web.Sample/ImageSharp.Web.Sample.csproj index d20146da..09577d86 100644 --- a/samples/ImageSharp.Web.Sample/ImageSharp.Web.Sample.csproj +++ b/samples/ImageSharp.Web.Sample/ImageSharp.Web.Sample.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable 10 diff --git a/shared-infrastructure b/shared-infrastructure index f0d7ed20..d0f141ba 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit f0d7ed20b36ab1f9e379ca3bee528e6efd991b00 +Subproject commit d0f141bad2baf7e256aa38ef18129c31cfb857a5 diff --git a/src/ImageSharp.Web.Providers.AWS/Caching/AWSS3StorageCache.cs b/src/ImageSharp.Web.Providers.AWS/Caching/AWSS3StorageCache.cs index 676dbeca..8ed92834 100644 --- a/src/ImageSharp.Web.Providers.AWS/Caching/AWSS3StorageCache.cs +++ b/src/ImageSharp.Web.Providers.AWS/Caching/AWSS3StorageCache.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Web.Caching.AWS; /// public class AWSS3StorageCache : IImageCache { - private readonly IAmazonS3 amazonS3Client; + private readonly AmazonS3Client amazonS3Client; private readonly string bucketName; private readonly string cacheFolder; diff --git a/src/ImageSharp.Web.Providers.AWS/ImageSharp.Web.Providers.AWS.csproj b/src/ImageSharp.Web.Providers.AWS/ImageSharp.Web.Providers.AWS.csproj index a899bc38..571290b0 100644 --- a/src/ImageSharp.Web.Providers.AWS/ImageSharp.Web.Providers.AWS.csproj +++ b/src/ImageSharp.Web.Providers.AWS/ImageSharp.Web.Providers.AWS.csproj @@ -27,12 +27,12 @@ - net7.0;net6.0 + net9.0;net8.0 - net6.0 + net8.0 diff --git a/src/ImageSharp.Web.Providers.Azure/ImageSharp.Web.Providers.Azure.csproj b/src/ImageSharp.Web.Providers.Azure/ImageSharp.Web.Providers.Azure.csproj index 90be6e45..b7e7060c 100644 --- a/src/ImageSharp.Web.Providers.Azure/ImageSharp.Web.Providers.Azure.csproj +++ b/src/ImageSharp.Web.Providers.Azure/ImageSharp.Web.Providers.Azure.csproj @@ -27,12 +27,12 @@ - net7.0;net6.0 + net9.0;net8.0 - net6.0 + net8.0 diff --git a/src/ImageSharp.Web/Caching/HexEncoder.cs b/src/ImageSharp.Web/Caching/HexEncoder.cs index acf72787..96b4cdd1 100644 --- a/src/ImageSharp.Web/Caching/HexEncoder.cs +++ b/src/ImageSharp.Web/Caching/HexEncoder.cs @@ -32,7 +32,7 @@ public static unsafe string Encode(ReadOnlySpan bytes) { return string.Create(bytes.Length * 2, (Ptr: (IntPtr)bytesPtr, bytes.Length), (chars, args) => { - var ros = new ReadOnlySpan((byte*)args.Ptr, args.Length); + ReadOnlySpan ros = new((byte*)args.Ptr, args.Length); EncodeToUtf16(ros, chars); }); } diff --git a/src/ImageSharp.Web/Commands/CommandCollection.cs b/src/ImageSharp.Web/Commands/CommandCollection.cs index 16747d48..095a01c6 100644 --- a/src/ImageSharp.Web/Commands/CommandCollection.cs +++ b/src/ImageSharp.Web/Commands/CommandCollection.cs @@ -66,7 +66,7 @@ public IEnumerable Keys { if (this.TryGetValue(key, out KeyValuePair item)) { - this.SetItem(this.IndexOf(item), new(key, value)); + this.SetItem(this.IndexOf(item), new KeyValuePair(key, value)); } else { @@ -81,7 +81,7 @@ public IEnumerable Keys /// The to use as the key of the element to add. /// The to use as the value of the element to add. /// is null. - public void Add(string key, string value) => this.Add(new(key, value)); + public void Add(string key, string value) => this.Add(new KeyValuePair(key, value)); /// /// Inserts an element into the at the @@ -91,7 +91,7 @@ public IEnumerable Keys /// The to use as the key of the element to insert. /// The to use as the value of the element to insert. /// index is less than zero. -or- index is greater than . - public void Insert(int index, string key, string value) => this.Insert(index, new(key, value)); + public void Insert(int index, string key, string value) => this.Insert(index, new KeyValuePair(key, value)); /// /// Gets the value associated with the specified key. diff --git a/src/ImageSharp.Web/Commands/Converters/ColorConverter.cs b/src/ImageSharp.Web/Commands/Converters/ColorConverter.cs index ccf2c111..1f6b4a4d 100644 --- a/src/ImageSharp.Web/Commands/Converters/ColorConverter.cs +++ b/src/ImageSharp.Web/Commands/Converters/ColorConverter.cs @@ -11,18 +11,18 @@ namespace SixLabors.ImageSharp.Web.Commands.Converters; /// /// Allows the conversion of strings into rgba32 pixel colors. /// -public sealed class ColorConverter : ICommandConverter +public sealed partial class ColorConverter : ICommandConverter { /// /// The web color hexadecimal regex. Matches strings arranged /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. /// - private static readonly Regex HexColorRegex = new("([0-9a-fA-F][^,;.-]\\B{3}){1,2}", RegexOptions.Compiled); + private static readonly Regex HexColorRegex = CreateHexColorRegex(); /// /// The number color regex. /// - private static readonly Regex NumberRegex = new(@"\d+", RegexOptions.Compiled); + private static readonly Regex NumberRegex = CreateNumberRegex(); /// /// The color constants table map. @@ -85,9 +85,9 @@ public Color ConvertFrom(CommandParser parser, CultureInfo culture, string? valu return default; } - private static IDictionary InitializeColorConstantsTable() + private static Dictionary InitializeColorConstantsTable() { - IDictionary table = new Dictionary(StringComparer.OrdinalIgnoreCase); + Dictionary table = new(StringComparer.OrdinalIgnoreCase); foreach (FieldInfo field in typeof(Color).GetFields(BindingFlags.Public | BindingFlags.Static)) { @@ -99,4 +99,10 @@ private static IDictionary InitializeColorConstantsTable() return table; } + + [GeneratedRegex(@"\d+", RegexOptions.Compiled)] + private static partial Regex CreateNumberRegex(); + + [GeneratedRegex("([0-9a-fA-F][^,;.-]\\B{3}){1,2}", RegexOptions.Compiled)] + private static partial Regex CreateHexColorRegex(); } diff --git a/src/ImageSharp.Web/Commands/Converters/ConverterUtility.cs b/src/ImageSharp.Web/Commands/Converters/ConverterUtility.cs index c924e35c..18104b0f 100644 --- a/src/ImageSharp.Web/Commands/Converters/ConverterUtility.cs +++ b/src/ImageSharp.Web/Commands/Converters/ConverterUtility.cs @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Web.Commands.Converters; + internal static class ConverterUtility { /// diff --git a/src/ImageSharp.Web/Commands/Converters/EnumConverter.cs b/src/ImageSharp.Web/Commands/Converters/EnumConverter.cs index 43573145..c2f453f1 100644 --- a/src/ImageSharp.Web/Commands/Converters/EnumConverter.cs +++ b/src/ImageSharp.Web/Commands/Converters/EnumConverter.cs @@ -29,7 +29,7 @@ public sealed class EnumConverter : ICommandConverter { if (string.IsNullOrWhiteSpace(value)) { - return Activator.CreateInstance(propertyType); + return Enum.ToObject(propertyType, 0); } try @@ -51,7 +51,7 @@ public sealed class EnumConverter : ICommandConverter catch { // Just return the default value - return Activator.CreateInstance(propertyType); + return Enum.ToObject(propertyType, 0); } } diff --git a/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs b/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs index 89042ac2..8a7ea7b9 100644 --- a/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs +++ b/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Web.Commands; /// public class PresetOnlyQueryCollectionRequestParser : IRequestParser { - private readonly IDictionary presets; + private readonly Dictionary presets; /// /// The command constant for the preset query parameter. @@ -36,7 +36,7 @@ public CommandCollection ParseRequestCommands(HttpContext context) || !queryCollection.ContainsKey(QueryKey)) { // We return new here and below to ensure the collection is still mutable via events. - return new(); + return new CommandCollection(); } StringValues query = queryCollection[QueryKey]; @@ -46,10 +46,10 @@ public CommandCollection ParseRequestCommands(HttpContext context) return collection; } - return new(); + return new CommandCollection(); } - private static IDictionary ParsePresets( + private static Dictionary ParsePresets( IDictionary unparsedPresets) => unparsedPresets .Select(keyValue => diff --git a/src/ImageSharp.Web/Commands/QueryCollectionRequestParser.cs b/src/ImageSharp.Web/Commands/QueryCollectionRequestParser.cs index 420fc019..6eb73c6d 100644 --- a/src/ImageSharp.Web/Commands/QueryCollectionRequestParser.cs +++ b/src/ImageSharp.Web/Commands/QueryCollectionRequestParser.cs @@ -18,7 +18,7 @@ public CommandCollection ParseRequestCommands(HttpContext context) if (query is null || query.Count == 0) { // We return new to ensure the collection is still mutable via events. - return new(); + return new CommandCollection(); } CommandCollection transformed = new(); diff --git a/src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs b/src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs index 8c4a17bb..c50ecbed 100644 --- a/src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs +++ b/src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -23,7 +24,7 @@ public static class ImageSharpBuilderExtensions /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder SetRequestParser(this IImageSharpBuilder builder) + public static IImageSharpBuilder SetRequestParser<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TParser>(this IImageSharpBuilder builder) where TParser : class, IRequestParser { builder.Services.Replace(ServiceDescriptor.Singleton()); @@ -50,7 +51,7 @@ public static IImageSharpBuilder SetRequestParser(this IImageSharpBuilder builde /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder SetCache(this IImageSharpBuilder builder) + public static IImageSharpBuilder SetCache<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCache>(this IImageSharpBuilder builder) where TCache : class, IImageCache { builder.Services.Replace(ServiceDescriptor.Singleton()); @@ -77,7 +78,7 @@ public static IImageSharpBuilder SetCache(this IImageSharpBuilder builder, Func< /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder SetCacheKey(this IImageSharpBuilder builder) + public static IImageSharpBuilder SetCacheKey<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCacheKey>(this IImageSharpBuilder builder) where TCacheKey : class, ICacheKey { builder.Services.Replace(ServiceDescriptor.Singleton()); @@ -104,7 +105,7 @@ public static IImageSharpBuilder SetCacheKey(this IImageSharpBuilder builder, Fu /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder SetCacheHash(this IImageSharpBuilder builder) + public static IImageSharpBuilder SetCacheHash<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCacheHash>(this IImageSharpBuilder builder) where TCacheHash : class, ICacheHash { builder.Services.Replace(ServiceDescriptor.Singleton()); @@ -131,7 +132,7 @@ public static IImageSharpBuilder SetCacheHash(this IImageSharpBuilder builder, F /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder AddProvider(this IImageSharpBuilder builder) + public static IImageSharpBuilder AddProvider<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>(this IImageSharpBuilder builder) where TProvider : class, IImageProvider { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); @@ -161,10 +162,10 @@ public static IImageSharpBuilder AddProvider(this IImageSharpBuilder /// The core builder. /// The zero-based index at which the provider should be inserted. /// The . - public static IImageSharpBuilder InsertProvider(this IImageSharpBuilder builder, int index) + public static IImageSharpBuilder InsertProvider<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>(this IImageSharpBuilder builder, int index) where TProvider : class, IImageProvider { - var descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList(); + List descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList(); descriptors.RemoveAll(x => x.GetImplementationType() == typeof(TProvider)); descriptors.Insert(index, ServiceDescriptor.Singleton()); @@ -185,7 +186,7 @@ public static IImageSharpBuilder InsertProvider(this IImageSharpBuild public static IImageSharpBuilder InsertProvider(this IImageSharpBuilder builder, int index, Func implementationFactory) where TProvider : class, IImageProvider { - var descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList(); + List descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList(); descriptors.RemoveAll(x => x.GetImplementationType() == typeof(TProvider)); descriptors.Insert(index, ServiceDescriptor.Singleton(implementationFactory)); @@ -231,7 +232,7 @@ public static IImageSharpBuilder ClearProviders(this IImageSharpBuilder builder) /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder AddProcessor(this IImageSharpBuilder builder) + public static IImageSharpBuilder AddProcessor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this IImageSharpBuilder builder) where T : class, IImageWebProcessor { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); @@ -290,7 +291,7 @@ public static IImageSharpBuilder ClearProcessors(this IImageSharpBuilder builder /// The type of class implementing to add. /// The core builder. /// The . - public static IImageSharpBuilder AddConverter(this IImageSharpBuilder builder) + public static IImageSharpBuilder AddConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConverter>(this IImageSharpBuilder builder) where TConverter : class, ICommandConverter { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); @@ -343,21 +344,6 @@ public static IImageSharpBuilder ClearConverters(this IImageSharpBuilder builder return builder; } - /// - /// Registers an action used to configure a particular type of options. - /// - /// The options type to be configured. - /// The core builder. - /// The configuration being bound. - /// The . - public static IImageSharpBuilder Configure(this IImageSharpBuilder builder, IConfiguration config) - where TOptions : class - { - builder.Services.Configure(config); - - return builder; - } - /// /// Registers an action used to configure a particular type of options. /// diff --git a/src/ImageSharp.Web/ImageSharp.Web.csproj b/src/ImageSharp.Web/ImageSharp.Web.csproj index aaf62cce..89c8539e 100644 --- a/src/ImageSharp.Web/ImageSharp.Web.csproj +++ b/src/ImageSharp.Web/ImageSharp.Web.csproj @@ -27,12 +27,12 @@ - net7.0;net6.0 + net9.0;net8.0 - net6.0 + net8.0 diff --git a/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs b/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs index 6bcde2e0..3ee0b91d 100644 --- a/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs +++ b/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs @@ -346,7 +346,7 @@ private async Task ProcessRequestAsync( { // TODO: Do we need some way to set options based upon processors? DecoderOptions decoderOptions = await this.options.OnBeforeLoadAsync.Invoke(imageCommandContext, this.options.Configuration) - ?? new() { Configuration = this.options.Configuration }; + ?? new DecoderOptions { Configuration = this.options.Configuration }; FormattedImage? image = null; try diff --git a/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs b/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs index fa4c21e6..f2b5f7e8 100644 --- a/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs +++ b/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs @@ -41,7 +41,7 @@ public class ImageSharpMiddlewareOptions /// Gets or sets the recyclable memorystream manager used for managing pooled stream /// buffers independently from image buffer pooling. /// - public RecyclableMemoryStreamManager MemoryStreamManager { get; set; } = new RecyclableMemoryStreamManager(); + public RecyclableMemoryStreamManager MemoryStreamManager { get; set; } = new(); /// /// Gets or sets a value indicating whether to use culture-independent (invariant) diff --git a/src/ImageSharp.Web/Processors/ResizeWebProcessor.cs b/src/ImageSharp.Web/Processors/ResizeWebProcessor.cs index 4004bfba..a4fee9f2 100644 --- a/src/ImageSharp.Web/Processors/ResizeWebProcessor.cs +++ b/src/ImageSharp.Web/Processors/ResizeWebProcessor.cs @@ -129,7 +129,7 @@ public FormattedImage Process( ResizeMode mode = GetMode(commands, parser, culture); - return new() + return new ResizeOptions { Size = size, CenterCoordinates = GetCenter(image, orientation, commands, parser, culture), diff --git a/src/ImageSharp.Web/Providers/PhysicalFileSystemProvider.cs b/src/ImageSharp.Web/Providers/PhysicalFileSystemProvider.cs index 7634e20f..62514b9b 100644 --- a/src/ImageSharp.Web/Providers/PhysicalFileSystemProvider.cs +++ b/src/ImageSharp.Web/Providers/PhysicalFileSystemProvider.cs @@ -56,6 +56,6 @@ private static PhysicalFileProvider GetProvider( { Guard.NotNull(options, nameof(options)); Guard.NotNull(environment, nameof(environment)); - return new(GetProviderRoot(options.Value, environment.WebRootPath, environment.ContentRootPath)); + return new PhysicalFileProvider(GetProviderRoot(options.Value, environment.WebRootPath, environment.ContentRootPath)); } } diff --git a/src/ImageSharp.Web/RequestAuthorizationUtilities.cs b/src/ImageSharp.Web/RequestAuthorizationUtilities.cs index 970a2e89..d792c31a 100644 --- a/src/ImageSharp.Web/RequestAuthorizationUtilities.cs +++ b/src/ImageSharp.Web/RequestAuthorizationUtilities.cs @@ -124,7 +124,7 @@ public void StripUnknownCommands(CommandCollection commands) /// The command collection handling. /// The computed HMAC. public string? ComputeHMAC(HostString host, PathString path, QueryString queryString, CommandHandling handling) - => this.ComputeHMAC(host, path, queryString, new(QueryHelpers.ParseQuery(queryString.Value)), handling); + => this.ComputeHMAC(host, path, queryString, new QueryCollection(QueryHelpers.ParseQuery(queryString.Value)), handling); /// /// Compute a Hash-based Message Authentication Code (HMAC) for request authentication. @@ -207,7 +207,7 @@ private static void ToComponents( } } - private HttpContext ToHttpContext(HostString host, PathString path, QueryString queryString, QueryCollection query) + private DefaultHttpContext ToHttpContext(HostString host, PathString path, QueryString queryString, QueryCollection query) { DefaultHttpContext context = new() { RequestServices = this.serviceProvider }; HttpRequest request = context.Request; diff --git a/src/ImageSharp.Web/Synchronization/RefCountedConcurrentDictionary.cs b/src/ImageSharp.Web/Synchronization/RefCountedConcurrentDictionary.cs index c9c34cab..39fda27e 100644 --- a/src/ImageSharp.Web/Synchronization/RefCountedConcurrentDictionary.cs +++ b/src/ImageSharp.Web/Synchronization/RefCountedConcurrentDictionary.cs @@ -222,12 +222,7 @@ public RefCountedValue(TValue value, int refCount) this.RefCount = refCount; } - public bool Equals( -#if NET5_0_OR_GREATER - RefCountedValue? other) -#else - [System.Diagnostics.CodeAnalysis.AllowNull] RefCountedValue other) -#endif + public bool Equals(RefCountedValue? other) => (other != null) && (this.RefCount == other.RefCount) && EqualityComparer.Default.Equals(this.Value, other.Value); public override bool Equals(object? obj) diff --git a/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBaseline.cs b/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBaseline.cs index f91b3239..ae0fdf85 100644 --- a/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBaseline.cs +++ b/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBaseline.cs @@ -20,12 +20,12 @@ public string Create(string value, uint length) // { // throw new ArgumentOutOfRangeException(nameof(length), $"Value must be greater than or equal to {2} and less than or equal to {64}."); // } - using (var hashAlgorithm = SHA256.Create()) + using (SHA256 hashAlgorithm = SHA256.Create()) { // Concatenate the hash bytes into one long string. int len = (int)length; byte[] hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(value)); - var sb = new StringBuilder(len); + StringBuilder sb = new(len); for (int i = 0; i < len / 2; i++) { sb.Append(hash[i].ToString("X2")); diff --git a/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBenchmarks.cs b/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBenchmarks.cs index 3e816a73..c6d3438c 100644 --- a/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBenchmarks.cs +++ b/tests/ImageSharp.Web.Benchmarks/Caching/CacheHashBenchmarks.cs @@ -13,8 +13,8 @@ public class CacheHashBenchmarks { private const string URL = "http://testwebsite.com/image-12345.jpeg?width=400"; private static readonly IOptions MWOptions = Options.Create(new ImageSharpMiddlewareOptions()); - private static readonly SHA256CacheHash Sha256Hasher = new SHA256CacheHash(MWOptions); - private static readonly CacheHashBaseline NaiveSha256Hasher = new CacheHashBaseline(); + private static readonly SHA256CacheHash Sha256Hasher = new(MWOptions); + private static readonly CacheHashBaseline NaiveSha256Hasher = new(); [Benchmark(Baseline = true, Description = "Baseline Sha256Hasher")] public string HashUsingBaselineHash() => NaiveSha256Hasher.Create(URL, 12); diff --git a/tests/ImageSharp.Web.Benchmarks/Caching/CacheKeyBenchmarks.cs b/tests/ImageSharp.Web.Benchmarks/Caching/CacheKeyBenchmarks.cs index b04d5fb6..d3982c24 100644 --- a/tests/ImageSharp.Web.Benchmarks/Caching/CacheKeyBenchmarks.cs +++ b/tests/ImageSharp.Web.Benchmarks/Caching/CacheKeyBenchmarks.cs @@ -57,7 +57,7 @@ public class CacheKeyBenchmarks private static HttpContext CreateContext() { - var httpContext = new DefaultHttpContext(); + DefaultHttpContext httpContext = new(); httpContext.Request.Scheme = Uri.UriSchemeHttp; httpContext.Request.Host = new HostString("testwebsite.com"); httpContext.Request.PathBase = "/images"; diff --git a/tests/ImageSharp.Web.Benchmarks/Caching/StringJoinBenchmarks.cs b/tests/ImageSharp.Web.Benchmarks/Caching/StringJoinBenchmarks.cs index 775d705d..e237630d 100644 --- a/tests/ImageSharp.Web.Benchmarks/Caching/StringJoinBenchmarks.cs +++ b/tests/ImageSharp.Web.Benchmarks/Caching/StringJoinBenchmarks.cs @@ -26,7 +26,7 @@ public string JoinUsingStringBuilder() const char separator = '/'; // Each key substring char + separator + key - var sb = new StringBuilder((this.CacheFolderDepth * 2) + Key.Length); + StringBuilder sb = new((this.CacheFolderDepth * 2) + Key.Length); ReadOnlySpan paths = keySpan.Slice(0, this.CacheFolderDepth); for (int i = 0; i < paths.Length; i++) { diff --git a/tests/ImageSharp.Web.Benchmarks/Caching/ToHexBenchmarks.cs b/tests/ImageSharp.Web.Benchmarks/Caching/ToHexBenchmarks.cs index ec6ec7b2..22784750 100644 --- a/tests/ImageSharp.Web.Benchmarks/Caching/ToHexBenchmarks.cs +++ b/tests/ImageSharp.Web.Benchmarks/Caching/ToHexBenchmarks.cs @@ -18,7 +18,7 @@ public class ToHexBenchmarks public string StringBuilderToHex() { const int len = 12; - var sb = new StringBuilder(len); + StringBuilder sb = new(len); for (int i = 0; i < len / 2; i++) { sb.Append(Bytes[i].ToString("x2")); @@ -56,7 +56,7 @@ public string CustomToHex() private static byte[] Hash() { - using (var hashAlgorithm = SHA256.Create()) + using (SHA256 hashAlgorithm = SHA256.Create()) { // Concatenate the hash bytes into one long string. string value = "http://testwebsite.com/image-12345.jpeg?width=400"; diff --git a/tests/ImageSharp.Web.Benchmarks/ImageSharp.Web.Benchmarks.csproj b/tests/ImageSharp.Web.Benchmarks/ImageSharp.Web.Benchmarks.csproj index e1db5d1a..970371f6 100644 --- a/tests/ImageSharp.Web.Benchmarks/ImageSharp.Web.Benchmarks.csproj +++ b/tests/ImageSharp.Web.Benchmarks/ImageSharp.Web.Benchmarks.csproj @@ -12,18 +12,18 @@ - net7.0;net6.0 + net9.0;net8.0 - net6.0 + net8.0 - + - + diff --git a/tests/ImageSharp.Web.Tests/Caching/CacheHashTests.cs b/tests/ImageSharp.Web.Tests/Caching/CacheHashTests.cs index ea2f4d25..7c02bef5 100644 --- a/tests/ImageSharp.Web.Tests/Caching/CacheHashTests.cs +++ b/tests/ImageSharp.Web.Tests/Caching/CacheHashTests.cs @@ -55,7 +55,7 @@ public void CacheHashLengthIsIdentical() private static string CreateLongString() { const int Length = 2048; - var sb = new StringBuilder(Length); + StringBuilder sb = new(Length); for (int i = 0; i < Length; i++) { diff --git a/tests/ImageSharp.Web.Tests/Caching/CacheKeyTests.cs b/tests/ImageSharp.Web.Tests/Caching/CacheKeyTests.cs index 90317b67..a5871427 100644 --- a/tests/ImageSharp.Web.Tests/Caching/CacheKeyTests.cs +++ b/tests/ImageSharp.Web.Tests/Caching/CacheKeyTests.cs @@ -19,7 +19,7 @@ public class CacheKeyTests public void UriRelativeCacheKey_Is_Relative() { HttpContext context = CreateHttpContext(); - var commands = new CommandCollection() + CommandCollection commands = new() { { "Width", "400" } }; @@ -34,7 +34,7 @@ public void UriRelativeCacheKey_Is_Relative() public void UriRelativeLowerInvariantCacheKey_Is_RelativeAndLowercase() { HttpContext context = CreateHttpContext(); - var commands = new CommandCollection() + CommandCollection commands = new() { { "Width", "400" } }; @@ -49,7 +49,7 @@ public void UriRelativeLowerInvariantCacheKey_Is_RelativeAndLowercase() public void UriAbsoluteCacheKey_Is_Absolute() { HttpContext context = CreateHttpContext(); - var commands = new CommandCollection() + CommandCollection commands = new() { { "Width", "400" } }; @@ -64,7 +64,7 @@ public void UriAbsoluteCacheKey_Is_Absolute() public void UriAbsoluteLowerInvariantCacheKey_Is_AbsoluteAndLowercase() { HttpContext context = CreateHttpContext(); - var commands = new CommandCollection() + CommandCollection commands = new() { { "Width", "400" } }; @@ -79,7 +79,7 @@ public void UriAbsoluteLowerInvariantCacheKey_Is_AbsoluteAndLowercase() public void LegacyV1CacheKey_Matches_V1_Behavior() { HttpContext context = CreateHttpContext(); - var commands = new CommandCollection() + CommandCollection commands = new() { { "Width", "400" } }; @@ -92,7 +92,7 @@ public void LegacyV1CacheKey_Matches_V1_Behavior() private static HttpContext CreateHttpContext() { - var httpContext = new DefaultHttpContext(); + DefaultHttpContext httpContext = new(); httpContext.Request.Scheme = Uri.UriSchemeHttp; httpContext.Request.Host = new HostString("Testwebsite.com"); httpContext.Request.PathBase = "/Images"; diff --git a/tests/ImageSharp.Web.Tests/Caching/HexEncoderTests.cs b/tests/ImageSharp.Web.Tests/Caching/HexEncoderTests.cs index 21eb5203..8bc5ada7 100644 --- a/tests/ImageSharp.Web.Tests/Caching/HexEncoderTests.cs +++ b/tests/ImageSharp.Web.Tests/Caching/HexEncoderTests.cs @@ -13,7 +13,7 @@ public class HexEncoderTests public void HexEncoderOutputIsCorrect() { byte[] hash = Hash(); - var sb = new StringBuilder(hash.Length * 2); + StringBuilder sb = new(hash.Length * 2); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("x2")); @@ -27,7 +27,7 @@ public void HexEncoderOutputIsCorrect() private static byte[] Hash() { - using (var hashAlgorithm = SHA256.Create()) + using (SHA256 hashAlgorithm = SHA256.Create()) { // Concatenate the hash bytes into one long string. const string Value = "http://testwebsite.com/image-12345.jpeg?width=400"; diff --git a/tests/ImageSharp.Web.Tests/Caching/ImageCacheMetadataTests.cs b/tests/ImageSharp.Web.Tests/Caching/ImageCacheMetadataTests.cs index 93358615..ac0df442 100644 --- a/tests/ImageSharp.Web.Tests/Caching/ImageCacheMetadataTests.cs +++ b/tests/ImageSharp.Web.Tests/Caching/ImageCacheMetadataTests.cs @@ -7,8 +7,8 @@ namespace SixLabors.ImageSharp.Web.Tests.Caching; public class ImageCacheMetaDataTests { - private static readonly DateTime SourceLastWriteTimeUtc = new DateTime(1980, 11, 3); - private static readonly DateTime CacheLastWriteTimeUtc = new DateTime(1980, 11, 4); + private static readonly DateTime SourceLastWriteTimeUtc = new(1980, 11, 3); + private static readonly DateTime CacheLastWriteTimeUtc = new(1980, 11, 4); private static readonly TimeSpan MaxAge = TimeSpan.FromDays(7); private const string ContentType = "image/jpeg"; private const long ContentLength = 1234; @@ -20,7 +20,7 @@ public class ImageCacheMetaDataTests [Fact] public void ConstructorAssignsProperties() { - var meta = new ImageCacheMetadata( + ImageCacheMetadata meta = new( SourceLastWriteTimeUtc, CacheLastWriteTimeUtc, ContentType, @@ -37,13 +37,13 @@ public void ConstructorAssignsProperties() [Fact] public void EqualityChecksAreCorrect() { - var meta = new ImageCacheMetadata( + ImageCacheMetadata meta = new( SourceLastWriteTimeUtc, CacheLastWriteTimeUtc, ContentType, MaxAge, ContentLength); - var meta2 = new ImageCacheMetadata( + ImageCacheMetadata meta2 = new( meta.SourceLastWriteTimeUtc, meta.CacheLastWriteTimeUtc, meta.ContentType, @@ -52,7 +52,7 @@ public void EqualityChecksAreCorrect() Assert.Equal(meta, meta2); - var meta3 = new ImageCacheMetadata( + ImageCacheMetadata meta3 = new( SourceLastWriteTimeUtc, CacheLastWriteTimeUtc, "image/png", diff --git a/tests/ImageSharp.Web.Tests/Caching/ImageMetaDataTests.cs b/tests/ImageSharp.Web.Tests/Caching/ImageMetaDataTests.cs index dad80db1..2eb63273 100644 --- a/tests/ImageSharp.Web.Tests/Caching/ImageMetaDataTests.cs +++ b/tests/ImageSharp.Web.Tests/Caching/ImageMetaDataTests.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Web.Tests.Caching; public class ImageMetaDataTests { - private static readonly DateTime LastWriteTimeUtc = new DateTime(1980, 11, 4); + private static readonly DateTime LastWriteTimeUtc = new(1980, 11, 4); private static readonly TimeSpan MaxAge = TimeSpan.FromDays(7); private const long ContentLength = 1234; @@ -18,7 +18,7 @@ public class ImageMetaDataTests [Fact] public void ConstructorAssignsProperties() { - var meta = new ImageMetadata(LastWriteTimeUtc, MaxAge, ContentLength); + ImageMetadata meta = new(LastWriteTimeUtc, MaxAge, ContentLength); Assert.Equal(LastWriteTimeUtc, meta.LastWriteTimeUtc); Assert.Equal(MaxAge, meta.CacheControlMaxAge); Assert.Equal(ContentLength, meta.ContentLength); @@ -27,11 +27,11 @@ public void ConstructorAssignsProperties() [Fact] public void EqualityChecksAreCorrect() { - var meta = new ImageMetadata(LastWriteTimeUtc, MaxAge, ContentLength); - var meta2 = new ImageMetadata(meta.LastWriteTimeUtc, meta.CacheControlMaxAge, meta.ContentLength); + ImageMetadata meta = new(LastWriteTimeUtc, MaxAge, ContentLength); + ImageMetadata meta2 = new(meta.LastWriteTimeUtc, meta.CacheControlMaxAge, meta.ContentLength); Assert.Equal(meta, meta2); - var meta3 = new ImageMetadata(meta.LastWriteTimeUtc, TimeSpan.FromDays(1), 4321); + ImageMetadata meta3 = new(meta.LastWriteTimeUtc, TimeSpan.FromDays(1), 4321); Assert.NotEqual(meta, meta3); } } diff --git a/tests/ImageSharp.Web.Tests/Caching/PhysicialFileSystemCacheTests.cs b/tests/ImageSharp.Web.Tests/Caching/PhysicialFileSystemCacheTests.cs index 966d2336..afe3953c 100644 --- a/tests/ImageSharp.Web.Tests/Caching/PhysicialFileSystemCacheTests.cs +++ b/tests/ImageSharp.Web.Tests/Caching/PhysicialFileSystemCacheTests.cs @@ -36,7 +36,7 @@ public void FilePathMatchesReference(string key, int cacheFolderDepth, string ex #endif public void GetCacheRoot(string cacheFolder, string cacheRootPath, string webRootPath, string contentRootPath, string expected) { - var cacheOptions = new PhysicalFileSystemCacheOptions + PhysicalFileSystemCacheOptions cacheOptions = new() { CacheFolder = cacheFolder, CacheRootPath = cacheRootPath @@ -53,7 +53,7 @@ public void GetCacheRoot(string cacheFolder, string cacheRootPath, string webRoo [InlineData("cacheFolder", null, "", "C:\\root\\")] public void GetCacheRootThrows(string cacheFolder, string cacheRootPath, string webRootPath, string contentRootPath) { - var cacheOptions = new PhysicalFileSystemCacheOptions + PhysicalFileSystemCacheOptions cacheOptions = new() { CacheFolder = cacheFolder, CacheRootPath = cacheRootPath diff --git a/tests/ImageSharp.Web.Tests/Commands/CommandCollectionTests.cs b/tests/ImageSharp.Web.Tests/Commands/CommandCollectionTests.cs index 1001610b..b46d9295 100644 --- a/tests/ImageSharp.Web.Tests/Commands/CommandCollectionTests.cs +++ b/tests/ImageSharp.Web.Tests/Commands/CommandCollectionTests.cs @@ -11,7 +11,7 @@ public class CommandCollectionTests public void CanAddCommands() { CommandCollection collection = new(); - collection.Add(new("a", "b")); + collection.Add(new KeyValuePair("a", "b")); Assert.Single(collection); } @@ -19,8 +19,8 @@ public void CanAddCommands() public void CannotAddDuplicateCommands() { CommandCollection collection = new(); - collection.Add(new("a", "b")); - Assert.Throws(() => collection.Add(new("a", "b"))); + collection.Add(new KeyValuePair("a", "b")); + Assert.Throws(() => collection.Add(new KeyValuePair("a", "b"))); Assert.Single(collection); } @@ -30,7 +30,7 @@ public void CanReadCommands() const string key = "a"; const string value = "b"; CommandCollection collection = new(); - collection.Add(new(key, value)); + collection.Add(new KeyValuePair(key, value)); Assert.Equal(value, collection[key]); } @@ -59,8 +59,8 @@ public void CanInsertCommands() public void CannotInsertDuplicateCommands() { CommandCollection collection = new(); - collection.Add(new("a", "b")); - Assert.Throws(() => collection.Insert(0, new("a", "b"))); + collection.Add(new KeyValuePair("a", "b")); + Assert.Throws(() => collection.Insert(0, new KeyValuePair("a", "b"))); Assert.Single(collection); } @@ -88,7 +88,7 @@ public void CanInsertCommandsViaKey() public void CannotInsertDuplicateCommandsViaKey() { CommandCollection collection = new(); - collection.Add(new("a", "b")); + collection.Add(new KeyValuePair("a", "b")); Assert.Throws(() => collection.Insert(0, "a", "b")); Assert.Single(collection); } @@ -190,7 +190,7 @@ public void KeysAreOrdered() CommandCollection collection = new(); foreach (string key in keys) { - collection.Insert(0, new(key, null)); + collection.Insert(0, new KeyValuePair(key, null)); } int index = 0; diff --git a/tests/ImageSharp.Web.Tests/Commands/CommandParserTests.cs b/tests/ImageSharp.Web.Tests/Commands/CommandParserTests.cs index a8b7ed70..bb1be089 100644 --- a/tests/ImageSharp.Web.Tests/Commands/CommandParserTests.cs +++ b/tests/ImageSharp.Web.Tests/Commands/CommandParserTests.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Web.Tests.Commands; public class CommandParserTests { private static readonly CultureInfo Inv = CultureInfo.InvariantCulture; - private static readonly CultureInfo Dk = new CultureInfo("da-DK"); + private static readonly CultureInfo Dk = new("da-DK"); private const double Pi = 3.14159265358979; private static readonly string PiStringInv = Pi.ToString(CultureInfo.InvariantCulture); @@ -20,8 +20,8 @@ public class CommandParserTests private static readonly double RoundedPi = Math.Round(Pi, MidpointRounding.AwayFromZero); public static TheoryData IntegralValuesInv { get; } - = new TheoryData - { + = new() + { { (sbyte)1, "1", Inv }, { (byte)1, "1", Inv }, { (short)1, "1", Inv }, @@ -36,8 +36,8 @@ public class CommandParserTests }; public static TheoryData IntegralValuesDk { get; } - = new TheoryData - { + = new() + { { (sbyte)1, "1", Dk }, { (byte)1, "1", Dk }, { (short)1, "1", Dk }, @@ -52,8 +52,8 @@ public class CommandParserTests }; public static TheoryData RealValuesInv { get; } - = new TheoryData - { + = new() + { { (sbyte)RoundedPi, PiStringInv, Inv }, { (byte)RoundedPi, PiStringInv, Inv }, { (short)RoundedPi, PiStringInv, Inv }, @@ -68,8 +68,8 @@ public class CommandParserTests }; public static TheoryData RealValuesDanish { get; } - = new TheoryData - { + = new() + { { (sbyte)RoundedPi, PiStringDk, Dk }, { (byte)RoundedPi, PiStringDk, Dk }, { (short)RoundedPi, PiStringDk, Dk }, @@ -84,45 +84,45 @@ public class CommandParserTests }; public static TheoryData EnumValues { get; } - = new TheoryData - { + = new() + { { ResizeMode.Max, "max", Inv }, { ResizeMode.Crop, "this is not, an enum value", Inv }, // Unknown returns default }; public static TheoryData IntegralArrays { get; } - = new TheoryData - { + = new() + { { new[] { 1, 2, 3, 4 }, ToNumericList(Inv, 1, 2, 3, 4), Inv }, }; public static TheoryData RealArraysInv { get; } - = new TheoryData - { + = new() + { { new[] { 1.667F, 2.667F, 3.667F, 4.667F }, ToNumericList(Inv, 1.667F, 2.667F, 3.667F, 4.667F), Inv }, }; public static TheoryData RealArraysDk { get; } - = new TheoryData - { + = new() + { { new[] { 1.667F, 2.667F, 3.667F, 4.667F }, ToNumericList(Dk, 1.667F, 2.667F, 3.667F, 4.667F), Dk }, }; public static TheoryData IntegralLists { get; } - = new TheoryData - { + = new() + { { new List { 1, 2, 3, 4 }, ToNumericList(Inv, 1, 2, 3, 4), Inv }, }; public static TheoryData, string, CultureInfo> RealLists { get; } - = new TheoryData, string, CultureInfo> - { + = new() + { { new List { 1.667F, 2.667F, 3.667F, 4.667F }, "1.667,2.667,3.667,4.667", Inv }, }; public static TheoryData ColorValuesInv { get; } - = new TheoryData - { + = new() + { { default, string.Empty, Inv }, { Color.White, ToNumericList(Inv, 255, 255, 255), Inv }, { Color.Transparent, ToNumericList(Inv, 0, 0, 0, 0), Inv }, @@ -133,8 +133,8 @@ public class CommandParserTests }; public static TheoryData ColorValuesDk { get; } - = new TheoryData - { + = new() + { { default, string.Empty, Dk }, { Color.White, ToNumericList(Dk, 255, 255, 255), Dk }, { Color.Transparent, ToNumericList(Dk, 0, 0, 0, 0), Dk }, @@ -169,7 +169,7 @@ public void CommandParserCanConvert(T expected, string param, CultureInfo cul [Fact] public void CommandParseThrowsCorrectly() { - var emptyParser = new CommandParser(Array.Empty()); + CommandParser emptyParser = new(Array.Empty()); Assert.Throws( () => emptyParser.ParseValue("true", CultureInfo.InvariantCulture)); @@ -177,7 +177,7 @@ public void CommandParseThrowsCorrectly() private static CommandParser GetCommandParser() { - var converters = new List + List converters = new() { new IntegralNumberConverter(), new IntegralNumberConverter(), @@ -232,8 +232,8 @@ private static CommandParser GetCommandParser() private static string ToNumericList(CultureInfo culture, params T[] values) where T : IConvertible { - var sb = new StringBuilder(); - var ls = culture.TextInfo.ListSeparator[0]; + StringBuilder sb = new(); + char ls = culture.TextInfo.ListSeparator[0]; for (int i = 0; i < values.Length; i++) { diff --git a/tests/ImageSharp.Web.Tests/Commands/PresetOnlyQueryCollectionRequestParserTests.cs b/tests/ImageSharp.Web.Tests/Commands/PresetOnlyQueryCollectionRequestParserTests.cs index 39446044..d789c080 100644 --- a/tests/ImageSharp.Web.Tests/Commands/PresetOnlyQueryCollectionRequestParserTests.cs +++ b/tests/ImageSharp.Web.Tests/Commands/PresetOnlyQueryCollectionRequestParserTests.cs @@ -87,7 +87,7 @@ public void PresetOnlyQueryCollectionRequestParserCommandsWithoutMatchingPreset( private static HttpContext CreateHttpContext(string query) { - var httpContext = new DefaultHttpContext(); + DefaultHttpContext httpContext = new(); httpContext.Request.Path = "/testwebsite.com/image-12345.jpeg"; httpContext.Request.QueryString = new QueryString(query); return httpContext; diff --git a/tests/ImageSharp.Web.Tests/Commands/QueryCollectionUriParserTests.cs b/tests/ImageSharp.Web.Tests/Commands/QueryCollectionUriParserTests.cs index 1b01577d..3a7ab4da 100644 --- a/tests/ImageSharp.Web.Tests/Commands/QueryCollectionUriParserTests.cs +++ b/tests/ImageSharp.Web.Tests/Commands/QueryCollectionUriParserTests.cs @@ -13,8 +13,8 @@ public void QueryCollectionParserExtractsCommands() { CommandCollection expected = new() { - { new("width", "400") }, - { new("height", "200") } + { new KeyValuePair("width", "400") }, + { new KeyValuePair("height", "200") } }; HttpContext context = CreateHttpContext(); @@ -25,7 +25,7 @@ public void QueryCollectionParserExtractsCommands() private static HttpContext CreateHttpContext() { - var httpContext = new DefaultHttpContext(); + DefaultHttpContext httpContext = new(); httpContext.Request.Path = "/testwebsite.com/image-12345.jpeg"; // Duplicate height param to test replacements diff --git a/tests/ImageSharp.Web.Tests/DependencyInjection/ServiceRegistrationExtensionsTests.cs b/tests/ImageSharp.Web.Tests/DependencyInjection/ServiceRegistrationExtensionsTests.cs index 4a22a158..8751086c 100644 --- a/tests/ImageSharp.Web.Tests/DependencyInjection/ServiceRegistrationExtensionsTests.cs +++ b/tests/ImageSharp.Web.Tests/DependencyInjection/ServiceRegistrationExtensionsTests.cs @@ -44,7 +44,7 @@ private static bool IsServiceImplementationFactory(Se [Fact] public void DefaultServicesAreRegistered() { - var services = new ServiceCollection(); + ServiceCollection services = new(); services.AddImageSharp(); Assert.Single(services, IsService); @@ -104,7 +104,7 @@ public void DefaultServicesAreRegistered() [Fact] public void CanSetRequestParser() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.SetRequestParser(); @@ -119,7 +119,7 @@ public void CanSetRequestParser() [Fact] public void CanSetCache() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.SetCache(); @@ -134,7 +134,7 @@ public void CanSetCache() [Fact] public void CanSetCacheKey() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.SetCacheKey(); @@ -149,7 +149,7 @@ public void CanSetCacheKey() [Fact] public void CanSetCacheHash() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.SetCacheHash(); @@ -164,7 +164,7 @@ public void CanSetCacheHash() [Fact] public void CanAddRemoveImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProvider(); @@ -178,7 +178,7 @@ public void CanAddRemoveImageProviders() [Fact] public void CanInsertRemoveImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.InsertProvider(0); @@ -197,7 +197,7 @@ public void CanInsertRemoveImageProviders() [Fact] public void CanInsertIdempotentImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.InsertProvider(0); @@ -217,7 +217,7 @@ public void CanInsertIdempotentImageProviders() [Fact] public void CanAddRemoveFactoryImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProvider(_ => new MockImageProvider()); @@ -231,7 +231,7 @@ public void CanAddRemoveFactoryImageProviders() [Fact] public void CanInsertIdempotentFactoryImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.InsertProvider(0, _ => new MockImageProvider()); @@ -251,7 +251,7 @@ public void CanInsertIdempotentFactoryImageProviders() [Fact] public void CanInsertRemoveFactoryImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.InsertProvider(0, _ => new MockImageProvider()); @@ -270,7 +270,7 @@ public void CanInsertRemoveFactoryImageProviders() [Fact] public void CanAddRemoveAllImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProvider(); @@ -284,7 +284,7 @@ public void CanAddRemoveAllImageProviders() [Fact] public void CanAddRemoveAllFactoryImageProviders() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProvider(_ => new MockImageProvider()); @@ -298,7 +298,7 @@ public void CanAddRemoveAllFactoryImageProviders() [Fact] public void CanAddRemoveImageProcessors() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProcessor(); @@ -312,7 +312,7 @@ public void CanAddRemoveImageProcessors() [Fact] public void CanAddRemoveFactoryImageProcessors() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProcessor(_ => new MockWebProcessor()); @@ -326,7 +326,7 @@ public void CanAddRemoveFactoryImageProcessors() [Fact] public void CanAddRemoveAllImageProcessors() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProcessor(); @@ -340,7 +340,7 @@ public void CanAddRemoveAllImageProcessors() [Fact] public void CanAddRemoveAllFactoryImageProcessors() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddProcessor(_ => new MockWebProcessor()); @@ -354,7 +354,7 @@ public void CanAddRemoveAllFactoryImageProcessors() [Fact] public void CanAddRemoveCommandConverters() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddConverter(); @@ -368,7 +368,7 @@ public void CanAddRemoveCommandConverters() [Fact] public void CanAddRemoveFactoryCommandConverters() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddConverter(_ => new MockCommandConverter()); @@ -382,7 +382,7 @@ public void CanAddRemoveFactoryCommandConverters() [Fact] public void CanAddRemoveAllCommandConverters() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddConverter(); @@ -396,7 +396,7 @@ public void CanAddRemoveAllCommandConverters() [Fact] public void CanAddRemoveAllFactoryCommandConverters() { - var services = new ServiceCollection(); + ServiceCollection services = new(); IImageSharpBuilder builder = services.AddImageSharp(); builder.AddConverter(_ => new MockCommandConverter()); diff --git a/tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj b/tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj index 8ce5cb2e..b645beae 100644 --- a/tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj +++ b/tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj @@ -8,12 +8,12 @@ - net7.0;net6.0 + net9.0;net8.0 - net6.0 + net8.0 diff --git a/tests/ImageSharp.Web.Tests/Processors/AutoOrientWebProcessorTests.cs b/tests/ImageSharp.Web.Tests/Processors/AutoOrientWebProcessorTests.cs index 706c8f31..c6e73626 100644 --- a/tests/ImageSharp.Web.Tests/Processors/AutoOrientWebProcessorTests.cs +++ b/tests/ImageSharp.Web.Tests/Processors/AutoOrientWebProcessorTests.cs @@ -21,13 +21,13 @@ public void AutoOrientWebProcessor_UpdatesOrientation() CommandCollection commands = new() { - { new(AutoOrientWebProcessor.AutoOrient, bool.TrueString) } + { new KeyValuePair(AutoOrientWebProcessor.AutoOrient, bool.TrueString) } }; const ushort tl = 1; const ushort br = 3; using Image image = new(1, 1); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, br); Assert.True(image.Metadata.ExifProfile.TryGetValue(ExifTag.Orientation, out IExifValue orientation)); diff --git a/tests/ImageSharp.Web.Tests/Processors/BackgroundColorWebProcessorTests.cs b/tests/ImageSharp.Web.Tests/Processors/BackgroundColorWebProcessorTests.cs index 6ad05672..7e4080fe 100644 --- a/tests/ImageSharp.Web.Tests/Processors/BackgroundColorWebProcessorTests.cs +++ b/tests/ImageSharp.Web.Tests/Processors/BackgroundColorWebProcessorTests.cs @@ -20,13 +20,13 @@ public void BackgroundColorWebProcessor_UpdatesColor() CommandCollection commands = new() { - { new(BackgroundColorWebProcessor.Color, nameof(Color.Orange)) } + { new KeyValuePair(BackgroundColorWebProcessor.Color, nameof(Color.Orange)) } }; - using var image = new Image(1, 1); + using Image image = new(1, 1); Assert.True(Color.Transparent.Equals(image[0, 0])); - using var formatted = new FormattedImage(image, PngFormat.Instance); + using FormattedImage formatted = new(image, PngFormat.Instance); new BackgroundColorWebProcessor().Process(formatted, null, commands, parser, culture); Assert.True(Color.Orange.Equals(image[0, 0])); @@ -44,7 +44,7 @@ public void BackgroundColorWebProcessor_CanReportAlphaRequirements(string color) CommandCollection commands = new() { - { new(BackgroundColorWebProcessor.Color, color) } + { new KeyValuePair(BackgroundColorWebProcessor.Color, color) } }; Assert.True(new BackgroundColorWebProcessor().RequiresTrueColorPixelFormat(commands, parser, culture)); diff --git a/tests/ImageSharp.Web.Tests/Processors/FormatWebProcessorTests.cs b/tests/ImageSharp.Web.Tests/Processors/FormatWebProcessorTests.cs index b54802e4..81bb2c9f 100644 --- a/tests/ImageSharp.Web.Tests/Processors/FormatWebProcessorTests.cs +++ b/tests/ImageSharp.Web.Tests/Processors/FormatWebProcessorTests.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Web.Tests.Processors; public class FormatWebProcessorTests { public static TheoryData FormatNameData { get; } - = new TheoryData + = new() { { BmpFormat.Instance.Name }, { GifFormat.Instance.Name }, @@ -36,11 +36,11 @@ public void FormatWebProcessor_UpdatesFormat() CommandCollection commands = new() { - { new(FormatWebProcessor.Format, GifFormat.Instance.Name) }, + { new KeyValuePair(FormatWebProcessor.Format, GifFormat.Instance.Name) }, }; - using var image = new Image(1, 1); - using var formatted = new FormattedImage(image, PngFormat.Instance); + using Image image = new(1, 1); + using FormattedImage formatted = new(image, PngFormat.Instance); Assert.Equal(formatted.Format, PngFormat.Instance); new FormatWebProcessor(Options.Create(new ImageSharpMiddlewareOptions())) @@ -58,7 +58,7 @@ public void FormatWebProcessor_CanReportAlphaRequirements(string format) CommandCollection commands = new() { - { new(FormatWebProcessor.Format, format) }, + { new KeyValuePair(FormatWebProcessor.Format, format) }, }; FormatWebProcessor processor = new(Options.Create(new ImageSharpMiddlewareOptions())); diff --git a/tests/ImageSharp.Web.Tests/Processors/QualityWebProcessorTests.cs b/tests/ImageSharp.Web.Tests/Processors/QualityWebProcessorTests.cs index d4bae8c1..c3ebd99c 100644 --- a/tests/ImageSharp.Web.Tests/Processors/QualityWebProcessorTests.cs +++ b/tests/ImageSharp.Web.Tests/Processors/QualityWebProcessorTests.cs @@ -23,11 +23,11 @@ public void QualityWebProcessor_UpdatesJpegQuality() CommandCollection commands = new() { - { new(QualityWebProcessor.Quality, "42") }, + { new KeyValuePair(QualityWebProcessor.Quality, "42") }, }; - using var image = new Image(1, 1); - using var formatted = new FormattedImage(image, JpegFormat.Instance); + using Image image = new(1, 1); + using FormattedImage formatted = new(image, JpegFormat.Instance); Assert.Equal(JpegFormat.Instance, formatted.Format); Assert.Equal(typeof(JpegEncoder), formatted.Encoder.GetType()); @@ -47,12 +47,12 @@ public void QualityWebProcessor_UpdatesWebpQuality() CommandCollection commands = new() { { - new(QualityWebProcessor.Quality, "42") + new KeyValuePair(QualityWebProcessor.Quality, "42") }, }; - using var image = new Image(1, 1); - using var formatted = new FormattedImage(image, WebpFormat.Instance); + using Image image = new(1, 1); + using FormattedImage formatted = new(image, WebpFormat.Instance); Assert.Equal(WebpFormat.Instance, formatted.Format); Assert.Equal(typeof(WebpEncoder), formatted.Encoder.GetType()); @@ -67,17 +67,17 @@ public void QualityWebProcessor_UpdatesWebpQuality() [Fact] public void QualityWebProcessor_CanReportAlphaRequirements() { - var converters = new List + List converters = new() { new IntegralNumberConverter(), }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; CommandCollection commands = new() { - { new(QualityWebProcessor.Quality, this.random.Next(1, 100).ToString()) }, + { new KeyValuePair(QualityWebProcessor.Quality, this.random.Next(1, 100).ToString()) }, }; Assert.False(new QualityWebProcessor().RequiresTrueColorPixelFormat(commands, parser, culture)); diff --git a/tests/ImageSharp.Web.Tests/Processors/ResizeWebProcessorTests.cs b/tests/ImageSharp.Web.Tests/Processors/ResizeWebProcessorTests.cs index 62ae8d28..f7793813 100644 --- a/tests/ImageSharp.Web.Tests/Processors/ResizeWebProcessorTests.cs +++ b/tests/ImageSharp.Web.Tests/Processors/ResizeWebProcessorTests.cs @@ -36,7 +36,7 @@ public void ResizeWebProcessor_UpdatesSize(string resampler) const int width = 4; const int height = 6; - var converters = new List + List converters = new() { new IntegralNumberConverter(), new ArrayConverter(), @@ -46,22 +46,22 @@ public void ResizeWebProcessor_UpdatesSize(string resampler) new ColorConverter() }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; CommandCollection commands = new() { // We only need to do this for the unit tests. // Commands generated via URL will automatically be converted to lowecase - { new(ResizeWebProcessor.Sampler, resampler.ToLowerInvariant()) }, - { new(ResizeWebProcessor.Width, width.ToString()) }, - { new(ResizeWebProcessor.Height, height.ToString()) }, - { new(ResizeWebProcessor.Xy, "0,0") }, - { new(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) } + { new KeyValuePair(ResizeWebProcessor.Sampler, resampler.ToLowerInvariant()) }, + { new KeyValuePair(ResizeWebProcessor.Width, width.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Height, height.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Xy, "0,0") }, + { new KeyValuePair(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) } }; - using var image = new Image(1, 1); - using var formatted = new FormattedImage(image, PngFormat.Instance); + using Image image = new(1, 1); + using FormattedImage formatted = new(image, PngFormat.Instance); new ResizeWebProcessor().Process(formatted, null, commands, parser, culture); Assert.Equal(width, image.Width); @@ -83,7 +83,7 @@ public void ResizeWebProcessor_RespectsOrientation_Size(ushort orientation, bool const int width = 4; const int height = 6; - var converters = new List + List converters = new() { new IntegralNumberConverter(), new ArrayConverter(), @@ -93,21 +93,21 @@ public void ResizeWebProcessor_RespectsOrientation_Size(ushort orientation, bool new ColorConverter() }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; CommandCollection commands = new() { - { new(ResizeWebProcessor.Width, width.ToString()) }, - { new(ResizeWebProcessor.Height, height.ToString()) }, - { new(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) } + { new KeyValuePair(ResizeWebProcessor.Width, width.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Height, height.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) } }; - using var image = new Image(1, 1); - image.Metadata.ExifProfile = new(); + using Image image = new(1, 1); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, orientation); - using var formatted = new FormattedImage(image, PngFormat.Instance); + using FormattedImage formatted = new(image, PngFormat.Instance); new ResizeWebProcessor().Process(formatted, null, commands, parser, culture); if (rotated) @@ -139,7 +139,7 @@ public void ResizeWebProcessor_RespectsOrientation_Center(ushort orientation) const float x = .25F; const float y = .5F; - var converters = new List + List converters = new() { new IntegralNumberConverter(), new ArrayConverter(), @@ -149,21 +149,21 @@ public void ResizeWebProcessor_RespectsOrientation_Center(ushort orientation) new ColorConverter() }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; CommandCollection commands = new() { - { new(ResizeWebProcessor.Width, width.ToString()) }, - { new(ResizeWebProcessor.Height, height.ToString()) }, - { new(ResizeWebProcessor.Xy, FormattableString.Invariant($"{x},{y}")) }, - { new(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) } + { new KeyValuePair(ResizeWebProcessor.Width, width.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Height, height.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Xy, FormattableString.Invariant($"{x},{y}")) }, + { new KeyValuePair(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) } }; - using var image = new Image(3, 3); - image.Metadata.ExifProfile = new(); + using Image image = new(3, 3); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, orientation); - using var formatted = new FormattedImage(image, PngFormat.Instance); + using FormattedImage formatted = new(image, PngFormat.Instance); PointF expected = ExifOrientationUtilities.Transform(new Vector2(x, y), Vector2.Zero, Vector2.One, orientation); ResizeOptions options = ResizeWebProcessor.GetResizeOptions(formatted, commands, parser, culture); @@ -182,7 +182,7 @@ public void ResizeWebProcessor_RespectsOrientation_Center(ushort orientation) [InlineData(ExifOrientationMode.LeftBottom)] public void ResizeWebProcessor_RespectsOrientation_Anchor(ushort orientation) { - var converters = new List + List converters = new() { new IntegralNumberConverter(), new ArrayConverter(), @@ -192,11 +192,11 @@ public void ResizeWebProcessor_RespectsOrientation_Anchor(ushort orientation) new ColorConverter() }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; using Image image = new(1, 1); - image.Metadata.ExifProfile = new(); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, orientation); using FormattedImage formatted = new(image, PngFormat.Instance); @@ -204,10 +204,10 @@ public void ResizeWebProcessor_RespectsOrientation_Anchor(ushort orientation) { CommandCollection commands = new() { - { new(ResizeWebProcessor.Width, 4.ToString()) }, - { new(ResizeWebProcessor.Height, 6.ToString()) }, - { new(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) }, - { new(ResizeWebProcessor.Anchor, anchor.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Width, 4.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Height, 6.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) }, + { new KeyValuePair(ResizeWebProcessor.Anchor, anchor.ToString()) }, }; AnchorPositionMode expected = ExifOrientationUtilities.Transform(anchor, orientation); @@ -231,7 +231,7 @@ public void ResizeWebProcessor_CanIgnoreOrientation(ushort orientation) const int width = 4; const int height = 6; - var converters = new List + List converters = new() { new IntegralNumberConverter(), new ArrayConverter(), @@ -241,22 +241,22 @@ public void ResizeWebProcessor_CanIgnoreOrientation(ushort orientation) new ColorConverter() }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; CommandCollection commands = new() { - { new(ResizeWebProcessor.Width, width.ToString()) }, - { new(ResizeWebProcessor.Height, height.ToString()) }, - { new(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) }, - { new(ResizeWebProcessor.Orient, bool.FalseString) } + { new KeyValuePair(ResizeWebProcessor.Width, width.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Height, height.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Mode, nameof(ResizeMode.Stretch)) }, + { new KeyValuePair(ResizeWebProcessor.Orient, bool.FalseString) } }; - using var image = new Image(1, 1); - image.Metadata.ExifProfile = new(); + using Image image = new(1, 1); + image.Metadata.ExifProfile = new ExifProfile(); image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, orientation); - using var formatted = new FormattedImage(image, PngFormat.Instance); + using FormattedImage formatted = new(image, PngFormat.Instance); new ResizeWebProcessor().Process(formatted, null, commands, parser, culture); Assert.Equal(width, image.Width); @@ -273,17 +273,17 @@ public void ResizeWebProcessor_CanIgnoreOrientation(ushort orientation) [InlineData(ResizeMode.Manual, false)] public void ResizeWebProcessor_CanReportAlphaRequirements(ResizeMode resizeMode, bool requiresAlpha) { - var converters = new List + List converters = new() { new EnumConverter(), }; - var parser = new CommandParser(converters); + CommandParser parser = new(converters); CultureInfo culture = CultureInfo.InvariantCulture; CommandCollection commands = new() { - { new(ResizeWebProcessor.Mode, resizeMode.ToString()) }, + { new KeyValuePair(ResizeWebProcessor.Mode, resizeMode.ToString()) }, }; Assert.Equal(requiresAlpha, new ResizeWebProcessor().RequiresTrueColorPixelFormat(commands, parser, culture)); diff --git a/tests/ImageSharp.Web.Tests/Processors/WebProcessingExtensionsTests.cs b/tests/ImageSharp.Web.Tests/Processors/WebProcessingExtensionsTests.cs index e31027c2..4983573c 100644 --- a/tests/ImageSharp.Web.Tests/Processors/WebProcessingExtensionsTests.cs +++ b/tests/ImageSharp.Web.Tests/Processors/WebProcessingExtensionsTests.cs @@ -12,7 +12,7 @@ public class WebProcessingExtensionsTests [Fact] public void WebProcessingExtensions_GetBySupportedCommands() { - var processors = new IImageWebProcessor[] + IImageWebProcessor[] processors = new IImageWebProcessor[] { new QualityWebProcessor(), new ResizeWebProcessor(), @@ -22,9 +22,9 @@ public void WebProcessingExtensions_GetBySupportedCommands() CommandCollection commands = new() { - new(ResizeWebProcessor.Width, null), - new(QualityWebProcessor.Quality, null), - new(ResizeWebProcessor.Height, null) + new KeyValuePair(ResizeWebProcessor.Width, null), + new KeyValuePair(QualityWebProcessor.Quality, null), + new KeyValuePair(ResizeWebProcessor.Height, null) }; IReadOnlyList<(int Index, IImageWebProcessor Processor)> supportedProcessors = processors.OrderBySupportedCommands(commands); @@ -37,7 +37,7 @@ public void WebProcessingExtensions_GetBySupportedCommands() [Fact] public void WebProcessingExtensions_GetBySupportedCommands_Empty() { - var processors = new IImageWebProcessor[] + IImageWebProcessor[] processors = new IImageWebProcessor[] { new MockWebProcessor() }; diff --git a/tests/ImageSharp.Web.Tests/Providers/PhysicalFileSystemProviderTests.cs b/tests/ImageSharp.Web.Tests/Providers/PhysicalFileSystemProviderTests.cs index 26a3b6c2..e8768250 100644 --- a/tests/ImageSharp.Web.Tests/Providers/PhysicalFileSystemProviderTests.cs +++ b/tests/ImageSharp.Web.Tests/Providers/PhysicalFileSystemProviderTests.cs @@ -29,7 +29,7 @@ public class PhysicalFileSystemProviderTests #endif public void GetProviderRoot(string providerRootPath, string webRootPath, string contentRootPath, string expected) { - var providerOptions = new PhysicalFileSystemProviderOptions + PhysicalFileSystemProviderOptions providerOptions = new() { ProviderRootPath = providerRootPath }; @@ -45,7 +45,7 @@ public void GetProviderRoot(string providerRootPath, string webRootPath, string [InlineData(null, "", "C:\\root\\")] public void GetProviderRootThrows(string providerRootPath, string webRootPath, string contentRootPath) { - var providerOptions = new PhysicalFileSystemProviderOptions + PhysicalFileSystemProviderOptions providerOptions = new() { ProviderRootPath = providerRootPath }; diff --git a/tests/ImageSharp.Web.Tests/Synchronization/RefCountedConcurrentDictionaryTests.cs b/tests/ImageSharp.Web.Tests/Synchronization/RefCountedConcurrentDictionaryTests.cs index c8ad2e6b..49ae1744 100644 --- a/tests/ImageSharp.Web.Tests/Synchronization/RefCountedConcurrentDictionaryTests.cs +++ b/tests/ImageSharp.Web.Tests/Synchronization/RefCountedConcurrentDictionaryTests.cs @@ -81,7 +81,7 @@ public async Task StressTest() async Task Worker(int workerIndex) { - var random = new Random(workerIndex); + Random random = new(workerIndex); for (int i = 0; i < 1000; i++) { string key = keys[random.Next(0, keys.Length)]; diff --git a/tests/ImageSharp.Web.Tests/TagHelpers/HmacTokenTagHelperTests.cs b/tests/ImageSharp.Web.Tests/TagHelpers/HmacTokenTagHelperTests.cs index 62f15d53..e67cff3e 100644 --- a/tests/ImageSharp.Web.Tests/TagHelpers/HmacTokenTagHelperTests.cs +++ b/tests/ImageSharp.Web.Tests/TagHelpers/HmacTokenTagHelperTests.cs @@ -115,7 +115,7 @@ private static TagHelperOutput MakeImageTagHelperOutput(TagHelperAttributeList a attributes, getChildContentAsync: (useCachedResult, encoder) => { - var tagHelperContent = new DefaultTagHelperContent(); + DefaultTagHelperContent tagHelperContent = new(); tagHelperContent.SetContent(default); return Task.FromResult(tagHelperContent); }); @@ -123,14 +123,14 @@ private static TagHelperOutput MakeImageTagHelperOutput(TagHelperAttributeList a private static ViewContext MakeViewContext(string requestPathBase = null) { - var actionContext = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); + ActionContext actionContext = new(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); if (requestPathBase != null) { actionContext.HttpContext.Request.PathBase = new PathString(requestPathBase); } - var metadataProvider = new EmptyModelMetadataProvider(); - var viewData = new ViewDataDictionary(metadataProvider, new ModelStateDictionary()); + EmptyModelMetadataProvider metadataProvider = new(); + ViewDataDictionary viewData = new(metadataProvider, new ModelStateDictionary()); return new ViewContext( actionContext, new FakeView(), diff --git a/tests/ImageSharp.Web.Tests/TagHelpers/ImageTagHelperTests.cs b/tests/ImageSharp.Web.Tests/TagHelpers/ImageTagHelperTests.cs index 9f8acd02..7b74c129 100644 --- a/tests/ImageSharp.Web.Tests/TagHelpers/ImageTagHelperTests.cs +++ b/tests/ImageSharp.Web.Tests/TagHelpers/ImageTagHelperTests.cs @@ -250,7 +250,7 @@ public void RendersImageTag_SrcIncludes_ResizePosition() ImageTagHelper helper = this.GetHelper(); helper.Src = "testimage.png"; helper.Width = 100; - helper.Center = new(20, 50); + helper.Center = new PointF(20, 50); // Act helper.Process(context, output); diff --git a/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs b/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs index b01ad5b3..bde6dabb 100644 --- a/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs +++ b/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs @@ -27,7 +27,7 @@ private static void InitializeAzureStorage(IServiceProvider services, AzureBlobS { // Upload an image to the Azure Test Storage; AzureBlobContainerClientOptions containerOptions = options.BlobContainers.First(); - var container = new BlobContainerClient(containerOptions.ConnectionString, containerOptions.ContainerName); + BlobContainerClient container = new(containerOptions.ConnectionString, containerOptions.ContainerName); container.CreateIfNotExists(PublicAccessType.Blob); IWebHostEnvironment environment = services.GetRequiredService(); @@ -40,14 +40,14 @@ private static void InitializeAzureStorage(IServiceProvider services, AzureBlobS using Stream stream = file.CreateReadStream(); // Set the max-age property so we get coverage for testing is in our Azure provider. - var cacheControl = new CacheControlHeaderValue + CacheControlHeaderValue cacheControl = new() { Public = true, MaxAge = TimeSpan.FromDays(7), MustRevalidate = true }; - var headers = new BlobHttpHeaders + BlobHttpHeaders headers = new() { CacheControl = cacheControl.ToString(), };