Skip to content

Commit 56c2d58

Browse files
committed
Switch to the newer using statement.
1 parent e945fb0 commit 56c2d58

23 files changed

+448
-637
lines changed

tests/Magick.NET.Tests/Coders/TheAvifCoder.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,28 @@ public class TheAvifCoder
1212
[Fact]
1313
public void ShouldEncodeAndDecodeAlphaChannel()
1414
{
15-
using (var input = new MagickImage(Files.TestPNG))
16-
{
17-
input.Resize(new Percentage(15));
15+
using var input = new MagickImage(Files.TestPNG);
16+
input.Resize(new Percentage(15));
1817

19-
using (var stream = new MemoryStream())
20-
{
21-
input.Write(stream, MagickFormat.Avif);
18+
using var stream = new MemoryStream();
19+
input.Write(stream, MagickFormat.Avif);
2220

23-
stream.Position = 0;
21+
stream.Position = 0;
2422

25-
using (var output = new MagickImage(stream))
26-
{
27-
Assert.True(output.HasAlpha);
28-
Assert.Equal(MagickFormat.Avif, output.Format);
29-
Assert.Equal(input.Width, output.Width);
30-
Assert.Equal(input.Height, output.Height);
31-
}
32-
}
33-
}
23+
using var output = new MagickImage(stream);
24+
Assert.True(output.HasAlpha);
25+
Assert.Equal(MagickFormat.Avif, output.Format);
26+
Assert.Equal(input.Width, output.Width);
27+
Assert.Equal(input.Height, output.Height);
3428
}
3529

3630
[Fact]
3731
public void ShouldIgnoreEmptyExifProfile()
3832
{
39-
using (var image = new MagickImage())
40-
{
41-
try
42-
{
43-
image.Read(Files.Coders.EmptyExifAVIF);
44-
}
45-
catch (MagickCorruptImageErrorException exception)
46-
{
47-
Assert.Contains("Invalid clean-aperture specification", exception.Message);
48-
}
49-
}
33+
using var image = new MagickImage();
34+
35+
var exception = Assert.Throws<MagickCorruptImageErrorException>(() => image.Read(Files.Coders.EmptyExifAVIF));
36+
Assert.Contains("Invalid clean-aperture specification", exception.Message);
5037
}
5138
}
5239
}

tests/Magick.NET.Tests/Coders/TheBgrCoder.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,30 @@ public class TheBgrCoder
2424
public void ShouldSetTheCorrectValueForTheAlphaChannel()
2525
{
2626
_settings.Format = MagickFormat.Bgra;
27-
using (var image = new MagickImage(_bytes, _settings))
28-
{
29-
using (var pixels = image.GetPixels())
30-
{
31-
var pixel = pixels.GetPixel(0, 0);
32-
Assert.Equal(4, pixel.Channels);
33-
Assert.Equal(3, pixel.GetChannel(0));
34-
Assert.Equal(2, pixel.GetChannel(1));
35-
Assert.Equal(1, pixel.GetChannel(2));
36-
Assert.Equal(4, pixel.GetChannel(3));
37-
}
38-
}
27+
using var image = new MagickImage(_bytes, _settings);
28+
using var pixels = image.GetPixels();
29+
30+
var pixel = pixels.GetPixel(0, 0);
31+
Assert.Equal(4, pixel.Channels);
32+
Assert.Equal(3, pixel.GetChannel(0));
33+
Assert.Equal(2, pixel.GetChannel(1));
34+
Assert.Equal(1, pixel.GetChannel(2));
35+
Assert.Equal(4, pixel.GetChannel(3));
3936
}
4037

4138
[Fact]
4239
public void ShouldSetTheCorrectValueForTheOpacityChannel()
4340
{
4441
_settings.Format = MagickFormat.Bgro;
45-
using (var image = new MagickImage(_bytes, _settings))
46-
{
47-
using (var pixels = image.GetPixels())
48-
{
49-
var pixel = pixels.GetPixel(0, 0);
50-
Assert.Equal(4, pixel.Channels);
51-
Assert.Equal(3, pixel.GetChannel(0));
52-
Assert.Equal(2, pixel.GetChannel(1));
53-
Assert.Equal(1, pixel.GetChannel(2));
54-
Assert.Equal(Quantum.Max - 4, pixel.GetChannel(3));
55-
}
56-
}
42+
using var image = new MagickImage(_bytes, _settings);
43+
using var pixels = image.GetPixels();
44+
var pixel = pixels.GetPixel(0, 0);
45+
46+
Assert.Equal(4, pixel.Channels);
47+
Assert.Equal(3, pixel.GetChannel(0));
48+
Assert.Equal(2, pixel.GetChannel(1));
49+
Assert.Equal(1, pixel.GetChannel(2));
50+
Assert.Equal(Quantum.Max - 4, pixel.GetChannel(3));
5751
}
5852
}
5953
}

