diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 3910b2c49..fe57b3840 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -141,9 +141,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg TestEnvironment.InputImagesDirectoryFullPath, fileName); - const int NumberOfRuns = 5; + const int numberOfRuns = 5; - for (int i = 0; i < NumberOfRuns; i++) + for (int i = 0; i < numberOfRuns; i++) { var cts = new CancellationTokenSource(); if (cancellationDelayMs == 0) @@ -157,16 +157,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg try { - using var image = await Image.LoadAsync(hugeFile, cts.Token); + using Image image = await Image.LoadAsync(hugeFile, cts.Token); } catch (TaskCanceledException) { - // Succesfully observed a cancellation + // Successfully observed a cancellation return; } } - throw new Exception($"No cancellation happened out of {NumberOfRuns} runs!"); + throw new Exception($"No cancellation happened out of {numberOfRuns} runs!"); } [Theory(Skip = "Identify is too fast, doesn't work reliably.")] diff --git a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs index f9ff41df1..ba6e71935 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs @@ -90,12 +90,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png using (Image image = provider.GetImage(new PngDecoder())) { PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); - Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("leading space")); - Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("trailing space")); - Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("space")); - Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("empty")); - Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("invalid characters")); - Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("too large")); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("leading space", System.StringComparison.Ordinal)); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("trailing space", System.StringComparison.Ordinal)); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("space", System.StringComparison.Ordinal)); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("empty", System.StringComparison.Ordinal)); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("invalid characters", System.StringComparison.Ordinal)); + Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("too large", System.StringComparison.Ordinal)); } } @@ -277,20 +277,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png private static void VerifyTextDataIsPresent(PngMetadata meta) { Assert.NotNull(meta); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("Comment") && m.Value.Equals("comment")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("Author") && m.Value.Equals("ImageSharp")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("Copyright") && m.Value.Equals("ImageSharp")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("Title") && m.Value.Equals("unittest")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("Description") && m.Value.Equals("compressed-text")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("International") && m.Value.Equals("'e', mu'tlheghvam, ghaH yu'") && - m.LanguageTag.Equals("x-klingon") && m.TranslatedKeyword.Equals("warning")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("International2") && m.Value.Equals("ИМАГЕШАРП") && m.LanguageTag.Equals("rus")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational") && m.Value.Equals("la plume de la mante") && - m.LanguageTag.Equals("fra") && m.TranslatedKeyword.Equals("foobar")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational2") && m.Value.Equals("這是一個考驗") && - m.LanguageTag.Equals("chinese")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoLang") && m.Value.Equals("this text chunk is missing a language tag")); - Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoTranslatedKeyword") && m.Value.Equals("dieser chunk hat kein übersetztes Schlüßelwort")); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Comment", System.StringComparison.Ordinal) && m.Value.Equals("comment", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Author", System.StringComparison.Ordinal) && m.Value.Equals("ImageSharp", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Copyright", System.StringComparison.Ordinal) && m.Value.Equals("ImageSharp", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Title", System.StringComparison.Ordinal) && m.Value.Equals("unittest", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("Description", System.StringComparison.Ordinal) && m.Value.Equals("compressed-text", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("International", System.StringComparison.Ordinal) && m.Value.Equals("'e', mu'tlheghvam, ghaH yu'", System.StringComparison.Ordinal) && + m.LanguageTag.Equals("x-klingon", System.StringComparison.Ordinal) && m.TranslatedKeyword.Equals("warning", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("International2", System.StringComparison.Ordinal) && m.Value.Equals("ИМАГЕШАРП", System.StringComparison.Ordinal) && m.LanguageTag.Equals("rus", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational", System.StringComparison.Ordinal) && m.Value.Equals("la plume de la mante", System.StringComparison.Ordinal) && + m.LanguageTag.Equals("fra", System.StringComparison.Ordinal) && m.TranslatedKeyword.Equals("foobar", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational2", System.StringComparison.Ordinal) && m.Value.Equals("這是一個考驗", System.StringComparison.Ordinal) && + m.LanguageTag.Equals("chinese", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoLang", System.StringComparison.Ordinal) && m.Value.Equals("this text chunk is missing a language tag", System.StringComparison.Ordinal)); + Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoTranslatedKeyword", System.StringComparison.Ordinal) && m.Value.Equals("dieser chunk hat kein übersetztes Schlüßelwort", System.StringComparison.Ordinal)); } } } diff --git a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs index ecbc331b2..14f6ed8df 100644 --- a/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs +++ b/tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests ArgumentOutOfRangeException ex = Assert.Throws( () => { - this.Collection.AddFrame(new Rgba32[0]); + this.Collection.AddFrame(Array.Empty()); }); Assert.StartsWith($"Parameter \"data\" ({typeof(int)}) must be greater than or equal to {100}, was {0}", ex.Message); @@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Tests public void AddFrameFromPixelData() { Assert.True(this.Image.Frames.RootFrame.TryGetSinglePixelSpan(out Span imgSpan)); - var pixelData = imgSpan.ToArray(); + Rgba32[] pixelData = imgSpan.ToArray(); this.Image.Frames.AddFrame(pixelData); Assert.Equal(2, this.Image.Frames.Count); } @@ -276,46 +276,46 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void MoveFrame_LeavesFrameInCorrectLocation() { - for (var i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { this.Image.Frames.CreateFrame(); } - var frame = this.Image.Frames[4]; + ImageFrame frame = this.Image.Frames[4]; this.Image.Frames.MoveFrame(4, 7); - var newIndex = this.Image.Frames.IndexOf(frame); + int newIndex = this.Image.Frames.IndexOf(frame); Assert.Equal(7, newIndex); } [Fact] public void IndexOf_ReturnsCorrectIndex() { - for (var i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { this.Image.Frames.CreateFrame(); } - var frame = this.Image.Frames[4]; - var index = this.Image.Frames.IndexOf(frame); + ImageFrame frame = this.Image.Frames[4]; + int index = this.Image.Frames.IndexOf(frame); Assert.Equal(4, index); } [Fact] public void Contains_TrueIfMember() { - for (var i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { this.Image.Frames.CreateFrame(); } - var frame = this.Image.Frames[4]; + ImageFrame frame = this.Image.Frames[4]; Assert.True(this.Image.Frames.Contains(frame)); } [Fact] public void Contains_FalseIfNonMember() { - for (var i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { this.Image.Frames.CreateFrame(); } diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs b/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs index 3fbe1f70d..271aa30cf 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests private static readonly Size ExpectedImageSize = new Size(108, 202); - private byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; + private static byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; private IImageInfo LocalImageInfo => this.localImageInfoMock.Object; @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void FromBytes_GlobalConfiguration() { - IImageInfo info = Image.Identify(this.ActualImageBytes, out IImageFormat type); + IImageInfo info = Image.Identify(ActualImageBytes, out IImageFormat type); Assert.Equal(ExpectedImageSize, info.Size()); Assert.Equal(ExpectedGlobalFormat, type); @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void FromStream_GlobalConfiguration() { - using (var stream = new MemoryStream(this.ActualImageBytes)) + using (var stream = new MemoryStream(ActualImageBytes)) { IImageInfo info = Image.Identify(stream, out IImageFormat type); @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void FromStream_GlobalConfiguration_NoFormat() { - using (var stream = new MemoryStream(this.ActualImageBytes)) + using (var stream = new MemoryStream(ActualImageBytes)) { IImageInfo info = Image.Identify(stream); @@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void FromNonSeekableStream_GlobalConfiguration() { - using var stream = new MemoryStream(this.ActualImageBytes); + using var stream = new MemoryStream(ActualImageBytes); using var nonSeekableStream = new NonSeekableStream(stream); IImageInfo info = Image.Identify(nonSeekableStream, out IImageFormat type); @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public void FromNonSeekableStream_GlobalConfiguration_NoFormat() { - using var stream = new MemoryStream(this.ActualImageBytes); + using var stream = new MemoryStream(ActualImageBytes); using var nonSeekableStream = new NonSeekableStream(stream); IImageInfo info = Image.Identify(nonSeekableStream); @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public async Task FromStreamAsync_GlobalConfiguration_NoFormat() { - using (var stream = new MemoryStream(this.ActualImageBytes)) + using (var stream = new MemoryStream(ActualImageBytes)) { var asyncStream = new AsyncStreamWrapper(stream, () => false); IImageInfo info = await Image.IdentifyAsync(asyncStream); @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public async Task FromStreamAsync_GlobalConfiguration() { - using (var stream = new MemoryStream(this.ActualImageBytes)) + using (var stream = new MemoryStream(ActualImageBytes)) { var asyncStream = new AsyncStreamWrapper(stream, () => false); (IImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); @@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public async Task FromNonSeekableStreamAsync_GlobalConfiguration_NoFormat() { - using var stream = new MemoryStream(this.ActualImageBytes); + using var stream = new MemoryStream(ActualImageBytes); using var nonSeekableStream = new NonSeekableStream(stream); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); @@ -178,7 +178,7 @@ namespace SixLabors.ImageSharp.Tests [Fact] public async Task FromNonSeekableStreamAsync_GlobalConfiguration() { - using var stream = new MemoryStream(this.ActualImageBytes); + using var stream = new MemoryStream(ActualImageBytes); using var nonSeekableStream = new NonSeekableStream(stream); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); diff --git a/tests/ImageSharp.Tests/Memory/Allocators/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/Allocators/BufferTestSuite.cs index 1124b6439..1cadf1653 100644 --- a/tests/ImageSharp.Tests/Memory/Allocators/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/Allocators/BufferTestSuite.cs @@ -60,24 +60,24 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } } - public static readonly TheoryData LenthValues = new TheoryData { 0, 1, 7, 1023, 1024 }; + public static readonly TheoryData LengthValues = new TheoryData { 0, 1, 7, 1023, 1024 }; [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void HasCorrectLength_byte(int desiredLength) { this.TestHasCorrectLength(desiredLength); } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void HasCorrectLength_float(int desiredLength) { this.TestHasCorrectLength(desiredLength); } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void HasCorrectLength_CustomStruct(int desiredLength) { this.TestHasCorrectLength(desiredLength); @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void CanAllocateCleanBuffer_byte(int desiredLength) { this.TestCanAllocateCleanBuffer(desiredLength, false); @@ -101,14 +101,14 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void CanAllocateCleanBuffer_double(int desiredLength) { this.TestCanAllocateCleanBuffer(desiredLength); } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void CanAllocateCleanBuffer_CustomStruct(int desiredLength) { this.TestCanAllocateCleanBuffer(desiredLength); @@ -145,14 +145,14 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void SpanPropertyIsAlwaysTheSame_int(int desiredLength) { this.TestSpanPropertyIsAlwaysTheSame(desiredLength); } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void SpanPropertyIsAlwaysTheSame_byte(int desiredLength) { this.TestSpanPropertyIsAlwaysTheSame(desiredLength, false); @@ -174,18 +174,18 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void WriteAndReadElements_float(int desiredLength) { - this.TestWriteAndReadElements(desiredLength, x => x * 1.2f); + this.TestWriteAndReadElements(desiredLength, x => x * 1.2f); } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void WriteAndReadElements_byte(int desiredLength) { - this.TestWriteAndReadElements(desiredLength, x => (byte)(x + 1), false); - this.TestWriteAndReadElements(desiredLength, x => (byte)(x + 1), true); + this.TestWriteAndReadElements(desiredLength, x => (byte)(x + 1), false); + this.TestWriteAndReadElements(desiredLength, x => (byte)(x + 1), true); } private void TestWriteAndReadElements(int desiredLength, Func getExpectedValue, bool testManagedByteBuffer = false) @@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators { using (IMemoryOwner buffer = this.Allocate(desiredLength, AllocationOptions.None, testManagedByteBuffer)) { - T[] expectedVals = new T[buffer.Length()]; + var expectedVals = new T[buffer.Length()]; for (int i = 0; i < buffer.Length(); i++) { @@ -211,7 +211,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void IndexingSpan_WhenOutOfRange_Throws_byte(int desiredLength) { this.TestIndexOutOfRangeShouldThrow(desiredLength, false); @@ -219,14 +219,14 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void IndexingSpan_WhenOutOfRange_Throws_long(int desiredLength) { this.TestIndexOutOfRangeShouldThrow(desiredLength); } [Theory] - [MemberData(nameof(LenthValues))] + [MemberData(nameof(LengthValues))] public void IndexingSpan_WhenOutOfRange_Throws_CustomStruct(int desiredLength) { this.TestIndexOutOfRangeShouldThrow(desiredLength); @@ -316,4 +316,4 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators } } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index cc7f32bef..a2688359f 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations [Fact] public void PixelTypeInfoHasCorrectBitsPerPixel() { - var bits = this.Operations.GetPixelTypeInfo().BitsPerPixel; + int bits = this.Operations.GetPixelTypeInfo().BitsPerPixel; Assert.Equal(Unsafe.SizeOf() * 8, bits); } diff --git a/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs index e983577a2..d144c876f 100644 --- a/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; @@ -9,7 +10,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing { - public abstract class BaseImageOperationsExtensionTest + public abstract class BaseImageOperationsExtensionTest : IDisposable { protected readonly IImageProcessingContext operations; private readonly FakeImageOperationsProvider.FakeImageOperations internalOperations; @@ -58,5 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Processing return Assert.IsType(operation.GenericProcessor); } + + public void Dispose() => this.source?.Dispose(); } } diff --git a/tests/ImageSharp.Tests/Processing/ImageOperationTests.cs b/tests/ImageSharp.Tests/Processing/ImageOperationTests.cs index cd0a65ad5..d85495b92 100644 --- a/tests/ImageSharp.Tests/Processing/ImageOperationTests.cs +++ b/tests/ImageSharp.Tests/Processing/ImageOperationTests.cs @@ -171,7 +171,7 @@ namespace SixLabors.ImageSharp.Tests.Processing private static void CheckThrowsCorrectObjectDisposedException(Action action) { - var ex = Assert.Throws(action); + ObjectDisposedException ex = Assert.Throws(action); Assert.Equal(ExpectedExceptionMessage, ex.Message); } } diff --git a/tests/ImageSharp.Tests/Processing/ImageProcessingContextTests.cs b/tests/ImageSharp.Tests/Processing/ImageProcessingContextTests.cs index c206938a2..220bd5f05 100644 --- a/tests/ImageSharp.Tests/Processing/ImageProcessingContextTests.cs +++ b/tests/ImageSharp.Tests/Processing/ImageProcessingContextTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using Moq; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; @@ -12,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Processing /// /// Contains test cases for default implementation. /// - public class ImageProcessingContextTests + public class ImageProcessingContextTests : IDisposable { private readonly Image image = new Image(10, 10); @@ -195,5 +196,7 @@ namespace SixLabors.ImageSharp.Tests.Processing .Setup(p => p.CreatePixelSpecificProcessor(Configuration.Default, It.IsAny>(), It.IsAny())) .Returns(this.cloningProcessorImpl.Object); } + + public void Dispose() => this.image?.Dispose(); } } diff --git a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs index e64ae74c6..ab3a1d760 100644 --- a/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs +++ b/tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs @@ -9,8 +9,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Normalization { - [Trait("Category", "Processors")] // ReSharper disable InconsistentNaming + [Trait("Category", "Processors")] public class HistogramEqualizationTests { private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.0456F); @@ -18,10 +18,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization [Theory] [InlineData(256)] [InlineData(65536)] - public void GlobalHistogramEqualization_WithDifferentLumanceLevels(int luminanceLevels) + public void GlobalHistogramEqualization_WithDifferentLuminanceLevels(int luminanceLevels) { // Arrange - var pixels = new byte[] + byte[] pixels = { 52, 55, 61, 59, 70, 61, 76, 61, 62, 59, 55, 104, 94, 85, 59, 71, @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization } } - var expected = new byte[] + byte[] expected = { 0, 12, 53, 32, 146, 53, 174, 53, 57, 32, 12, 227, 219, 202, 32, 154, @@ -150,13 +150,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization using (Image image = provider.GetImage()) { var options = new HistogramEqualizationOptions() - { - Method = HistogramEqualizationMethod.AdaptiveTileInterpolation, - LuminanceLevels = 256, - ClipHistogram = true, - ClipLimit = 5, - NumberOfTiles = 10 - }; + { + Method = HistogramEqualizationMethod.AdaptiveTileInterpolation, + LuminanceLevels = 256, + ClipHistogram = true, + ClipLimit = 5, + NumberOfTiles = 10 + }; image.Mutate(x => x.HistogramEqualization(options)); image.DebugSave(provider); image.CompareToReferenceOutput(ValidatorComparer, provider); diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index 7273a65f7..c8d0633d7 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Tests public TestDecoder Decoder { get; } - private byte[] header = Guid.NewGuid().ToByteArray(); + private readonly byte[] header = Guid.NewGuid().ToByteArray(); public MemoryStream CreateStream(byte[] marker = null) { @@ -119,16 +119,16 @@ namespace SixLabors.ImageSharp.Tests public IEnumerable FileExtensions => this.SupportedExtensions; - public bool IsSupportedFileFormat(ReadOnlySpan header) + public bool IsSupportedFileFormat(ReadOnlySpan fileHeader) { - if (header.Length < this.header.Length) + if (fileHeader.Length < this.header.Length) { return false; } for (int i = 0; i < this.header.Length; i++) { - if (header[i] != this.header[i]) + if (fileHeader[i] != this.header[i]) { return false; } @@ -137,11 +137,11 @@ namespace SixLabors.ImageSharp.Tests return true; } - public void Configure(Configuration host) + public void Configure(Configuration configuration) { - host.ImageFormatsManager.AddImageFormatDetector(new TestHeader(this)); - host.ImageFormatsManager.SetEncoder(this, new TestEncoder(this)); - host.ImageFormatsManager.SetDecoder(this, new TestDecoder(this)); + configuration.ImageFormatsManager.AddImageFormatDetector(new TestHeader(this)); + configuration.ImageFormatsManager.SetEncoder(this, new TestEncoder(this)); + configuration.ImageFormatsManager.SetDecoder(this, new TestDecoder(this)); } public struct DecodeOperation @@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.Tests public class TestHeader : IImageFormatDetector { - private TestFormat testFormat; + private readonly TestFormat testFormat; public int HeaderSize => this.testFormat.HeaderSize; @@ -199,7 +199,7 @@ namespace SixLabors.ImageSharp.Tests public class TestDecoder : IImageDecoder, IImageInfoDetector { - private TestFormat testFormat; + private readonly TestFormat testFormat; public TestDecoder(TestFormat testFormat) { @@ -212,20 +212,20 @@ namespace SixLabors.ImageSharp.Tests public int HeaderSize => this.testFormat.HeaderSize; - public Image Decode(Configuration config, Stream stream) + public Image Decode(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel - => this.DecodeImpl(config, stream, default).GetAwaiter().GetResult(); + => this.DecodeImpl(configuration, stream, default).GetAwaiter().GetResult(); - public Task> DecodeAsync(Configuration config, Stream stream, CancellationToken cancellationToken) + public Task> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel - => this.DecodeImpl(config, stream, cancellationToken); + => this.DecodeImpl(configuration, stream, cancellationToken); private async Task> DecodeImpl(Configuration config, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { var ms = new MemoryStream(); await stream.CopyToAsync(ms, config.StreamProcessingBufferSize, cancellationToken); - var marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray(); + byte[] marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray(); this.testFormat.DecodeCalls.Add(new DecodeOperation { Marker = marker, @@ -251,9 +251,9 @@ namespace SixLabors.ImageSharp.Tests => await this.DecodeImpl(configuration, stream, cancellationToken); } - public class TestEncoder : ImageSharp.Formats.IImageEncoder + public class TestEncoder : IImageEncoder { - private TestFormat testFormat; + private readonly TestFormat testFormat; public TestEncoder(TestFormat testFormat) { diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs index 0cf76a389..12db71e66 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests if (!addedRows.Any()) { - addedRows = new[] { new object[0] }; + addedRows = new[] { Array.Empty() }; } bool firstIsProvider = this.FirstIsProvider(testMethod); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/SemaphoreReadMemoryStreamTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/SemaphoreReadMemoryStreamTests.cs index 87f8cb8c1..92f972941 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/SemaphoreReadMemoryStreamTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/SemaphoreReadMemoryStreamTests.cs @@ -1,13 +1,12 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. using System.IO; using System.Threading; using System.Threading.Tasks; -using SixLabors.ImageSharp.Tests.TestUtilities; using Xunit; -namespace SixLabors.ImageSharp.Tests +namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests { public class SemaphoreReadMemoryStreamTests {