tests/Magick.NET.Tests/Coders/TheCaptionCoder.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ public void ShouldNotReplaceNonBreakingSpaceWithNewline()
1818
Width = 160,
1919
};
2020

21-
using (var image = new MagickImage("caption:Нуорунен в Карелии", settings))
22-
{
23-
image.Trim();
21+
using var image = new MagickImage("caption:Нуорунен в Карелии", settings);
22+
image.Trim();
2423

25-
Assert.Equal(88, image.Width);
26-
Assert.Equal(41, image.Height);
27-
}
24+
Assert.Equal(88, image.Width);
25+
Assert.Equal(41, image.Height);
2826
}
2927

3028
[Fact]
@@ -37,13 +35,11 @@ public void ShouldReplaceOghamSpaceMarkWithNewline()
3735
Width = 160,
3836
};
3937

40-
using (var image = new MagickImage("caption:Нуорунен в Карелии", settings))
41-
{
42-
image.Trim();
38+
using var image = new MagickImage("caption:Нуорунен в Карелии", settings);
39+
image.Trim();
4340

44-
Assert.Equal(99, image.Width);
45-
Assert.Equal(41, image.Height);
46-
}
41+
Assert.Equal(99, image.Width);
42+
Assert.Equal(41, image.Height);
4743
}
4844

4945
[Fact]
@@ -56,13 +52,11 @@ public void ShouldAddNewlineWhenTextDoesNotContainNewline()
5652
Width = 160,
5753
};
5854

59-
using (var image = new MagickImage("caption:НуоруненвКарелии", settings))
60-
{
61-
image.Trim();
55+
using var image = new MagickImage("caption:НуоруненвКарелии", settings);
56+
image.Trim();
6257

63-
Assert.Equal(157, image.Width);
64-
Assert.Equal(37, image.Height);
65-
}
58+
Assert.Equal(157, image.Width);
59+
Assert.Equal(37, image.Height);
6660
}
6761

6862
[Fact]
@@ -74,16 +68,14 @@ public void ShouldJoinFontLigatures()
7468
FontPointsize = 200,
7569
};
7670

77-
using (var image = new MagickImage("label:find fly", settings))
78-
{
79-
image.Trim();
71+
using var image = new MagickImage("label:find fly", settings);
72+
image.Trim();
8073

81-
Assert.Equal(635, image.Width);
82-
Assert.Equal(204, image.Height);
74+
Assert.Equal(635, image.Width);
75+
Assert.Equal(204, image.Height);
8376

84-
ColorAssert.Equal(MagickColors.Black, image, 50, 58);
85-
ColorAssert.Equal(MagickColors.Black, image, 475, 3);
86-
}
77+
ColorAssert.Equal(MagickColors.Black, image, 50, 58);
78+
ColorAssert.Equal(MagickColors.Black, image, 475, 3);
8779
}
8880
}
8981
}

tests/Magick.NET.Tests/Coders/TheDdsCoder.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,30 @@ public class TheDdsCoder
1212
[Fact]
1313
public void ShouldUseDxt1AsTheDefaultCompression()
1414
{
15-
using (var input = new MagickImage(Files.Builtin.Logo))
16-
{
17-
using (var output = WriteDds(input))
18-
{
19-
Assert.Equal(CompressionMethod.DXT1, output.Compression);
20-
}
21-
}
15+
using var input = new MagickImage(Files.Builtin.Logo);
16+
using var output = WriteDds(input);
17+
18+
Assert.Equal(CompressionMethod.DXT1, output.Compression);
2219
}
2320

2421
[Fact]
2522
public void ShouldUseDxt5AsTheDefaultCompressionForImagesWithAnAlphaChannel()
2623
{
27-
using (var input = new MagickImage(Files.Builtin.Logo))
28-
{
29-
input.Alpha(AlphaOption.Set);
24+
using var input = new MagickImage(Files.Builtin.Logo);
25+
input.Alpha(AlphaOption.Set);
26+
using var output = WriteDds(input);
3027

31-
using (var output = WriteDds(input))
32-
{
33-
Assert.Equal(CompressionMethod.DXT5, output.Compression);
34-
}
35-
}
28+
Assert.Equal(CompressionMethod.DXT5, output.Compression);
3629
}
3730

3831
private static MagickImage WriteDds(MagickImage input)
3932
{
40-
using (var memStream = new MemoryStream())
41-
{
42-
input.Format = MagickFormat.Dds;
43-
input.Write(memStream);
44-
memStream.Position = 0;
33+
using var memStream = new MemoryStream();
34+
input.Format = MagickFormat.Dds;
35+
input.Write(memStream);
36+
memStream.Position = 0;
4537

46-
return new MagickImage(memStream);
47-
}
38+
return new MagickImage(memStream);
4839
}
4940
}
5041
}

tests/Magick.NET.Tests/Coders/TheDngCoder.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,33 @@ public class TheDngCoder
1212
[Fact]
1313
public void ShouldReadTheThumbnail()
1414
{
15-
using (var image = new MagickImage())
15+
var settings = new MagickReadSettings
1616
{
17-
var settings = new MagickReadSettings
17+
Defines = new DngReadDefines
1818
{
19-
Defines = new DngReadDefines
20-
{
21-
ReadThumbnail = true,
22-
},
23-
};
19+
ReadThumbnail = true,
20+
},
21+
};
2422

25-
image.Ping(Files.Coders.RawKodakDC50KDC, settings);
23+
using var image = new MagickImage();
24+
image.Ping(Files.Coders.RawKodakDC50KDC, settings);
2625

27-
var profile = image.GetProfile("dng:thumbnail");
28-
Assert.NotNull(profile);
26+
var profile = image.GetProfile("dng:thumbnail");
27+
Assert.NotNull(profile);
2928

30-
var data = profile.GetData();
31-
Assert.NotNull(data);
32-
Assert.Equal(18432, data.Length);
33-
}
29+
var data = profile.GetData();
30+
Assert.NotNull(data);
31+
Assert.Equal(18432, data.Length);
3432
}
3533

3634
[Fact]
3735
public void ShouldNotReadTheThumbnailByDefault()
3836
{
39-
using (var image = new MagickImage())
40-
{
41-
image.Ping(Files.Coders.RawKodakDC50KDC);
37+
using var image = new MagickImage();
38+
image.Ping(Files.Coders.RawKodakDC50KDC);
4239

43-
var profile = image.GetProfile("dng:thumbnail");
44-
Assert.Null(profile);
45-
}
40+
var profile = image.GetProfile("dng:thumbnail");
41+
Assert.Null(profile);
4642
}
4743
}
4844
}

tests/Magick.NET.Tests/Coders/TheJp2Coder.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@ public class TheJp2Coder
1111
[Fact]
1212
public void ShouldReadTheImageWithCorrectDimensions()
1313
{
14-
using (var image = new MagickImage(Files.Coders.GrimJP2))
15-
{
16-
Assert.Equal(2155, image.Width);
17-
Assert.Equal(2687, image.Height);
18-
}
14+
using var image = new MagickImage(Files.Coders.GrimJP2);
1915

20-
using (var image = new MagickImage(Files.Coders.GrimJP2 + "[0]"))
21-
{
22-
Assert.Equal(2155, image.Width);
23-
Assert.Equal(2687, image.Height);
24-
}
16+
Assert.Equal(2155, image.Width);
17+
Assert.Equal(2687, image.Height);
2518

26-
using (var image = new MagickImage(Files.Coders.GrimJP2 + "[1]"))
27-
{
28-
Assert.Equal(256, image.Width);
29-
Assert.Equal(256, image.Height);
30-
}
19+
using var first = new MagickImage(Files.Coders.GrimJP2 + "[0]");
20+
21+
Assert.Equal(2155, first.Width);
22+
Assert.Equal(2687, first.Height);
23+
24+
using var second = new MagickImage(Files.Coders.GrimJP2 + "[1]");
25+
26+
Assert.Equal(256, second.Width);
27+
Assert.Equal(256, second.Height);
3128
}
3229
}
3330
}

0 commit comments

Comments
 (0)